/* ipm.css — layout-level styles for the IPM tab (map stage, chrome, legend,
   tooltip, toast). Component cosmetics live in each component's own css. Cosmic
   glass per UI.md; tokens from css/base.css. Mobile-first → scales up. */

.ipm-root { display: flex; flex-direction: column; min-height: calc(100vh - var(--nav-h, 86px) - 8px); color: var(--text-primary, #e8ecf6); }

/* ── top bar ─────────────────────────────────────────────────────────────── */
.ipm-topbar {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px;
  padding: 14px clamp(12px, 2vw, 24px) 12px;
  border-bottom: 1px solid var(--glass-border, rgba(255,255,255,.08));
}
.ipm-crumbs { grid-column: 1 / -1; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-height: 20px; }
.ipm-crumb {
  appearance: none; border: 0; background: transparent; cursor: pointer; padding: 3px 7px; border-radius: 7px;
  font: 600 11.5px/1 var(--font-display, 'Space Grotesk', sans-serif); letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim, #64748b); transition: color .15s, background .15s;
}
.ipm-crumb:hover { color: var(--accent-cyan, #38bdf8); background: var(--glass-1, rgba(255,255,255,.05)); }
.ipm-crumb.is-current { color: var(--text-primary, #e8ecf6); cursor: default; }
.ipm-crumb-sep { color: var(--text-dim, #64748b); opacity: .6; }
.ipm-topbar-title { grid-column: 1; min-width: 0; }
.ipm-title { margin: 2px 0 0; font: 700 clamp(18px, 2.4vw, 24px)/1.1 var(--font-display, 'Space Grotesk', sans-serif); letter-spacing: -.01em; }
.ipm-sub { margin: 4px 0 0; font-size: 13px; color: var(--text-secondary, #cbd5e1); }
.ipm-topbar-actions { grid-column: 2; grid-row: 2; display: flex; gap: 8px; align-self: end; }
.ipm-iconbtn {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; cursor: pointer;
  background: var(--glass-1, rgba(255,255,255,.05)); border: 1px solid var(--glass-border-2, rgba(255,255,255,.12));
  color: var(--text-secondary, #cbd5e1); transition: color .15s, background .15s, border-color .15s, opacity .15s;
}
.ipm-iconbtn:hover { color: var(--accent-cyan, #38bdf8); border-color: color-mix(in srgb, var(--accent-cyan,#38bdf8) 45%, transparent); background: var(--glass-2, rgba(255,255,255,.08)); }
.ipm-iconbtn:disabled { opacity: .35; pointer-events: none; }

/* ── view tabs (Facility Map · Procedures · Insights) ────────────────────── */
.ipm-viewtabs { display: flex; gap: 3px; padding: 9px clamp(12px, 2vw, 24px) 0; border-bottom: 1px solid var(--glass-border, rgba(255,255,255,.08)); flex: none; }
.ipm-vtab { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; padding: 9px 14px; margin-bottom: -1px;
  font: 700 13px/1 var(--font-body, 'Inter', sans-serif); color: var(--text-secondary, #94a3b8);
  background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 9px 9px 0 0; transition: color .15s, background .15s, border-color .15s; }
.ipm-vtab svg { opacity: .85; }
.ipm-vtab:hover { color: var(--text-primary, #e8ecf6); background: var(--glass-1, rgba(255,255,255,.05)); }
.ipm-vtab.is-on { color: var(--accent-cyan, #38bdf8); border-bottom-color: var(--accent-cyan, #38bdf8); }
html[data-theme="light"] .ipm-vtab { color: #475569; }
html[data-theme="light"] .ipm-vtab.is-on { color: #0369a1; border-bottom-color: #0ea5e9; }
/* per-person notification badge on the Procedures tab (only the assignee sees it) */
.ipm-vtab.has-todo { color: var(--text-primary, #e8ecf6); }
.ipm-vtab-badge { display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 4px; margin-left: 7px; border-radius: 100px;
  font: 800 10px/1 var(--font-body, 'Inter', sans-serif); color: #04050f; background: #f6435f; box-shadow: 0 0 0 2px color-mix(in srgb, #f6435f 35%, transparent);
  animation: ipm-vtab-pulse 1.8s ease-in-out infinite; }
@keyframes ipm-vtab-pulse { 0%,100% { box-shadow: 0 0 0 2px color-mix(in srgb, #f6435f 35%, transparent); } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, #f6435f 0%, transparent); } }
@media (prefers-reduced-motion: reduce) { .ipm-vtab-badge { animation: none; } }

/* ── view containers ─────────────────────────────────────────────────────── */
.ipm-mapview { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.ipm-procview { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.ipm-procview[hidden], .ipm-mapview[hidden] { display: none; }

/* ── map stage ───────────────────────────────────────────────────────────── */
.ipm-stage {
  position: relative; flex: 1 1 auto; min-height: 460px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(56,189,248,.06), transparent 60%),
    var(--col-void, #06070f);
}
.ipm-map { position: absolute; inset: 0; }
.ipm-map canvas { position: absolute; inset: 0; }

/* WebGL-unavailable fallback */
.ipm-mapfail { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 6px; padding: 24px; color: var(--text-secondary, #cbd5e1); }
.ipm-mapfail-sub { font-size: 12px; color: var(--text-dim, #64748b); }

/* ── pot/room tooltip (Pixi → DOM overlay) ───────────────────────────────── */
.ipm-map-tip {
  position: absolute; z-index: 6; pointer-events: none; max-width: 240px;
  padding: 9px 11px; border-radius: 11px;
  background: var(--col-indigo, #0f1535); border: 1px solid var(--glass-border-2, rgba(255,255,255,.14));
  box-shadow: 0 18px 44px rgba(2,4,14,.55);
  font-size: 12px; line-height: 1.5; color: var(--text-secondary, #cbd5e1);
  opacity: 0; transform: translateY(3px); transition: opacity .12s, transform .12s;
}
.ipm-map-tip.is-on { opacity: 1; transform: translateY(0); }
.ipm-map-tip b { display: block; color: var(--text-primary, #e8ecf6); font: 700 12.5px/1.3 var(--font-display, 'Space Grotesk', sans-serif); margin-bottom: 2px; }
.ipm-map-tip span { display: block; color: var(--text-dim, #94a3b8); }
.ipm-map-tip .ipm-tip-tier { font-weight: 700; }

/* ── legend (floating glass, bottom-left) ────────────────────────────────── */
.ipm-legend {
  position: absolute; right: 14px; bottom: 14px; z-index: 7; width: 246px;
  border-radius: 14px; overflow: hidden;
  background: color-mix(in srgb, var(--col-indigo, #0f1535) 86%, transparent);
  border: 1px solid var(--glass-border-2, rgba(255,255,255,.14));
  box-shadow: 0 20px 50px rgba(2,4,14,.5);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  animation: ipm-legend-in .4s cubic-bezier(.2,.7,.2,1) both;
}
.ipm-legend-head {
  width: 100%; display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 11px 13px; border: 0; background: transparent; color: var(--text-primary, #e8ecf6);
  font: 700 11.5px/1 var(--font-display, 'Space Grotesk', sans-serif); letter-spacing: .08em; text-transform: uppercase;
}
.ipm-legend-key { color: var(--accent-cyan, #38bdf8); flex: none; }
.ipm-legend-head span { flex: 1 1 auto; text-align: left; }
.ipm-legend-chev { color: var(--text-dim, #64748b); transition: transform .25s ease; }
.ipm-legend.is-collapsed .ipm-legend-chev { transform: rotate(-90deg); }
.ipm-legend-body { display: grid; gap: 2px; padding: 0 8px 9px; max-height: 340px; overflow: auto; transition: max-height .28s ease, opacity .2s ease, padding .28s ease; }
.ipm-legend.is-collapsed .ipm-legend-body { max-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0; pointer-events: none; }
.ipm-legend-row {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  padding: 6px 7px; border-radius: 9px; border: 1px solid transparent; background: transparent;
  color: var(--text-secondary, #cbd5e1); transition: background .15s, border-color .15s;
}
.ipm-legend-row:hover { background: var(--glass-1, rgba(255,255,255,.05)); }
.ipm-legend-row.is-active { background: var(--glass-2, rgba(255,255,255,.09)); border-color: var(--glass-border-2, rgba(255,255,255,.16)); }
.ipm-legend.is-filtering .ipm-legend-row:not(.is-active) { opacity: .5; }
.ipm-legend-sw { flex: none; width: 26px; height: 26px; display: grid; place-items: center; }
.ipm-legend-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.ipm-legend-txt b { font: 700 12px/1.2 var(--font-display, 'Space Grotesk', sans-serif); color: var(--text-primary, #e8ecf6); }
.ipm-legend-txt small { font-size: 10.5px; color: var(--text-dim, #94a3b8); line-height: 1.3; }
.ipm-legend-hint { font-size: 10px; color: var(--text-dim, #64748b); padding: 6px 7px 2px; }

/* mobile legend → bottom-aligned, narrower */
@media (max-width: 640px) {
  .ipm-legend { left: 10px; right: 10px; width: auto; bottom: 10px; }
  .ipm-stage { min-height: 70vh; }
}

/* ── toast ───────────────────────────────────────────────────────────────── */
.ipm-toast {
  position: absolute; left: 50%; bottom: 22px; transform: translate(-50%, 8px); z-index: 9;
  padding: 10px 16px; border-radius: 100px; pointer-events: none;
  background: var(--col-indigo, #0f1535); border: 1px solid var(--glass-border-2, rgba(255,255,255,.16));
  box-shadow: 0 16px 40px rgba(2,4,14,.5); color: var(--text-primary, #e8ecf6); font-size: 13px;
  opacity: 0; transition: opacity .2s, transform .2s;
}
.ipm-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@keyframes ipm-legend-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .ipm-legend { animation: none; } }

/* light theme legibility */
html[data-theme="light"] .ipm-stage { background: radial-gradient(120% 90% at 50% 0%, rgba(56,189,248,.08), transparent 60%), #eef2fb; }
html[data-theme="light"] .ipm-legend {
  background: rgba(255,255,255,.92);
  border-color: var(--glass-border-2, rgba(130,100,200,.32));
  box-shadow: 0 20px 50px rgba(80,90,160,.18);
}
html[data-theme="light"] .ipm-map-tip {
  background: #fff; color: var(--text-secondary, #334155);
  border-color: var(--glass-border-2, rgba(130,100,200,.32));
  box-shadow: 0 18px 44px rgba(80,90,160,.20);
}
html[data-theme="light"] .ipm-map-tip b { color: var(--text-primary, #13103a); }
/* the map builds tooltip rows with dark-tuned inline colours (light greys/cyans
   that vanish on the white tip). Force the plain info rows to a readable muted
   navy (!important beats the inline style); the semantic tier line keeps its hue
   but gets a soft tinted chip so even pale hues (cyan/amber/violet) stay legible. */
html[data-theme="light"] .ipm-map-tip span:not(.ipm-tip-tier) { color: var(--text-muted, rgba(19,16,58,.60)) !important; }
html[data-theme="light"] .ipm-map-tip .ipm-tip-tier {
  display: inline-block; margin: 1px 0 2px; padding: 1px 6px; border-radius: 6px;
  background: rgba(19,16,58,.06); filter: saturate(1.15) brightness(0.82);
}
html[data-theme="light"] .ipm-toast {
  background: #fff; color: var(--text-primary, #13103a);
  border-color: var(--glass-border-2, rgba(130,100,200,.32));
  box-shadow: 0 16px 40px rgba(80,90,160,.18);
}
html[data-theme="light"] .ipm-mapfail-sub { color: var(--text-muted, rgba(19,16,58,.50)); }

/* ── MOBILE (2026-07-06 overhaul) — scoped, desktop untouched ── */
/* P0: Pixi sets an inline touch-action:none on its canvas, and the 640px band
   makes the stage 70vh tall — every vertical swipe over the map was swallowed
   and the page felt frozen. pan-y (!important beats the inline style) restores
   page scroll; taps + the JS pinch/pan layer in map-renderer still work. */
@media (max-width: 768px), (pointer: coarse) {
  .ipm-map canvas { touch-action: pan-y !important; }
}
@media (max-width: 768px) {
  /* dvh: 100vh mis-sizes as the mobile URL bar collapses */
  .ipm-root { min-height: calc(100vh - var(--nav-h, 86px) - 8px); min-height: calc(100dvh - var(--nav-h, 86px) - 8px); }
}
@media (max-width: 640px) {
  /* shorter stage (overrides the 70vh band above) so content below the map is reachable */
  .ipm-stage { min-height: 55vh; min-height: 55dvh; }
  /* view tabs: horizontal scroll strip so all three stay reachable at 320px */
  .ipm-viewtabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .ipm-viewtabs::-webkit-scrollbar { display: none; }
  .ipm-vtab { flex: none; white-space: nowrap; min-height: 44px; }
  /* the toast used to render on top of the full-width legend header — lift it clear */
  .ipm-toast { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 32px); white-space: normal; text-align: center; }
  /* drop the legend's blur on phones (non-lite path) — its 86% color-mix bg is already opaque enough */
  .ipm-legend { backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (pointer: coarse) {
  .ipm-iconbtn { width: 44px; height: 44px; }
}
