:root {
  --bg: #12161C; --surface: #1C222B; --raised: #262E39; --border: #3A4452;
  --text: #EEF2F6; --muted: #9AA6B4; --accent: #2FB8E6; --danger: #F0524F; --warning: #F2B233; --success: #4CC26A;
  --common: #9AA3AD; --uncommon: #4CC26A; --rare: #3B8CF0; --epic: #A55CF0; --legendary: #F2B233;
  --radius: 10px; --nav-h: 64px;
  font-family: "Chakra Petch", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }

/* login */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
input, textarea, select { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: 16px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* buttons */
.btn { border: 1px solid var(--border); background: var(--raised); border-radius: 8px; padding: 10px 14px; min-height: 44px; cursor: pointer; font-size: 15px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121A; font-weight: 600; }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.good { border-color: var(--success); color: var(--success); background: transparent; }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* layout: mobile first, bottom navigation */
.app { min-height: 100%; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 1px solid var(--border); z-index: 10; }
.nav .brand, .nav .logout { display: none; }
.nav button { flex: 1; background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 12px; color: var(--muted); position: relative; cursor: pointer; }
.nav button .ico { font-size: 20px; line-height: 1; }
.nav button.active { color: var(--accent); }
.badge { position: absolute; top: 8px; left: 55%; background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; font-style: normal; }
.badge:empty { display: none; }
main { padding: 16px 14px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
h2 { font-size: 20px; margin: 4px 0 14px; }
h3 { font-size: 16px; margin: 0 0 10px; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* desktop: sidebar */
@media (min-width: 900px) {
  .nav { top: 0; bottom: 0; right: auto; width: 210px; height: auto; flex-direction: column; border-top: 0; border-right: 1px solid var(--border); padding: 16px 10px; gap: 4px; }
  .nav .brand { display: block; font-weight: 700; font-size: 18px; padding: 6px 12px 16px; }
  .nav .logout { display: flex; margin-top: auto; }
  .nav button { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 10px 12px; border-radius: 8px; }
  .nav button.active { background: var(--raised); }
  .badge { position: static; margin-left: auto; }
  main { margin-left: 210px; padding: 24px 28px; }
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.three { grid-template-columns: repeat(3, 1fr); }
}

/* overview */
.stat { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--border); }
.stat:last-child { border-bottom: 0; }
.stat b { font-size: 18px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 13px; border: 1px solid var(--border); }
.pill.on { color: var(--success); border-color: var(--success); }
.pill.busy { color: var(--warning); border-color: var(--warning); }
.pill.off { color: var(--muted); }
.needs li { margin: 6px 0; }
.pre { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.45; }
.log { font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; font-size: 12px; background: #0B0E12; border-radius: 8px; padding: 10px;
  max-height: 60vh; overflow: auto; white-space: pre-wrap; word-break: break-word; }

/* warnings */
.warn { border-radius: 8px; padding: 12px; margin-bottom: 12px; border: 1px solid; }
.warn.danger { border-color: var(--danger); background: rgba(240,82,79,.12); }
.warn.caution { border-color: var(--warning); background: rgba(242,178,51,.10); }
.warn.info { border-color: var(--accent); background: rgba(47,184,230,.08); }

/* assets */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chip { white-space: nowrap; }
.chip.active { border-color: var(--accent); color: var(--accent); }
.assets { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 600px) { .assets { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .assets { grid-template-columns: repeat(4, 1fr); } }
.asset { padding: 0; overflow: hidden; cursor: pointer; text-align: left; }
.asset .thumb { aspect-ratio: 1; background: #0B0E12; display: flex; align-items: center; justify-content: center; }
.asset .thumb img { width: 100%; height: 100%; object-fit: contain; }
.asset .meta { padding: 8px 10px; font-size: 13px; }
.asset .meta b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; color: var(--muted); }
.status.escalated { color: var(--danger); }
.status.awaiting_review, .status.concept_review { color: var(--warning); }
.status.approved { color: var(--success); }
.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; }
.gallery img { height: 240px; max-width: 85%; object-fit: contain; background: #0B0E12; border-radius: 8px; scroll-snap-align: start; }
audio { width: 100%; }

/* files */
.filelist button { width: 100%; text-align: left; }
.editor { width: 100%; min-height: 55vh; font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; font-size: 14px; line-height: 1.5; resize: vertical; }
.md h1, .md h2, .md h3 { margin: 16px 0 8px; } .md h1 { font-size: 22px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md p, .md li { line-height: 1.5; } .md code { background: #0B0E12; padding: 1px 5px; border-radius: 4px; }
.md pre { background: #0B0E12; padding: 10px; border-radius: 8px; overflow-x: auto; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; } .md td, .md th { border: 1px solid var(--border); padding: 6px 8px; }

/* modal and toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.modal-box { width: 100%; max-width: 720px; max-height: 90vh; overflow: auto; border-radius: 14px 14px 0 0; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .modal { align-items: center; } .modal-box { border-radius: 14px; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); background: var(--raised);
  border: 1px solid var(--border); padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: 90vw; }
@media (min-width: 900px) { .toast { bottom: 24px; } }

.meter { height: 8px; background: var(--bg); border-radius: 6px; overflow: hidden; margin-top: 4px; }
.meter div { height: 100%; border-radius: 6px; }
.qcard { border-top: 1px solid var(--border); padding-top: 10px; }
.qcard:first-of-type { border-top: 0; padding-top: 0; }
