/* Page grid + responsive layout (DEMO_UX_DESIGN.md §2). */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink-1);
  font: 400 var(--fs-14)/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent-2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tnum { font-feature-settings: "tnum" 1; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--ink-3); }

/* ---------- desktop (≥ 1100 px): grid 1fr 360px · 48 / 72 / 1fr / 48 ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 360px;
  grid-template-rows: 48px 88px auto 1fr 48px;
  grid-template-areas:
    "hdr   hdr"
    "kpis  kpis"
    "trend side"
    "vp    side"
    "time  time";
}
.hdr { grid-area: hdr; }
.kpis { grid-area: kpis; }
/* Expanded trend chart. Hidden, its row has no height and the view fills the space. */
.trend { grid-area: trend; min-width: 0; }
.viewport { grid-area: vp; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.side { grid-area: side; position: relative; min-height: 0; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--bg-2); }
.timebar { grid-area: time; }
.phone-only { display: none !important; }
.phone-latest { display: none; }
.sheet-handle, .sheet-close { display: none !important; }

.viewport-canvas { display: block; position: absolute; inset: 0; touch-action: none; }

/* Inspector: a 380 px drawer over the feed column (§2.1). */
.inspector {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  z-index: 20;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: drawer-in var(--t-panel) var(--ease);
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- tablet (700–1099 px): right column becomes a draggable bottom sheet ---------- */
@media (max-width: 1099px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 48px 88px auto 1fr 48px;
    grid-template-areas: "hdr" "kpis" "trend" "vp" "time";
  }
  .side {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 48px;
    height: var(--sheet-h);
    z-index: 30;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: var(--shadow);
    transform: translateY(calc(100% - 44px));
    transition: transform var(--t-panel) var(--ease);
  }
  .app.sheet-open .side { transform: none; }
  .sheet-handle { display: flex !important; }
  .sheet-close { display: inline-flex !important; }
  .phone-only#menuBtn { display: inline-flex !important; }
  .inspector { width: 100%; border-left: 0; border-radius: 14px 14px 0 0; }
  .vp-panel .view-label { display: none; }
}

/* ---------- phone (< 700 px): graceful degradation (§2.3) ---------- */
@media (max-width: 699px) {
  .app {
    grid-template-rows: 44px 56px auto 1fr auto 48px;
    grid-template-areas: "hdr" "kpis" "trend" "vp" "latest" "time";
  }
  .phone-only { display: inline-flex !important; }
  .phone-latest { display: flex; grid-area: latest; }
  .hero { display: none; }
  .hdr .link-sm { display: none; }
  .side { height: 85vh; height: 85dvh; transform: translateY(105%); bottom: 0; z-index: 40; }
  .app.sheet-open .side { transform: none; }
  .hide-sm { display: none !important; }
}
