:root {
  --bg: #0e1120; --panel: #161a2e; --panel-2: #1d2240; --line: #2a3055; --text: #e8ebf7; --muted: #9aa2c0;
  --accent: #7aa2ff; --gold: #ffd36e; --good: #3fcf8e; --warn: #ffb547; --bad: #ff6b7a; --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.app { display: grid; grid-template-columns: 220px 1fr; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 8px 18px; }
.brand img { width: 30px; height: 30px; }
.nav button { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: none; border: 0; padding: 10px 12px; border-radius: 10px; color: var(--muted); cursor: pointer; text-align: left; }
.nav button.on, .nav button:hover { background: var(--panel-2); color: var(--text); }
.badge { background: var(--gold); color: #1b1600; border-radius: 99px; font-size: 12px; font-weight: 700; padding: 0 7px; min-width: 20px; text-align: center; }
.badge:empty { display: none; }
.side .foot { margin-top: auto; color: var(--muted); font-size: 13px; padding: 8px; display: grid; gap: 8px; }
.meter { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--good); }
main { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.view { display: none; flex: 1; overflow: auto; padding: 22px clamp(16px, 3vw, 36px); }
.view.on { display: block; }
#view-chat.on { display: flex; flex-direction: column; padding: 0; }
h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.pill { display: inline-block; border: 1px solid var(--line); border-radius: 99px; padding: 1px 9px; font-size: 12px; color: var(--muted); }
.dry { border-color: var(--warn); color: var(--warn); }

/* chat */
.msgs { flex: 1; overflow: auto; padding: 22px clamp(16px, 3vw, 36px); display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 760px; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.av { flex: none; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #0e1120; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me .bubble { background: #233066; border-color: #33448a; }
.who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px clamp(12px, 3vw, 36px) 14px; display: grid; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 3px 11px; font-size: 13px; cursor: pointer; color: var(--muted); }
.chip:hover { color: var(--text); border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: flex-end; }
textarea, input[type=text], select { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%; }
textarea { resize: none; min-height: 46px; max-height: 160px; }
.btn { background: var(--accent); color: #0b1130; border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 650; cursor: pointer; white-space: nowrap; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.good { background: var(--good); color: #04210f; }
.btn.bad { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; width: 46px; height: 46px; cursor: pointer; flex: none; }

/* cards */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 8px; align-content: start; }
.card h3 { margin: 0; font-size: 16px; }
.meta { color: var(--muted); font-size: 13px; }
.status { font-size: 12px; font-weight: 650; border-radius: 99px; padding: 1px 9px; justify-self: start; }
.s-queued { background: #2a3055; color: var(--muted); } .s-working { background: #1e3a6e; color: #9cc0ff; }
.s-needs_approval, .s-pending { background: #4a3a10; color: var(--gold); } .s-done, .s-approved, .s-info { background: #113a29; color: var(--good); }
.s-failed, .s-rejected { background: #45161e; color: var(--bad); } .s-cancelled, .s-revise { background: #2a3055; color: var(--muted); }
.zone { margin-bottom: 24px; }
.zone h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { color: var(--muted); padding: 30px 0; }
table.jobs { width: 100%; border-collapse: collapse; }
table.jobs td, table.jobs th { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.jobs th { color: var(--muted); font-weight: 500; font-size: 13px; }

/* modal + markdown */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 18px; width: min(860px, 94vw); max-height: 88vh; padding: 0; }
dialog::backdrop { background: rgba(5, 7, 15, .7); }
.dlg-head { position: sticky; top: 0; background: var(--panel); padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.dlg-body { padding: 4px 20px 20px; }
.dlg-foot { position: sticky; bottom: 0; background: var(--panel); padding: 14px 20px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.md table { border-collapse: collapse; margin: 10px 0; } .md td, .md th { border: 1px solid var(--line); padding: 5px 10px; }
.md code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }
.md h1 { font-size: 20px; } .md h2 { font-size: 16px; margin-top: 22px; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.sw { display: grid; gap: 4px; font-size: 12px; color: var(--muted); text-align: center; }
.sw i { width: 64px; height: 44px; border-radius: 10px; border: 1px solid var(--line); display: block; }
.shots { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.shots img { max-height: 220px; max-width: 100%; border-radius: 10px; border: 1px solid var(--line); background: #fff; }

/* hex map */
.map svg { width: 100%; height: auto; max-height: 70vh; }
.hex-label { font-size: 12px; fill: var(--text); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.bot { animation: bob 1.6s ease-in-out infinite; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 26px; display: grid; gap: 12px; }
.err { color: var(--bad); min-height: 20px; font-size: 14px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { order: 2; flex-direction: row; padding: 6px; border-right: 0; border-top: 1px solid var(--line); }
  .brand, .side .foot { display: none; }
  .nav { display: flex; width: 100%; }
  .nav button { flex-direction: column; justify-content: center; font-size: 12px; padding: 6px 4px; gap: 2px; }
  .msg { max-width: 100%; }
}
