/*
 * Data for All Studio styles.
 * Colours, type, spacing, radii and shadows come from the shared Sonra design
 * tokens (assets/tokens.css, copied from design/tokens.css). This file maps the
 * Studio's own class names onto those tokens and adds its app layout. No hex
 * values here: if something is missing, add a token upstream.
 */

:root {
  /* Studio aliases -> shared tokens */
  --panel: var(--surface);
  --panel-2: var(--surface-sunken);
  --line: var(--hairline);
  --line-strong: var(--hairline-strong);
  --text: var(--ink);
  --muted: var(--ink-muted);
  --faint: var(--ink-faint);

  /* Code surfaces reuse the dark panel. The platform accents (--meta,
     --google, --tiktok) and syntax colours (--code-kw, --code-num) come from
     the shared tokens. */
  --code-bg: var(--panel-dark);
  --code-text: var(--on-dark);
  --code-muted: var(--on-dark-muted);
  --code-str: var(--accent);

  --radius: var(--radius-lg);
  --shadow: var(--shadow-md);
  --font: var(--font-sans);
  --mono: var(--font-mono);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: var(--leading-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); }
code, pre, kbd { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.logo-mark { display: grid; }
.logo-text em { font-style: normal; font-weight: 500; color: var(--muted); }
.brand-switcher { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; flex-wrap: wrap; }
.brand-switcher select { max-width: 240px; }
.readiness { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-size: 13px; color: var(--muted); }
.ring { --p: 0; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); }
.ring span { width: 26px; height: 26px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; font-size: 10px; font-weight: 700; color: var(--text); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.sidebar { border-right: 1px solid var(--nav-border); padding: 18px 12px; position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto; background: var(--nav-bg); color: var(--nav-text); }
.nav-label { font-family: var(--mono); font-size: 11px; font-weight: var(--weight-medium); text-transform: uppercase; letter-spacing: var(--tracking-mono); color: var(--nav-label); padding: 14px 10px 6px; }
.nav-label:first-child { padding-top: 0; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--nav-text);
  font: inherit; text-align: left; cursor: pointer;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.nav-item:hover { background: var(--nav-hover); color: var(--nav-text-strong); }
.nav-item.active { background: var(--nav-active-bg); color: var(--nav-active-text); font-weight: 600; }
.nav-item:focus-visible { outline-color: var(--accent); box-shadow: none; }
.nav-num { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: transparent; border: 1px solid var(--nav-border); color: var(--nav-text); flex: none; }
.nav-item.active .nav-num { border-color: var(--accent); color: var(--accent); }
.nav-item .dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sidebar .dot.ok { background: var(--ok-on-dark); }
.sidebar .dot.warn { background: var(--warn-on-dark); }
.sidebar .dot.error { background: var(--err-on-dark); }
.sidebar .dot.off { background: var(--off-on-dark); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.error { background: var(--err); }
.dot.off { background: var(--line-strong); }
.nav-icon { width: 22px; text-align: center; flex: none; color: var(--nav-text); }

.main { padding: 28px clamp(16px, 4vw, 48px) 80px; outline: none; max-width: 1180px; width: 100%; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-head h1 { font-size: 30px; font-weight: var(--weight-semibold); line-height: var(--leading-heading); margin: 0 0 6px; letter-spacing: var(--tracking-h2); }
.section-head p { margin: 0; color: var(--muted); max-width: 720px; }
.eyebrow { font-family: var(--mono); font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--accent-ink); text-transform: uppercase; letter-spacing: var(--tracking-mono); margin-bottom: 6px; }

/* ---------- cards & forms ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--space-5); margin-bottom: var(--space-4); }
.card h2 { font-size: 15px; margin: 0 0 4px; }
.card > .sub { color: var(--muted); margin: 0 0 16px; font-size: 13px; }
.grid { display: grid; gap: 14px 18px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.span { grid-column: 1 / -1; }
.field > label, .label { font-weight: 600; font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); }
.hint code, .sub code, p code, li code, td code { font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
input[type=text], input[type=url], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 8px 10px; width: 100%;
  transition: border-color .12s, box-shadow .12s;
}
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; min-height: 120px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: var(--focus-width) solid var(--focus-color); outline-offset: 1px; border-color: var(--accent-ink); box-shadow: var(--focus-halo); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-ink); }
.btn:focus-visible, .nav-item:focus-visible, .tab:focus-visible, .file-btn:focus-visible, a:focus-visible {
  outline: var(--focus-width) solid var(--focus-color); outline-offset: var(--focus-offset); box-shadow: var(--focus-halo); border-radius: var(--radius-sm);
}
input.invalid { border-color: var(--err); }
.mono { font-family: var(--mono); font-size: 13px; }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.choice { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-md); cursor: pointer; background: var(--panel); transition: border-color .12s, background .12s; }
.choice:hover { border-color: var(--accent); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice strong { font-size: 13.5px; }
.choice span { font-size: 12px; color: var(--muted); }
.choice:has(input:checked) { border-color: var(--accent-ink); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-ink); }
.choice:has(input:focus-visible) { box-shadow: var(--focus-halo), inset 0 0 0 1px var(--accent-ink); }
.choice .tag { position: absolute; top: 10px; right: 10px; font-size: 10px; font-weight: 700; color: var(--accent-ink); text-transform: uppercase; letter-spacing: .04em; }

.toggle-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.toggle-row:first-of-type { border-top: 0; padding-top: 0; }
.toggle-row .txt { flex: 1; }
.toggle-row .txt strong { display: block; font-size: 13.5px; }
.toggle-row .txt span { font-size: 12.5px; color: var(--muted); }
.switch { position: relative; width: 38px; height: 22px; flex: none; margin-top: 1px; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 22px; background: var(--line-strong); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { box-shadow: var(--focus-halo); }

.platform-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: var(--text-xs); font-weight: var(--weight-medium); letter-spacing: var(--tracking-mono); text-transform: uppercase; padding: 3px 9px; border-radius: var(--radius-pill); border: 1px solid var(--line); background: var(--panel); color: var(--muted); white-space: nowrap; }
.badge.meta { color: var(--meta); border-color: color-mix(in srgb, var(--meta) 35%, transparent); background: color-mix(in srgb, var(--meta) 8%, transparent); }
.badge.google { color: var(--google); border-color: color-mix(in srgb, var(--google) 35%, transparent); background: color-mix(in srgb, var(--google) 8%, transparent); }
.badge.tiktok { color: var(--tiktok); border-color: color-mix(in srgb, var(--tiktok) 35%, transparent); background: color-mix(in srgb, var(--tiktok) 8%, transparent); }
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.badge.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.badge.error { color: var(--err); background: var(--err-soft); border-color: transparent; }

/* ---------- buttons ---------- */
.btn { font: inherit; font-weight: var(--weight-semibold); font-size: 13.5px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer; background: var(--accent); color: var(--on-accent); white-space: nowrap; text-decoration: none; transition: background var(--motion-fast) var(--ease); }
.btn:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--panel); color: var(--text); border-color: var(--line-strong); }
.btn.secondary:hover { border-color: var(--accent-ink); color: var(--accent-ink); }
.btn.ghost { background: none; color: var(--muted); }
.btn.ghost:hover { background: var(--line); color: var(--text); }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }
.btn.danger-text:hover { color: var(--err); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.step-footer { display: flex; justify-content: space-between; margin-top: 24px; gap: 12px; }

/* ---------- callouts & checks ---------- */
.callout { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 14px; border: 1px solid transparent; }
.callout.info { background: var(--accent-soft); color: var(--text); }
.callout.warn { background: var(--warn-soft); }
.callout.error { background: var(--err-soft); }
.callout.ok { background: var(--ok-soft); }
.callout b { font-weight: 600; }
.callout .ico { flex: none; font-weight: 700; }
.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-top: 1px solid var(--line); font-size: 13px; }
.check-list li:first-child { border-top: 0; }
.check-list .sev { flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: var(--on-dark); margin-top: 1px; }
.sev.ok { background: var(--ok); }
.sev.warn { background: var(--warn); }
.sev.error { background: var(--err); }
.sev.off { background: var(--line-strong); }
.sev.note { background: var(--accent-ink); }
.check-list .go { margin-left: auto; flex: none; }

/* ---------- events table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-md); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-top: 1px solid var(--line); vertical-align: middle; }
thead th { border-top: 0; background: var(--panel-2); font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tr.disabled td:not(:first-child) { opacity: .45; }
td input[type=text] { padding: 5px 8px; font-size: 12.5px; min-width: 140px; }
td .ev-name { font-weight: 600; }
td .ev-desc { font-size: 12px; color: var(--muted); }
.cb { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---------- deploy / code ---------- */
.kit { display: grid; grid-template-columns: 260px minmax(0, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); box-shadow: var(--shadow); min-height: 560px; }
.file-tree { border-right: 1px solid var(--line); background: var(--panel-2); padding: 8px; overflow-y: auto; max-height: 76vh; }
.file-group { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); padding: 10px 8px 4px; }
.file-btn { display: block; width: 100%; text-align: left; border: 0; background: none; font: inherit; font-size: 12.5px; color: var(--text); padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.file-btn small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-btn:hover { background: var(--line); }
.file-btn.active { background: var(--accent-soft); color: var(--accent-ink); }
.file-btn .fname { font-family: var(--mono); font-size: 12px; }
.viewer { display: flex; flex-direction: column; min-width: 0; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.viewer-bar .path { font-family: var(--mono); font-size: 12.5px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
pre.code { margin: 0; padding: 16px; background: var(--code-bg); color: var(--code-text); font-size: 12.5px; line-height: 1.6; overflow: auto; max-height: 70vh; flex: 1; tab-size: 2; white-space: pre; }
pre.code.wrap { white-space: pre-wrap; word-break: break-all; }
.c-com { color: var(--code-muted); font-style: italic; }
.c-str { color: var(--code-str); }
.c-kw { color: var(--code-kw); }
.c-num { color: var(--code-num); }
.code-block { position: relative; }
.code-block .copy { position: absolute; top: 8px; right: 8px; }
.code-block pre.code { border-radius: var(--radius-sm); max-height: 420px; }

.md { padding: 20px 26px; overflow: auto; max-height: 70vh; font-size: 13.5px; }
.md h1 { font-size: 20px; margin: 0 0 12px; }
.md h2 { font-size: 16px; margin: 24px 0 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.md h3 { font-size: 14px; margin: 18px 0 6px; }
.md pre { background: var(--code-bg); color: var(--code-text); padding: 12px 14px; border-radius: var(--radius-sm); overflow-x: auto; font-size: 12.5px; }
.md code { font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.md pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.md table { margin: 8px 0 12px; width: auto; }
.md td, .md th { border: 1px solid var(--line); }
.md blockquote { margin: 10px 0; padding: 8px 14px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; }
.md ul { padding-left: 22px; }
.md li { margin: 3px 0; }
.md li.task { list-style: none; margin-left: -20px; }
.md li.task input { margin-right: 8px; accent-color: var(--accent); }

/* ---------- toolbox ---------- */
.hash-table td { font-family: var(--mono); font-size: 12px; word-break: break-all; }
.hash-table td:first-child { font-family: var(--font); font-weight: 600; white-space: nowrap; word-break: normal; }
.hash-table .muted { color: var(--faint); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tab { border: 0; background: none; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); padding: 8px 12px; border-bottom: 2px solid transparent; cursor: pointer; margin-bottom: -1px; }
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent-ink); }
.meter { height: 10px; border-radius: var(--radius-md); background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: var(--radius-pill); background: var(--accent); transition: width var(--motion) var(--ease); }
.score-big { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.id-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.id-opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; }
.id-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.id-opt small { display: block; color: var(--muted); font-size: 11.5px; }
.id-opt.auto { cursor: default; opacity: .85; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

.flow { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 4px 0 4px; }
.flow-step { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px; background: var(--panel); }
.flow-step b { display: block; font-size: 13px; margin-bottom: 2px; }
.flow-step span { font-size: 12px; color: var(--muted); }
.flow-step .n { font-size: 11px; font-weight: 700; color: var(--accent-ink); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-md); font-size: 13px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--nav-border); display: flex; overflow-x: auto; gap: 4px; padding: 8px; }
  .nav-label { display: none; }
  .nav-item { width: auto; white-space: nowrap; }
  .nav-item .dot { margin-left: 4px; }
  .kit { grid-template-columns: 1fr; }
  .file-tree { border-right: 0; border-bottom: 1px solid var(--line); max-height: 220px; }
  .topbar { flex-wrap: wrap; }
}
