/* Shared look for the demo apps. Same palette and feel as the portal (portal/ui.css):
   every colour comes from the tokens below, so a rebrand is a change to this block only. */

:root {
  color-scheme: light dark;
  --bg: #faf7f8; --surface: #ffffff; --surface-2: #f4eff2; --surface-3: #ece5ea;
  --border: #eae3e8; --border-strong: #d8cdd5;
  --text: #1a1520; --text-dim: #6e6577;
  --accent: #d6217e; --accent-hover: #b81868; --accent-soft: rgba(214, 33, 126, 0.1); --accent-ring: rgba(214, 33, 126, 0.28);
  --brand-1: #e23838; --brand-2: #d6217e; --brand-3: #f2762e; --brand-4: #fdb913;
  --ok: #0f9d6b; --warn: #d97706; --bad: #dc3545; --info: #2563eb;
  --ok-soft: rgba(15, 157, 107, 0.12); --warn-soft: rgba(217, 119, 6, 0.13); --bad-soft: rgba(220, 53, 69, 0.12); --info-soft: rgba(37, 99, 235, 0.11);
  --shadow-sm: 0 1px 2px rgba(26, 21, 32, 0.05);
  --shadow: 0 1px 2px rgba(26, 21, 32, 0.05), 0 8px 24px rgba(26, 21, 32, 0.07);
  --shadow-lg: 0 20px 50px rgba(26, 21, 32, 0.18);
  --radius: 16px; --radius-sm: 10px;
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #120f16; --surface: #1a1620; --surface-2: #211b27; --surface-3: #2a2330;
  --border: #2f2833; --border-strong: #433a49;
  --text: #f4eef7; --text-dim: #a89fb1;
  --accent: #ff64ab; --accent-hover: #ff85bd; --accent-soft: rgba(255, 100, 171, 0.15); --accent-ring: rgba(255, 100, 171, 0.35);
  --ok: #34d399; --warn: #fbbf24; --bad: #f87171; --info: #60a5fa;
  --ok-soft: rgba(52, 211, 153, 0.15); --warn-soft: rgba(251, 191, 36, 0.15); --bad-soft: rgba(248, 113, 113, 0.16); --info-soft: rgba(96, 165, 250, 0.15);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.6);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #120f16; --surface: #1a1620; --surface-2: #211b27; --surface-3: #2a2330;
    --border: #2f2833; --border-strong: #433a49; --text: #f4eef7; --text-dim: #a89fb1;
    --accent: #ff64ab; --accent-hover: #ff85bd; --accent-soft: rgba(255, 100, 171, 0.15); --accent-ring: rgba(255, 100, 171, 0.35);
    --ok: #34d399; --warn: #fbbf24; --bad: #f87171; --info: #60a5fa;
    --ok-soft: rgba(52, 211, 153, 0.15); --warn-soft: rgba(251, 191, 36, 0.15); --bad-soft: rgba(248, 113, 113, 0.16); --info-soft: rgba(96, 165, 250, 0.15);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.015em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.dim { color: var(--text-dim); }
.mono { font-family: var(--mono); }

/* ── Top bar ── */
.dm-top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: 0.7rem 1.5rem; min-height: 60px;
  background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.dm-brand { display: flex; align-items: center; gap: 0.7rem; color: var(--text); font-weight: 700; letter-spacing: -0.01em; }
.dm-brand:hover { text-decoration: none; }
.dm-mark {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 0.7rem;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2) 55%, var(--brand-3)); box-shadow: 0 6px 16px var(--accent-ring);
}
.dm-top .crumb { color: var(--text-dim); font-weight: 500; }
.dm-top .grow { flex: 1; }
.dm-top .live { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--text-dim); }
.dm-top .live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 var(--ok-soft); } 50% { box-shadow: 0 0 0 6px transparent; } }

/* ── Controls ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 0.85rem; transition: border-color 0.15s, background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--text); border-color: var(--text); color: var(--surface); box-shadow: none; }
.btn.primary:hover { background: color-mix(in srgb, var(--text) 86%, var(--surface)); border-color: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }
.btn.small { padding: 0.28rem 0.65rem; font-size: 0.78rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn { width: 36px; height: 36px; padding: 0; border-radius: 999px; }
input[type="text"], input[type="password"], input[type="search"], input[type="date"], input[type="time"], input[type="number"], input[type="email"], input[type="tel"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 0.55rem 0.8rem; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* ── Layout ── */
.page { padding: 1.5rem; max-width: 1480px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.6rem; }
.page-head p { margin: 0.25rem 0 0; color: var(--text-dim); max-width: 70ch; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 1rem; align-items: start; }
.split.wide-right { grid-template-columns: minmax(0, 1fr) 460px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.card h2 { font-size: 1rem; margin-bottom: 0.15rem; }
.card .sub { color: var(--text-dim); font-size: 0.8rem; margin-bottom: 0.9rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-bottom: 0.8rem; }
.card-head h2 { margin: 0; }

/* ── Stat tiles ── */
.stat { position: relative; overflow: hidden; }
.stat .label { font-size: 0.74rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 650; }
.stat .value { font-size: 2rem; font-weight: 750; letter-spacing: -0.03em; margin-top: 0.15rem; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 0.78rem; color: var(--text-dim); }
.stat::after { content: ""; position: absolute; right: -28px; top: -28px; width: 90px; height: 90px; border-radius: 50%; background: var(--accent-soft); }
.stat.ok::after { background: var(--ok-soft); } .stat.warn::after { background: var(--warn-soft); } .stat.bad::after { background: var(--bad-soft); }

/* ── Badges, bars, tables ── */
.badge { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.12rem 0.55rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; background: var(--surface-3); color: var(--text-dim); }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--ok); }
.dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand-2), var(--brand-3)); transition: width 0.6s ease; }
.bar.ok > i { background: var(--ok); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
table.t { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
table.t th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); }
table.t td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: none; }
table.t tbody tr:hover { background: var(--surface-2); }

/* ── Assistant dock ── */
.assistant-dock { position: sticky; top: 76px; height: calc(100vh - 100px); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-lg); border: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; }
.assistant-dock iframe { width: 100%; flex: 1; min-height: 0; border: 0; display: block; }
.ad-bar { display: flex; align-items: center; gap: 0.25rem; height: 30px; flex-shrink: 0; padding: 0 0.35rem 0 0.6rem; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 0.76rem; color: var(--text-dim); user-select: none; }
.ad-grip { letter-spacing: -2px; opacity: 0.6; }
.ad-title { flex: 1; font-weight: 600; }
.ad-btn { border: none; background: transparent; color: var(--text-dim); width: 26px; height: 24px; border-radius: 6px; display: grid; place-items: center; padding: 0; }
.ad-btn:hover { background: var(--surface-3); color: var(--text); }
.assistant-dock.floating { position: fixed; z-index: 2500; top: auto; resize: both; min-width: 320px; min-height: 360px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); box-shadow: 0 24px 70px rgba(26, 21, 32, 0.38); }
.assistant-dock.floating .ad-bar { cursor: grab; }
.assistant-dock.dragging .ad-bar { cursor: grabbing; }
.assistant-dock.minimised { display: none; }
.assistant-ph { display: grid; gap: 0.7rem; justify-items: center; align-content: center; text-align: center; min-height: 220px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-dim); font-size: 0.9rem; padding: 1.5rem; }
.ad-bubble { position: fixed; right: 22px; bottom: 22px; z-index: 2500; width: 54px; height: 54px; border-radius: 50%; border: none; color: #fff; display: grid; place-items: center; cursor: pointer; background: linear-gradient(135deg, var(--brand-1), var(--brand-2) 55%, var(--brand-3)); box-shadow: 0 10px 28px var(--accent-ring); }
.ad-bubble:hover { filter: brightness(1.06); }
.assistant-dock .dock-head { display: none; }

/* ── Toast ── */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 3000; display: grid; gap: 0.5rem; }
.toast { background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow-lg); animation: toast-in 0.25s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Chart bits ── */
.chart text { fill: var(--text-dim); font: 600 10px var(--font); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }

.split > *, .grid > *, .desk > *, .studio > *, .col > *, .stack > * { min-width: 0; }
.code, table.t { max-width: 100%; }

@media (max-width: 1100px) {
  .split, .split.wide-right { grid-template-columns: minmax(0, 1fr); }
  .assistant-dock { position: relative; top: 0; height: 620px; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .page { padding: 1rem; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .dm-top { padding: 0.6rem 1rem; }
  .dm-top .crumb, .dm-top .live { display: none; }
}

/* ── How it works: diagram modal ── */
.how-back { position: fixed; inset: 0; z-index: 4000; background: rgba(18, 15, 22, 0.62); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 1.2rem; animation: how-fade 0.18s ease; }
@keyframes how-fade { from { opacity: 0; } to { opacity: 1; } }
.how-modal { width: min(1180px, 100%); max-height: calc(100vh - 2.4rem); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow-lg); padding: 1.4rem 1.6rem 1.6rem; }
.how-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 0.8rem; }
.how-head h2 { font-size: 1.35rem; } .how-head p { margin: 0.3rem 0 0; color: var(--text-dim); max-width: 78ch; }
.how-diagram { border: 1px solid var(--border); border-radius: 16px; background: radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0 / 22px 22px, var(--bg); padding: 0.6rem; overflow-x: auto; }
.how-svg { width: 100%; min-width: 760px; height: auto; display: block; }
.how-edge { stroke: var(--text-dim); stroke-width: 1.6; opacity: 0.75; } .how-edge.dashed { stroke-dasharray: 5 5; }
.how-dot { fill: var(--accent); filter: drop-shadow(0 0 4px var(--accent-ring)); }
.how-pill { fill: var(--surface); stroke: var(--border-strong); } .how-pill-text { fill: var(--text); font: 650 10.5px var(--font); }
.how-box { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.4; }
.how-kind { fill: var(--text-dim); font: 750 9px var(--font); letter-spacing: 0.09em; } .how-label { fill: var(--text); font: 700 14px var(--font); } .how-sub { fill: var(--text-dim); font: 500 11px var(--font); }
.how-node.kind-oai .how-kind, .how-node.kind-oai .how-label, .how-node.kind-oai .how-sub { fill: #fff; } .how-node.kind-oai .how-box { fill: url(#how-oai); stroke: transparent; filter: drop-shadow(0 8px 18px var(--accent-ring)); }
.how-node.kind-model .how-box { stroke-dasharray: 6 4; stroke: var(--brand-3); } .how-node.kind-you .how-box { fill: var(--accent-soft); stroke: var(--accent); }
.how-node.kind-device .how-box, .how-node.kind-data .how-box { fill: var(--surface-2); }
.how-cols { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 1.4rem; margin-top: 1.1rem; }
.how-cols h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-dim); margin-bottom: 0.5rem; }
.how-steps { margin: 0; padding-left: 1.3rem; display: grid; gap: 0.45rem; } .how-steps li::marker { color: var(--accent); font-weight: 750; }
.how-tech { display: flex; flex-wrap: wrap; gap: 0.4rem; } .how-tech code { font: 600 0.74rem var(--mono); background: var(--surface-3); padding: 0.2rem 0.5rem; border-radius: 6px; }
@media (max-width: 800px) { .how-cols { grid-template-columns: 1fr; } .how-btn { display: none; } }

/* ── Staff console (console.js) ── */
.console { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.7rem 1rem; background: linear-gradient(180deg, var(--surface-2), var(--surface)); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.cbrand { display: flex; align-items: center; gap: 0.6rem; } .cbrand .dm-mark { width: 30px; height: 30px; font-size: 0.62rem; }
.cnavs { display: flex; gap: 0.3rem; background: var(--surface-3); padding: 0.25rem; border-radius: 999px; }
.cnav { border: none; background: transparent; padding: 0.4rem 1rem; border-radius: 999px; font-weight: 650; font-size: 0.85rem; color: var(--text-dim); }
.cnav.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.cbody { padding: 1.1rem 1.2rem 1.3rem; min-height: 420px; } .cview h3 { font-size: 0.95rem; margin-bottom: 0.7rem; }
.cform { display: grid; gap: 0.7rem; margin-bottom: 0.9rem; } .cform.inline { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.cf { display: grid; gap: 0.25rem; font-size: 0.74rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.cf input[type=text], .cf input[type=number], .cf select, .cf textarea { width: 100%; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text); font-size: 0.9rem; }
.cf.check { display: flex; align-items: center; gap: 0.5rem; text-transform: none; letter-spacing: 0; font-size: 0.88rem; color: var(--text); } .cf.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.cbtns { display: flex; gap: 0.5rem; margin: 0.4rem 0 1rem; }
.cbanner { margin: 0.7rem 1.2rem 0; padding: 0.55rem 0.8rem; border-radius: var(--radius-sm); font-size: 0.86rem; font-weight: 600; }
.cbanner.ok { background: var(--ok-soft); color: var(--ok); } .cbanner.bad { background: var(--bad-soft); color: var(--bad); } .cbanner.exported { margin: 0.8rem 0 0; } .cbanner a { margin-left: 0.5rem; }
.newrow td { background: var(--accent-soft); } .sm { font-size: 0.78rem; }
.iss { display: grid; gap: 0.1rem; padding: 0.55rem 0.7rem; border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 0.4rem; border-left: 4px solid var(--ok); } .iss.no { border-left-color: var(--bad); } .iss span { font-size: 0.8rem; color: var(--text-dim); }
