:root {
  color-scheme: dark;
  --bg: #08101d;
  --surface: #101a2a;
  --surface-2: #152235;
  --border: #24334a;
  --text: #f3f6fb;
  --muted: #8fa0b8;
  --accent: #62e6a7;
  --accent-dark: #0d3d2c;
  --danger: #ff6b78;
  --warning: #f5c866;
  --blue: #76a7ff;
  --radius: 16px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: 34px; letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 25px; letter-spacing: -.025em; }
h3 { margin-bottom: 8px; font-size: 17px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #173052 0, transparent 35%), var(--bg); }
.login-card { width: min(410px, 100%); display: grid; gap: 20px; padding: 34px; background: rgba(16, 26, 42, .94); border: 1px solid var(--border); border-radius: 22px; box-shadow: 0 30px 80px #0008; }
.brand-mark { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 15px; background: var(--accent); color: #062318; font-weight: 900; letter-spacing: -.05em; }
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
label { color: #c6d1e0; font-size: 13px; font-weight: 650; }
input, textarea, select { width: 100%; margin-top: 7px; padding: 12px 13px; color: var(--text); background: #0a1422; border: 1px solid var(--border); border-radius: 10px; outline: 0; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #62e6a719; }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.form-error { min-height: 18px; margin: -8px 0; color: var(--danger); font-size: 13px; }
.button { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 750; cursor: pointer; transition: .18s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: wait; transform: none; }
.button.primary { background: var(--accent); color: #052619; }
.button.secondary { background: var(--surface-2); border: 1px solid var(--border); }
.button.ghost { background: transparent; border: 1px solid var(--border); }
.button.danger { background: #3b1821; color: #ff9ca5; }
.button.wide { width: 100%; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); cursor: pointer; font-size: 21px; }
.text-button { border: 0; background: none; color: var(--accent); cursor: pointer; font-weight: 700; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 24px 16px; border-right: 1px solid var(--border); background: #0b1422; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 10px 28px; font-size: 18px; font-weight: 850; }
.nav { display: grid; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 11px 12px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; text-align: left; font-weight: 700; }
.nav-item span { width: 20px; color: #c8d5e7; font-size: 18px; text-align: center; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--accent-dark); color: var(--accent); }
.nav-item.logout { margin-top: auto; }
.workspace { min-width: 0; padding: 0 34px 70px; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 25px 0 22px; background: linear-gradient(var(--bg) 82%, transparent); }
.top-actions { display: flex; gap: 8px; }
.view { display: none; }
.view.active { display: block; animation: enter .2s ease; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { min-height: 112px; padding: 17px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.stat-card .label { color: var(--muted); font-size: 12px; font-weight: 700; }
.stat-card strong { display: block; margin-top: 14px; font-size: 27px; letter-spacing: -.04em; }
.stat-card.accent { background: linear-gradient(145deg, #18382e, #10251f); border-color: #275842; }
.panel { padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.task-list { display: grid; gap: 9px; }
.task-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: center; padding: 15px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; transition: .16s ease; }
.task-row:hover { border-color: #40536e; background: var(--surface-2); }
.compact .task-row { border-left: 3px solid var(--accent); }
.task-title { margin: 0 0 7px; overflow: hidden; color: var(--text); font-size: 15px; font-weight: 760; text-overflow: ellipsis; white-space: nowrap; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12px; }
.score { min-width: 56px; padding: 7px 10px; border-radius: 999px; background: #122234; color: var(--blue); font-size: 13px; font-weight: 850; text-align: center; }
.score.high { background: var(--accent-dark); color: var(--accent); }
.score.low { background: #321b22; color: #ff8994; }
.badge { display: inline-flex; align-items: center; padding: 3px 7px; border-radius: 6px; background: var(--surface-2); color: #b9c7da; font-size: 11px; font-weight: 700; }
.filters { display: grid; grid-template-columns: 1fr minmax(240px, .35fr); gap: 20px; align-items: center; margin-bottom: 14px; padding: 14px; }
.search { position: relative; }
.search span { position: absolute; left: 13px; top: 19px; color: var(--muted); }
.search input { margin: 0; padding-left: 36px; }
.range-label { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; }
.range-label input { margin: 0; padding: 0; accent-color: var(--accent); }
.range-label.large { grid-template-columns: 55px 1fr; margin-top: 10px; }
.range-label.large b { font-size: 22px; color: var(--accent); }
.empty { padding: 45px 20px; color: var(--muted); text-align: center; }

.analytics-grid, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.setting-card { display: grid; align-content: start; gap: 14px; }
.setting-icon { width: 43px; height: 43px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); font-size: 21px; }
.funnel { display: grid; gap: 9px; margin-top: 22px; }
.funnel-row { display: grid; grid-template-columns: 100px 1fr 38px; align-items: center; gap: 10px; font-size: 12px; }
.track { height: 9px; overflow: hidden; border-radius: 10px; background: #091321; }
.fill { height: 100%; border-radius: inherit; background: var(--accent); }
.bar-chart { height: 215px; display: flex; align-items: flex-end; gap: 14px; padding-top: 22px; }
.bar-item { flex: 1; display: grid; grid-template-rows: 1fr auto; height: 100%; gap: 8px; color: var(--muted); font-size: 11px; text-align: center; }
.bar { align-self: end; min-height: 3px; border-radius: 7px 7px 2px 2px; background: linear-gradient(var(--accent), #2a8d67); }
.reason-list { display: grid; gap: 8px; margin-top: 14px; }
.reason { display: flex; justify-content: space-between; gap: 20px; padding: 12px; border-radius: 9px; background: var(--surface-2); }

.task-dialog { width: min(1050px, calc(100% - 28px)); height: min(90vh, 900px); padding: 0; color: var(--text); border: 1px solid var(--border); border-radius: 20px; background: var(--bg); box-shadow: 0 40px 100px #000b; }
.task-dialog::backdrop { background: #02060dcc; backdrop-filter: blur(5px); }
.dialog-shell { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 22px 24px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { max-width: 800px; }
.detail-content { overflow-y: auto; padding: 22px 24px 40px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr); gap: 16px; }
.detail-stack { display: grid; align-content: start; gap: 14px; }
.description { line-height: 1.65; white-space: pre-wrap; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.fact { padding: 11px; border-radius: 9px; background: var(--surface-2); }
.fact span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.feedback-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.feedback-actions .selected { outline: 2px solid var(--accent); }
.proposal-box { padding: 15px; border-radius: 11px; background: #091321; border: 1px solid var(--border); white-space: pre-wrap; line-height: 1.6; }
.proposal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chat { display: grid; gap: 10px; max-height: 360px; overflow-y: auto; padding: 4px; }
.bubble { max-width: 88%; padding: 10px 12px; border-radius: 12px; line-height: 1.5; white-space: pre-wrap; }
.bubble.user, .bubble.user_edit { justify-self: end; background: #254a7b; }
.bubble.assistant { background: var(--surface-2); }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 10px; }
.chat-form input { margin: 0; }
.outcome-form { display: grid; gap: 11px; }
.inline-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.external-link { color: var(--accent); text-decoration: none; }
.toast { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: 360px; padding: 12px 16px; border-radius: 10px; background: #effff7; color: #08271b; box-shadow: 0 15px 40px #0008; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #ffecef; color: #50151c; }
.mobile-nav { display: none; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .workspace { padding: 0 14px 95px; }
  .topbar { padding-top: calc(17px + env(safe-area-inset-top)); }
  .topbar h2 { font-size: 22px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .stat-card { min-height: 100px; }
  .filters, .analytics-grid, .settings-grid, .detail-grid { grid-template-columns: 1fr; }
  .filters { gap: 12px; }
  .task-row { gap: 10px; padding: 13px; }
  .task-dialog { width: 100%; max-width: none; height: 94vh; margin: auto 0 0; border-radius: 20px 20px 0 0; }
  .dialog-head, .detail-content { padding-left: 16px; padding-right: 16px; }
  .dialog-head h2 { font-size: 18px; }
  .mobile-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); padding: 7px 8px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: #0b1422ee; backdrop-filter: blur(15px); }
  .mobile-nav button { display: grid; gap: 3px; place-items: center; padding: 5px; border: 0; background: none; color: var(--muted); font-size: 10px; }
  .mobile-nav button span { font-size: 19px; }
  .mobile-nav button.active { color: var(--accent); }
  .login-card { padding: 26px 22px; }
  .chat-form { grid-template-columns: 1fr; }
}
