/* Creative Lab Console - admin styles. Palette follows the Body Language app (navy, teal, burnt orange, cream). */
:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --border: #e6e2da;
  --text: #1b2a31;
  --muted: #66727a;
  --primary: #1f6f78;
  --primary-ink: #ffffff;
  --primary-soft: #e3f0f1;
  --accent: #d0662f;
  --accent-soft: #fbe9df;
  --success: #2e7d4f;
  --success-soft: #e2f3e8;
  --warn: #a8670a;
  --warn-soft: #fbf0d9;
  --danger: #b3261e;
  --danger-soft: #fbe4e2;
  --side: #1f3a44;
  --side-ink: #d6e3e6;
  --side-muted: #8fa7ad;
  --side-active: #2b5160;
  --shadow: 0 1px 2px rgba(20, 35, 40, .06), 0 1px 8px rgba(20, 35, 40, .04);
  --radius: 10px;
  --chart-1: #1f6f78;
  --chart-2: #d0662f;
  --chart-3: #7a9e7e;
  --chart-4: #c9a227;
  --chart-grid: #ece8e0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f171b; --surface: #162126; --surface-2: #1b282e; --border: #263840;
    --text: #e3ecee; --muted: #93a6ac; --primary: #4fb0ba; --primary-ink: #0d1b1f; --primary-soft: #193a3f;
    --accent: #ec8a55; --accent-soft: #3b2619; --success: #5cc387; --success-soft: #16301f;
    --warn: #e0a640; --warn-soft: #33270f; --danger: #f2827a; --danger-soft: #3a1a18;
    --side: #0b1316; --side-ink: #cfdde0; --side-muted: #7f979d; --side-active: #1a2b31;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --chart-1: #4fb0ba; --chart-2: #ec8a55; --chart-3: #9cc29f; --chart-4: #e0c15a; --chart-grid: #22323a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f171b; --surface: #162126; --surface-2: #1b282e; --border: #263840;
  --text: #e3ecee; --muted: #93a6ac; --primary: #4fb0ba; --primary-ink: #0d1b1f; --primary-soft: #193a3f;
  --accent: #ec8a55; --accent-soft: #3b2619; --success: #5cc387; --success-soft: #16301f;
  --warn: #e0a640; --warn-soft: #33270f; --danger: #f2827a; --danger-soft: #3a1a18;
  --side: #0b1316; --side-ink: #cfdde0; --side-muted: #7f979d; --side-active: #1a2b31;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --chart-1: #4fb0ba; --chart-2: #ec8a55; --chart-3: #9cc29f; --chart-4: #e0c15a; --chart-grid: #22323a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0 0 10px; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 12.5px; }
h1.mono, h1 .mono, h2.mono { font-size: inherit; letter-spacing: .02em; }
pre { white-space: pre-wrap; word-break: break-word; margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh;
  overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; color: #fff; font-weight: 650; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 13px; letter-spacing: .5px;
}
.brand small { display: block; color: var(--side-muted); font-weight: 500; font-size: 11.5px; }
.nav-group { margin: 12px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 7px;
  color: var(--side-ink); font-size: 13.5px;
}
.nav a:hover { background: var(--side-active); text-decoration: none; }
.nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav .count { background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.side-foot { margin-top: auto; padding: 12px 8px 0; font-size: 12px; color: var(--side-muted); }
.side-foot button { color: var(--side-ink); }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.topbar .spacer { flex: 1; }
.topbar form { margin: 0; }
.app-switch select { font-weight: 600; min-width: 190px; }
.content { padding: 24px 28px 48px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.menu-btn { display: none; }

/* ---------- Cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head p { margin: 2px 0 0; }
.card-body { padding: 16px 18px; }
.card + .card, .card + .grid, .grid + .card, .grid + .grid { margin-top: 16px; }
.grid { display: grid; gap: 16px; align-items: start; }
.grid > * { margin-top: 0 !important; min-width: 0; }
.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)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack > * + * { margin-top: 16px; }

.kpi { padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.accent { border-top: 3px solid var(--accent); }
.kpi.primary { border-top: 3px solid var(--primary); }

.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 200px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; line-height: 19px; white-space: nowrap; }
.badge-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--primary-soft); color: var(--primary); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Buttons & forms ---------- */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 8px;
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; white-space: nowrap;
}
.btn:hover, button:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); padding-left: 6px; padding-right: 6px; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-link { background: none; border: 0; padding: 0; color: var(--primary); font-weight: 500; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin: 0; }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=date],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 120px; resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; line-height: 1.5; min-height: 420px; tab-size: 2; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.check input { margin-top: 3px; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.searchbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.searchbar input[type=search] { max-width: 320px; }
.searchbar select { width: auto; }

/* ---------- Tabs / segmented ---------- */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg a { padding: 6px 12px; font-size: 13px; color: var(--muted); border-right: 1px solid var(--border); }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.seg a:hover { text-decoration: none; color: var(--text); }

/* ---------- Alerts ---------- */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--primary-soft); color: var(--primary); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.reveal { border: 1px dashed var(--accent); background: var(--accent-soft); color: var(--text); }
.reveal code { display: block; margin-top: 6px; padding: 8px 10px; background: var(--surface); border-radius: 6px; word-break: break-all; font-size: 13.5px; }

/* ---------- Meter ---------- */
.meter { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.meter.warn > span { background: var(--warn); }
.meter.danger > span { background: var(--danger); }

/* ---------- Definition lists ---------- */
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; font-weight: 500; word-break: break-word; }

/* ---------- Chat transcript ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 78%; padding: 10px 13px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.debrief { border-color: var(--accent); background: var(--accent-soft); }
.bubble .meta { display: block; font-size: 11.5px; opacity: .7; margin-top: 4px; }
.bubble.flagged { box-shadow: 0 0 0 2px var(--danger); }

/* ---------- Diff ---------- */
.diff { border: 1px solid var(--border); border-radius: 8px; overflow: auto; max-height: 520px; background: var(--surface); }
.diff div { padding: 1px 10px; white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.diff .add { background: var(--success-soft); }
.diff .del { background: var(--danger-soft); text-decoration: line-through; text-decoration-color: rgba(179, 38, 30, .4); }
.diff .add::before { content: "+ "; color: var(--success); }
.diff .del::before { content: "− "; color: var(--danger); }
.diff .same::before { content: "  "; }

.prompt-text { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; max-height: 460px; overflow: auto; }

/* ---------- Pager ---------- */
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .card-body { padding: 26px; }
.auth-brand { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; }
.auth-brand .logo { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }
#qr { background: #fff; padding: 10px; display: inline-block; border-radius: 8px; }

/* ---------- Public legal pages ---------- */
.legal-body { background: var(--surface); }
.legal-wrap { max-width: 780px; margin: 0 auto; padding: 0 20px; }
.legal-top { border-bottom: 1px solid var(--border); background: var(--surface); }
.legal-top .legal-wrap { display: flex; align-items: center; gap: 10px; padding-top: 14px; padding-bottom: 14px; flex-wrap: wrap; }
.legal-top .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.legal-top nav { margin-left: auto; display: flex; gap: 16px; font-size: 14px; }
.legal { padding-top: 28px; padding-bottom: 40px; font-size: 15.5px; line-height: 1.65; }
.legal h1 { font-size: 28px; margin-bottom: 4px; }
.legal h2 { font-size: 18px; margin: 28px 0 8px; }
.legal p, .legal li { max-width: 70ch; }
.legal ul, .legal ol { padding-left: 22px; }
.legal li { margin: 4px 0; }
.legal-summary { background: var(--primary-soft); border-radius: var(--radius); padding: 4px 20px 10px; margin: 20px 0; }
.legal-summary h2 { margin-top: 14px; }
.legal-table { margin: 10px 0; font-size: 14px; border: 1px solid var(--border); border-radius: 8px; display: block; overflow-x: auto; }
.legal-table td { min-width: 140px; }
.legal-form { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin: 12px 0 8px; }
.legal-foot { padding-top: 16px; padding-bottom: 30px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3, .g-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 18px 16px 40px; }
  .g2, .g4 { grid-template-columns: 1fr; }
  .app-switch select { min-width: 0; max-width: 160px; }
  .dl { grid-template-columns: 1fr; gap: 2px 0; }
  .dl dd { margin-bottom: 8px; }
  .bubble { max-width: 92%; }
  th, td { padding: 8px 10px; }
}

/* Feedback replies */
.reply-box { margin-top: 10px; padding: 8px 12px; border-left: 3px solid var(--primary); background: var(--primary-soft); border-radius: 6px; }
.reply-form { margin-top: 8px; }
.reply-form summary { list-style: none; display: inline-block; cursor: pointer; }
.reply-form summary::-webkit-details-marker { display: none; }
.reply-form form { margin-top: 8px; display: grid; gap: 8px; max-width: 640px; }
.reply-form textarea { width: 100%; }
