:root {
  --bg: #f5f6f8; --panel: #ffffff; --panel-2: #f9fafb; --ink: #16191d; --muted: #5f6873; --line: #e3e6eb;
  --accent: #c2410c; --accent-ink: #ffffff; --accent-soft: #fff1e8;
  --side: #14171c; --side-ink: #c9ced6; --side-active: #242932;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e2; --bad: #b91c1c; --bad-soft: #fdecec;
  --info: #1d4ed8; --info-soft: #e8efff;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #171a20; --panel-2: #1c2027; --ink: #e8eaee; --muted: #9aa3ae; --line: #2a2f38;
    --accent: #f97316; --accent-ink: #1a0d04; --accent-soft: #2b1a0e;
    --side: #0b0d10; --side-ink: #b7bec8; --side-active: #1e232b;
    --ok: #4ade80; --ok-soft: #0f2a19; --warn: #fbbf24; --warn-soft: #2b2110; --bad: #f87171; --bad-soft: #2d1414;
    --info: #93b4ff; --info-soft: #152040; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #171a20; --panel-2: #1c2027; --ink: #e8eaee; --muted: #9aa3ae; --line: #2a2f38;
  --accent: #f97316; --accent-ink: #1a0d04; --accent-soft: #2b1a0e;
  --side: #0b0d10; --side-ink: #b7bec8; --side-active: #1e232b;
  --ok: #4ade80; --ok-soft: #0f2a19; --warn: #fbbf24; --warn-soft: #2b2110; --bad: #f87171; --bad-soft: #2d1414;
  --info: #93b4ff; --info-soft: #152040; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); }
code { font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex: none; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 10px; color: #fff; }
.brand small { display: block; color: var(--side-ink); font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }
nav { padding: 6px 10px 12px; flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6c7480; margin: 14px 8px 4px; }
nav a { display: block; color: var(--side-ink); padding: 7px 10px; border-radius: 8px; font-size: 14px; }
nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.ai-pill { margin: 10px; padding: 8px 10px; border-radius: 8px; font-size: 12px; background: var(--side-active); }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.jobs-indicator { position: fixed; right: 18px; bottom: 18px; z-index: 20; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 999px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
main { padding: 26px 30px 60px; max-width: 1320px; width: 100%; outline: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 75ch; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.stack > * + * { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi span { color: var(--muted); font-size: 12.5px; }
.kpi.alert b { color: var(--bad); }

button, .btn { font: inherit; font-size: 13.5px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 13px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.danger { color: var(--bad); }
button.small, .btn.small { padding: 4px 9px; font-size: 12.5px; }
button:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { padding: 6px 10px; }

input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 14px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > input, .inline > select { width: auto; flex: 1; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.b-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.b-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.b-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.b-acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.list li:last-child { border-bottom: 0; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 6px 0; display: flex; gap: 8px; align-items: flex-start; }
.checks .ic { width: 20px; flex: none; text-align: center; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; border-radius: 0; background: none; padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.progress { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; background: var(--accent); }
.progress.ok > i { background: var(--ok); } .progress.warn > i { background: var(--warn); } .progress.bad > i { background: var(--bad); }

.clock { display: flex; gap: 4px; margin: 8px 0 4px; }
.clock span { flex: 1; height: 6px; border-radius: 3px; background: var(--panel-2); border: 1px solid var(--line); }
.clock span.on { background: var(--ok); border-color: transparent; }
.clock span.warn { background: var(--warn); border-color: transparent; }
.clock span.bad { background: var(--bad); border-color: transparent; }

.funnel { display: grid; gap: 6px; }
.funnel-row { display: grid; grid-template-columns: 110px 1fr 40px; gap: 10px; align-items: center; font-size: 13px; }
.funnel-row .bar { height: 18px; background: var(--accent); border-radius: 4px; opacity: .85; min-width: 2px; }

.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h3 { display: flex; justify-content: space-between; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.col.drop { outline: 2px dashed var(--accent); }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; margin-bottom: 8px; cursor: grab; font-size: 13px; }
.kcard b { display: block; }

.report h3 { margin-top: 14px; }
.report ul { margin: 4px 0 10px; padding-left: 18px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.sources { font-size: 12px; color: var(--muted); word-break: break-all; }
.draft { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 12px; white-space: pre-wrap; font-size: 13.5px; position: relative; }
.copy { position: absolute; top: 6px; right: 6px; }
.notice { padding: 10px 12px; border-radius: 9px; background: var(--warn-soft); color: var(--ink); font-size: 13px; border-left: 3px solid var(--warn); margin-bottom: 14px; }
.notice.info { background: var(--info-soft); border-left-color: var(--info); }
.notice.bad { background: var(--bad-soft); border-left-color: var(--bad); }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.thumb { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.thumb img { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--panel-2); display: block; }
.thumb div { padding: 8px; font-size: 12px; }
.chat { display: flex; flex-direction: column; gap: 12px; min-height: 360px; max-height: 62vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 80%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12.5px; padding: 5px 10px; border-radius: 999px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: min(90vw, 560px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--ink); width: min(620px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 12, 16, .45); }
dialog form { padding: 20px; max-height: 85vh; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .g-side, .g3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 800px) {
  .sidebar { position: fixed; left: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .topbar { display: flex; }
  main { padding: 18px 16px 60px; }
  .g2 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .msg { max-width: 92%; }
}
@media print { .sidebar, .topbar, .jobs-indicator { display: none; } main { padding: 0; } }
