:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #f8f9fd; --text: #121829; --muted: #66708a; --line: #e5e8f1;
  --brand: #3558f5; --brand-soft: #e9eeff; --brand-ink: #ffffff; --accent: #ffd23f;
  --good: #0f9d63; --good-soft: #e1f6ec; --warn: #d97706; --warn-soft: #fdf0dc; --bad: #dc3a3a; --bad-soft: #fde8e8;
  --shadow: 0 1px 2px rgba(18,24,41,.04), 0 6px 20px rgba(18,24,41,.05);
  --radius: 14px; --sidebar: 244px;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[data-theme="dark"] {
  --bg: #0c1120; --surface: #151b2e; --surface-2: #1a2136; --text: #e8ecf8; --muted: #94a0bd; --line: #262e48;
  --brand: #6f8aff; --brand-soft: #1e2850; --brand-ink: #0c1120;
  --good: #3ccf91; --good-soft: #12342a; --warn: #f5a742; --warn-soft: #3a2b13; --bad: #ff7676; --bad-soft: #3d1b20;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 24px; } h2 { font-size: 15px; } h3 { font-size: 13px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 10px; }
.sp { flex: 1; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* shell */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 18px 14px; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 17px; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; }
.brand .logo svg { width: 18px; height: 18px; stroke: var(--accent); stroke-width: 3; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.side-foot { margin-top: auto; padding: 10px 8px; font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; gap: 12px; align-items: center; padding: 12px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1; max-width: 460px; }
.search input { width: 100%; padding: 9px 12px 9px 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.search svg { position: absolute; left: 11px; top: 9px; color: var(--muted); }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 8px; font-weight: 600; color: var(--muted); font-size: 12.5px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.iconbtn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--muted); }
.iconbtn:hover { color: var(--text); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.content { padding: 26px 28px 60px; max-width: 1380px; width: 100%; margin: 0 auto; }
.pagehead { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.pagehead p { margin: 4px 0 0; color: var(--muted); }
.burger { display: none; }

/* cards & grid */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card > header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 8px; }
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(5, 1fr); margin-bottom: 16px; }
.g-2 { grid-template-columns: 1.6fr 1fr; margin-bottom: 16px; }
.g-3 { grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; }
.kpi { position: relative; overflow: hidden; }
.kpi .lbl { color: var(--muted); font-weight: 550; font-size: 12.5px; display: flex; gap: 8px; align-items: center; }
.kpi .val { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin: 8px 0 2px; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi .ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.kpi.warn .ico { background: var(--warn-soft); color: var(--warn); }
.kpi.good .ico { background: var(--good-soft); color: var(--good); }
.kpi.link { cursor: pointer; transition: transform .12s; }
.kpi.link:hover { transform: translateY(-2px); }
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; margin-bottom: 18px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-weight: 550; font-size: 13px; }

/* chips, badges */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.chip.btn { cursor: pointer; }
.chip.btn.on { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.chip.btn.on-bad { background: var(--bad); color: #fff; border-color: transparent; }
.demo-tag { font-size: 10px; padding: 1px 6px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); font-weight: 700; margin-left: 6px; vertical-align: 1px; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* score ring */
.ring { position: relative; width: 38px; height: 38px; flex: none; }
.ring svg { width: 38px; height: 38px; transform: rotate(-90deg); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.ring.lg { width: 64px; height: 64px; } .ring.lg svg { width: 64px; height: 64px; } .ring.lg span { font-size: 19px; }

/* lists */
.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; align-items: center; padding: 11px 6px; border-top: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.item:first-child { border-top: 0; }
.item:hover { background: var(--surface-2); }
.item .t { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .m { font-size: 12px; color: var(--muted); }
.item .body { flex: 1; min-width: 0; }

/* charts */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 170px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.bars .col { width: 100%; max-width: 34px; border-radius: 7px 7px 3px 3px; background: linear-gradient(180deg, var(--brand), color-mix(in srgb, var(--brand) 55%, transparent)); min-height: 3px; transition: filter .15s; }
.bars .b:hover .col { filter: brightness(1.15); }
.bars .lab { font-size: 11px; color: var(--muted); }
.bars .v { font-size: 11px; font-weight: 650; }
.hbar { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin-bottom: 11px; }
.hbar .track { grid-column: 1 / -1; height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.hbar .fill { height: 100%; border-radius: 99px; background: var(--brand); }
.hbar .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel .step { display: grid; grid-template-columns: 110px 1fr 40px; gap: 10px; align-items: center; }
.funnel .bar { height: 22px; border-radius: 7px; background: var(--brand-soft); position: relative; overflow: hidden; }
.funnel .bar i { position: absolute; inset: 0 auto 0 0; background: var(--brand); border-radius: 7px; opacity: .85; }
.donut { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut svg { width: 150px; height: 150px; flex: none; }
.legend { display: grid; gap: 5px; flex: 1; min-width: 140px; font-size: 12.5px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.legend b { margin-left: auto; font-variant-numeric: tabular-nums; }

/* filters / table */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar select, .toolbar input[type=search], .field input, .field select, .field textarea { padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); outline: none; }
.toolbar input[type=search] { min-width: 260px; flex: 1; }
.toolbar select:focus, .field input:focus, .field select:focus, .field textarea:focus, .toolbar input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.row-click { cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .title { font-weight: 600; max-width: 520px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tbl-wrap { padding: 0; overflow: hidden; }
.tbl-scroll { overflow-x: auto; }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; padding: 14px; }
.stage-sel { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 12.5px; font-weight: 600; }

/* kanban */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 14px; align-items: start; }
.kcol { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-height: 300px; }
.kcol.over { outline: 2px dashed var(--brand); background: var(--brand-soft); }
.kcol h3 { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; cursor: grab; box-shadow: var(--shadow); }
.kcard.dragging { opacity: .4; }
.kcard .t { font-weight: 600; margin-bottom: 8px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.kcard .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }

/* sources */
.src-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.src h3 { font-size: 14.5px; margin-bottom: 4px; }
.src .stags { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.src .extra { display: none; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 12.5px; }
.src.open .extra { display: block; }
.src .extra dt { color: var(--muted); font-weight: 600; margin-top: 6px; }
.src .extra dd { margin: 0; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 99px; background: var(--line); border: 0; margin: 0; cursor: pointer; transition: background .15s; }
.switch input:checked { background: var(--good); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; pointer-events: none; }
.switch:has(input:checked)::after { transform: translateX(16px); }
.stars { color: var(--accent); letter-spacing: 1px; filter: drop-shadow(0 0 .5px rgba(0,0,0,.4)); }

/* drawer & modal */
.overlay { position: fixed; inset: 0; background: rgba(8,12,24,.45); z-index: 50; display: flex; justify-content: flex-end; animation: fade .15s; }
.overlay.center { justify-content: center; align-items: center; }
.drawer { width: min(640px, 100%); height: 100%; background: var(--surface); overflow-y: auto; padding: 26px; box-shadow: -10px 0 40px rgba(0,0,0,.2); animation: slide .2s; }
.modal { width: min(560px, 94%); max-height: 92vh; overflow-y: auto; background: var(--surface); border-radius: 16px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
@keyframes fade { from { opacity: 0 } } @keyframes slide { from { transform: translateX(40px); opacity: 0 } }
.drawer h2 { font-size: 19px; line-height: 1.3; margin: 10px 0 6px; }
.dsec { margin-top: 22px; }
.dsec > h3 { margin-bottom: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-size: 11.5px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.facts dt { font-size: 12px; color: var(--muted); } .facts dd { margin: 2px 0 0; font-weight: 600; }
.stagebar { display: flex; flex-wrap: wrap; gap: 6px; }
.reason { display: grid; grid-template-columns: 150px 1fr 54px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 12.5px; }
.reason .track { height: 6px; background: var(--surface-2); border-radius: 9px; border: 1px solid var(--line); overflow: hidden; }
.reason .fill { height: 100%; background: var(--brand); }
.task { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.task.done span { text-decoration: line-through; color: var(--muted); }
.task input { width: 17px; height: 17px; accent-color: var(--good); }
.task .x { margin-left: auto; border: 0; background: none; color: var(--muted); }
.ev { font-size: 12.5px; padding: 6px 0; color: var(--muted); border-left: 2px solid var(--line); padding-left: 12px; margin-left: 4px; }
.ev b { color: var(--text); font-weight: 600; }
.field { display: grid; gap: 5px; margin-bottom: 14px; } .field label { font-weight: 600; font-size: 12.5px; }
.field .hint { font-size: 12px; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.tags input { border: 0; outline: 0; background: transparent; min-width: 140px; flex: 1; padding: 3px; }
.tags .chip { cursor: pointer; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--brand) 22%, transparent), transparent 60%),
  radial-gradient(700px 400px at 100% 110%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%), var(--bg); }
.login .box { width: min(430px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: 0 20px 60px rgba(18,24,41,.14); }
.login .brand { justify-content: center; padding-bottom: 12px; font-size: 20px; }
.login p { color: var(--muted); text-align: center; margin: 0 0 22px; }
.login .field input { padding: 13px 14px; font-size: 16px; }
.login .code { text-align: center; letter-spacing: .5em; font-size: 26px !important; font-weight: 700; }
.login .btn { width: 100%; justify-content: center; padding: 13px; font-size: 15px; }
.login .err { color: var(--bad); font-size: 13px; margin: -4px 0 12px; min-height: 18px; text-align: center; }
.login .ok { color: var(--good); font-size: 13px; text-align: center; margin-bottom: 12px; }
.login .top { position: fixed; top: 16px; right: 16px; display: flex; gap: 8px; }
.linkbtn { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 8px; width: 100%; }

#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.25); animation: fade .2s; }
.skeleton { height: 90px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { to { background-position: -200% 0 } }

@media (max-width: 1180px) { .g-kpi { grid-template-columns: repeat(3, 1fr); } .g-2, .g-3 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; transform: translateX(-100%); transition: transform .2s; width: 270px; }
  .sidebar.show { transform: none; box-shadow: 10px 0 40px rgba(0,0,0,.25); }
  .burger { display: grid; }
  .topbar { padding: 10px 14px; } .content { padding: 18px 14px 50px; }
  .g-kpi { grid-template-columns: 1fr 1fr; }
  .search { display: none; }
  .tbl thead { display: none; } .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { padding: 12px; border-bottom: 1px solid var(--line); } .tbl td { border: 0; padding: 3px 0; }
  .facts { grid-template-columns: 1fr; } .two { grid-template-columns: 1fr; }
  .reason { grid-template-columns: 110px 1fr 44px; }
}

.bell { position: relative; }
.badge { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.badge[hidden] { display: none; }
.popover { position: fixed; top: 60px; right: 90px; width: min(400px, 94vw); max-height: 70vh; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.28); z-index: 70; overflow: hidden; display: flex; flex-direction: column; }
.plist { overflow-y: auto; }
.pitem { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; align-items: flex-start; }
.pitem:hover { background: var(--surface-2); } .pitem.unread { background: var(--brand-soft); }
.runline { font-size: 12px; color: var(--muted); margin-bottom: 10px; } .runline.err { color: var(--bad); }

.pastezone { min-height: 110px; margin: 14px 0; padding: 14px; border: 2px dashed var(--line); border-radius: 12px; background: var(--surface-2); outline: none; overflow: hidden; font-weight: 600; color: var(--good); }
.pastezone:empty::before { content: attr(data-ph); color: var(--muted); font-weight: 400; }
.pastezone:focus { border-color: var(--brand); }

.prio-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; margin-top: 6px; }
.prio-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.prio-row > span:first-child { flex: 1; font-weight: 550; }
.prio-row select { padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 700; }
