:root {
  --navy: #121a2b;
  --yellow: #f5c518;
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #f8f7f3;
  --text: #121a2b;
  --muted: #667085;
  --line: #e4e2db;
  --hot: #16a34a;
  --hot-bg: #e7f7ed;
  --warm: #d4a106;
  --warm-bg: #fdf5d8;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(18, 26, 43, .06), 0 4px 14px rgba(18, 26, 43, .06);
  --radius: 14px;
  --bar-a: #121a2b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1320;
    --surface: #151d2e;
    --surface-2: #1b2438;
    --text: #eef0f4;
    --muted: #98a2b3;
    --line: #26314a;
    --hot: #34d27a;
    --hot-bg: rgba(52, 210, 122, .12);
    --warm: #f2c94c;
    --warm-bg: rgba(242, 201, 76, .12);
    --danger: #f87171;
    --bar-a: #6b8bd6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.muted { color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: background .15s, transform .05s, border-color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--yellow); border-color: var(--yellow); color: #121a2b; }
.btn.primary:hover { filter: brightness(.96); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon { padding: 8px 11px; font-size: 18px; line-height: 1; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.big { padding: 13px 16px; font-size: 16px; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }

input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(245, 197, 24, .25); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--text); font-weight: 400; font-size: 15px; }
.form-error { color: var(--danger); min-height: 1em; margin: 0; font-size: 14px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .2px; font-size: 17px; }
.logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--navy);
  background-image: linear-gradient(var(--yellow), var(--yellow)), linear-gradient(var(--yellow), var(--yellow)), linear-gradient(var(--yellow), var(--yellow)), linear-gradient(var(--yellow), var(--yellow));
  background-size: 7px 7px; background-repeat: no-repeat;
  background-position: 5px 5px, 14px 5px, 5px 14px, 14px 14px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--navy); }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 18px; padding: 28px;
  display: flex; flex-direction: column; gap: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card h1 { font-size: 24px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--navy); color: #fff;
}
.topbar .brand { color: #fff; }
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tab { background: transparent; border: 0; color: #c9cfda; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.tab:hover { color: #fff; background: rgba(255,255,255,.06); }
.tab.active { color: var(--navy); background: var(--yellow); }
.top-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.topbar .btn.ghost { color: #fff; }
.topbar .btn.ghost:hover { background: rgba(255,255,255,.08); }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 170px; padding: 6px; z-index: 30;
}
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

.view { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }

/* Toolbar */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search] { flex: 1 1 220px; max-width: 360px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.seg button.active { background: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.active { background: var(--yellow); color: #121a2b; } }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.hot { background: var(--hot); }
.dot.warm { background: var(--warm); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 26px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.hero { background: var(--navy); color: #fff; border-color: var(--navy); }
.stat.hero .k, .stat.hero .s { color: #c9cfda; }
.stat.hero .v { color: var(--yellow); }

/* Bulk bar */
.bulkbar {
  position: sticky; top: 58px; z-index: 15; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.bulkbar select { width: auto; background: #1e2a42; color: #fff; border-color: #2c3a58; padding: 6px 10px; }
.bulkbar .btn.ghost { color: #fff; }

/* Board */
.board { display: grid; grid-template-columns: repeat(4, minmax(250px, 1fr)); gap: 14px; align-items: start; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 160px; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.col-head h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .5px; }
.col-head .sum { margin-left: auto; font-size: 13px; color: var(--muted); font-weight: 600; }
.count { background: var(--line); color: var(--text); border-radius: 99px; padding: 1px 8px; font-size: 12px; font-weight: 700; }
.col.closed .col-head { background: var(--navy); color: #fff; border-radius: var(--radius) var(--radius) 0 0; }
.col.closed .col-head .sum { color: var(--yellow); }
.col.closed .count { background: var(--yellow); color: #121a2b; }
.col-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 80px; flex: 1; transition: background .15s; border-radius: 0 0 var(--radius) var(--radius); }
.col-body.over { background: rgba(245, 197, 24, .15); outline: 2px dashed var(--yellow); outline-offset: -6px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 6px; }

.card {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--warm);
  border-radius: 11px; padding: 10px 12px 10px 12px; cursor: pointer; box-shadow: 0 1px 2px rgba(18,26,43,.05);
  transition: transform .12s, box-shadow .12s;
}
.card.hot { border-left-color: var(--hot); }
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.card.dragging { opacity: .45; }
.card.selected { outline: 2px solid var(--yellow); }
.card.new-flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px rgba(245,197,24,.7); } 100% { box-shadow: 0 0 0 0 rgba(245,197,24,0); } }
.card-top { display: flex; gap: 8px; align-items: flex-start; }
.card-top input[type=checkbox] { width: 17px; height: 17px; margin: 2px 0 0; flex: none; accent-color: var(--yellow); cursor: pointer; }
.card-name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 13px; color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card-foot { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.pill { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; display: inline-flex; align-items: center; gap: 5px; }
.pill.hot { background: var(--hot-bg); color: var(--hot); }
.pill.warm { background: var(--warm-bg); color: var(--warm); }
.pill.urgent { background: var(--danger); color: #fff; }
.pill.value { background: var(--navy); color: var(--yellow); }
.card-foot .next { margin-left: auto; font-size: 12px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 600; }
.card-foot .next:hover { border-color: var(--yellow); background: var(--yellow); color: #121a2b; }

.lost { margin-top: 18px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); }
.lost summary { padding: 12px 14px; cursor: pointer; font-weight: 700; text-transform: uppercase; font-size: 14px; letter-spacing: .5px; display: flex; gap: 8px; align-items: center; }
.lost-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.lost .card { opacity: .8; border-left-color: var(--muted); }

/* Dialogs */
.dlg { border: 0; padding: 0; border-radius: 18px; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.dlg.small { width: min(420px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(10, 15, 26, .55); backdrop-filter: blur(2px); }
.dlg form, .dlg-inner { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dlg-head { display: flex; align-items: flex-start; gap: 10px; padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 20px; }
.dlg-head > :last-child { margin-left: auto; }
.dlg-body { padding: 16px 20px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dlg-foot .spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .full { grid-column: 1 / -1; }
.paste { background: var(--surface-2); border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; }
.paste summary { cursor: pointer; font-weight: 600; }
.paste textarea { margin: 10px 0 8px; }
.warn { background: var(--warm-bg); color: var(--text); border-radius: 10px; padding: 10px 12px; margin: 0; font-size: 14px; }

.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.quick a, .quick button { text-decoration: none; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; word-break: break-word; }
.stage-row { display: flex; gap: 6px; flex-wrap: wrap; }
.stage-row button { border: 1px solid var(--line); background: var(--surface-2); padding: 6px 10px; border-radius: 99px; cursor: pointer; font-size: 13px; font-weight: 600; }
.stage-row button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
@media (prefers-color-scheme: dark) { .stage-row button.on { background: var(--yellow); color: #121a2b; border-color: var(--yellow); } }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; }
.timeline li { display: flex; gap: 10px; }
.timeline .t { color: var(--muted); white-space: nowrap; min-width: 118px; }
h4 { margin: 4px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

/* Reports */
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.panel.wide { grid-column: 1 / -1; }
.panel h3 { font-size: 15px; }
.funnel-row { display: grid; grid-template-columns: 120px 1fr 70px; gap: 10px; align-items: center; font-size: 14px; }
.funnel-bar { height: 26px; border-radius: 7px; background: var(--surface-2); overflow: hidden; }
.funnel-bar > span { display: block; height: 100%; background: var(--navy); border-radius: 7px; min-width: 2px; }
@media (prefers-color-scheme: dark) { .funnel-bar > span { background: #4b6bb0; } }
.funnel-row.win .funnel-bar > span { background: var(--yellow); }
.funnel-row .n { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.funnel-row .pct { font-size: 12px; color: var(--muted); font-weight: 500; display: block; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart text { fill: var(--muted); font-size: 11px; }
svg.chart .grid { stroke: var(--line); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td { font-weight: 800; border-bottom: 0; }
.tbl-wrap { overflow-x: auto; }

.settings { display: grid; gap: 14px; max-width: 640px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* Import preview */
.preview { font-size: 13px; }
.preview .tbl td, .preview .tbl th { padding: 6px; white-space: nowrap; }

/* Toasts */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.3); font-weight: 600; display: flex; gap: 12px; align-items: center; animation: up .2s ease-out; }
.toast.err { background: var(--danger); }
.toast button { background: none; border: 0; color: var(--yellow); font-weight: 700; cursor: pointer; padding: 0; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Mobile */
@media (max-width: 1100px) {
  .board { grid-template-columns: repeat(4, 82vw); overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; margin: 0 -20px; padding-left: 20px; padding-right: 20px; }
  .col { scroll-snap-align: start; }
}
@media (min-width: 700px) and (max-width: 1100px) { .board { grid-template-columns: repeat(4, 340px); } }
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tab { flex: 1; }
  .view { padding: 14px 16px 60px; }
  .board { margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat .v { font-size: 22px; }
  .report-grid { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .bulkbar { top: 100px; }
  .toolbar input[type=search] { max-width: none; order: -1; flex-basis: 100%; }
  .dlg { width: 100vw; max-width: 100vw; max-height: 100dvh; border-radius: 18px 18px 0 0; margin: auto 0 0; }
  .dlg form, .dlg-inner { max-height: 92dvh; }
}
