/* ─────────────────────────────────────────────────────────────────────────
   demo.css  —  shared styles for wafermap guide demos
   ───────────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --accent:    #3b82f6;
  --accent-lo: #eff6ff;
  --text:      #0f172a;
  --text-2:    #334155;
  --muted:     #64748b;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
}

html, body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}

/* ── Page shell ──────────────────────────────────────────────────────────── */

.demo-page {
  display: flex;
  flex-direction: column;
  /* The shell flows in normal document height — NOT viewport-locked. Demos are
     documents: when content is taller than the window the page scrolls. Every
     canvas card therefore carries an EXPLICIT pixel height (never a flex-derived
     one), so the map area is well-defined regardless of shell height and
     renderWaferMap's ResizeObserver has nothing to feed back against. */
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.demo-header {
  flex-shrink: 0;
  background: #0f172a;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  padding: 10px 20px 11px;
  row-gap: 3px;
}

/* Col 1 row 1: logo */
.demo-logo {
  grid-column: 1;
  grid-row: 1;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
  color: #64748b;
  white-space: nowrap;
  text-decoration: none;
  align-self: end;
}
.demo-logo em { color: #3b82f6; font-style: normal; }

/* Col 1 row 2: title */
.demo-title {
  grid-column: 1;
  grid-row: 2;
  font-size: 16px;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -.02em;
  line-height: 1.2;
  align-self: start;
}

/* Col 2 rows 1-2: nav — vertically centred across both rows */
.demo-nav {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 20px;
  align-self: center;
}

.demo-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #cbd5e1;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
  line-height: 1;
}
.demo-nav-btn:hover {
  background: #1e3a5f;
  color: #f1f5f9;
  border-color: #475569;
}

/* desc stays in the HTML but moves below the title as a subtitle */
.demo-desc {
  grid-column: 1;
  grid-row: 3;
  font-size: 12px;
  color: #475569;
  margin-top: 2px;
  display: none; /* hidden — description lives in .demo-intro instead */
}

/* Sep no longer needed */
.demo-sep { display: none; }

/* ── Intro bar ───────────────────────────────────────────────────────────── */

.demo-intro {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 11px 20px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-2);
}

.demo-intro strong { color: var(--text); font-weight: 600; }
.demo-intro code   { font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; }

/* ── Controls bar ────────────────────────────────────────────────────────── */

.demo-controls {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 7px;
}

.ctrl-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}

.ctrl-sep { width: 1px; height: 22px; background: var(--border); }

/* Form controls */

select {
  padding: 5px 28px 5px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
}
select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59,130,246,.15); }

.toggle-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font: inherit;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.toggle-btn:hover { background: #e2e8f0; }
.toggle-btn.active {
  background: var(--accent-lo);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ── Main content area ───────────────────────────────────────────────────── */

.demo-content {
  display: flex;
  padding: 14px;
  gap: 14px;
}

/* ── Canvas card ─────────────────────────────────────────────────────────── */

.canvas-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Grow the canvas card to fill the window when maximised so the wafer uses the
   space instead of leaving an empty strip below it — but keep a 600px floor (so
   small windows still get a usable map and the page scrolls) and a 900px cap (so
   the wafer never becomes oversized on tall displays). The subtraction accounts
   for the header (~60px), intro (~66px), and the .demo-content padding (28px). */
.canvas-card.flex-1 { width: 100%; height: clamp(600px, calc(100vh - 170px), 900px); }

.canvas-card canvas,
.canvas-card > div[id] {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: block;
}

/* Floating pill label over the canvas */
.canvas-badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, .72);
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: 20px;
  pointer-events: none;
  letter-spacing: .02em;
  backdrop-filter: blur(4px);
  white-space: nowrap;
}

/* Caption strip at the bottom of a card */
.card-caption {
  flex-shrink: 0;
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}
.card-caption strong { color: var(--text-2); font-weight: 600; }

/* ── Side panel ──────────────────────────────────────────────────────────── */

.demo-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.demo-panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Panel sections ──────────────────────────────────────────────────────── */

.section { display: flex; flex-direction: column; gap: 8px; }

.section-heading {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-divider { height: 1px; background: var(--border); margin: 0; }

/* ── Stat tiles ──────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.stat {
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 6px 7px;
  text-align: center;
}
.stat.full { grid-column: 1 / -1; }

.stat-val {
  font-size: 19px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.stat-lbl {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
}

/* ── Key-value table ─────────────────────────────────────────────────────── */

.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 2px 0; vertical-align: top; }
.kv td:first-child { color: var(--muted); width: 48%; padding-right: 6px; font-size: 12px; }
.kv td:last-child  { font-weight: 500; font-size: 12px; }

/* ── Bin legend rows ─────────────────────────────────────────────────────── */

.bin-rows { display: flex; flex-direction: column; gap: 5px; }

.bin-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
}

.bin-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex-shrink: 0;
}

.bin-name { flex: 1; color: var(--text-2); }
.bin-count { color: var(--muted); font-size: 11px; }

/* ── Progress bar row ────────────────────────────────────────────────────── */

.pct-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
}
.pct-row .pname { flex: 1; color: var(--text-2); white-space: nowrap; }
.pct-bar  { flex: 1; height: 4px; background: #e5e7eb; border-radius: 2px; overflow: hidden; }
.pct-fill { height: 100%; border-radius: 2px; transition: width .3s; background: var(--accent); }
.pct-val  { color: var(--muted); width: 36px; text-align: right; }

/* ── Info / hover box ────────────────────────────────────────────────────── */

.info-box {
  background: var(--bg);
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.65;
  min-height: 42px;
}
.info-box .empty { color: var(--muted); font-style: italic; }

/* ── Badge ───────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: .03em;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-muted  { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* ── Multi-canvas grids ──────────────────────────────────────────────────── */

/* Multi-card grids carry an EXPLICIT height (like .canvas-card.flex-1's 600px),
   so cards inside are well-defined and the page flows/scrolls normally. width:100%
   makes the grid fill .demo-content; no flex:1 (that would re-derive height from
   the shell and reintroduce the ResizeObserver growth loop). */
.canvas-grid-2,
.canvas-grid-3 {
  display: grid;
  gap: 14px;
  width: 100%;
  height: 520px;
}

.canvas-grid-2 { grid-template-columns: 1fr 1fr; }
.canvas-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

.canvas-grid-4 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 14px;
  width: 100%;
  height: 640px;
}

/* ── Mobile — stack vertically, allow page scroll ───────────────────────── */

@media (max-width: 640px) {
  html, body { overflow: auto; height: auto; }

  .demo-page { height: auto; min-height: 100dvh; }

  .demo-header {
    padding: 10px 14px 11px;
    row-gap: 3px;
  }
  .demo-nav { padding-left: 12px; gap: 4px; }
  .demo-nav-btn { height: 26px; padding: 0 9px; font-size: 11px; }

  .demo-intro { padding: 10px 14px; }

  .demo-controls {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 14px;
    gap: 8px;
  }

  .demo-content {
    flex-direction: column;
    overflow: visible;
    padding: 10px;
    gap: 10px;
  }

  /* Single-canvas card: fixed height on the card so absolute children anchor correctly */
  .canvas-card.flex-1 {
    flex: none;
    height: 70vw;
    min-height: 260px;
    max-height: 480px;
  }

  /* Panel goes full-width below the canvas */
  .demo-panel { width: 100%; flex-shrink: 0; }
  .demo-panel-scroll { max-height: none; overflow-y: visible; }

  /* Multi-canvas grids: collapse to single column */
  .canvas-grid-2,
  .canvas-grid-3,
  .canvas-grid-4 {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    overflow: visible;
    flex: none;
    height: auto;
  }

  /* Fixed height on each grid card so absolute children (overlays, etc.) anchor correctly */
  .canvas-grid-2 .canvas-card,
  .canvas-grid-3 .canvas-card,
  .canvas-grid-4 .canvas-card {
    height: 70vw;
    min-height: 240px;
    max-height: 420px;
  }
}
