:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2230;
  --muted: #6b7384;
  --primary: #2f5bea;
  --primary-soft: #e8eefd;
  --danger: #d0342c;
  --danger-soft: #fdecea;
  --warn: #b86e00;
  --warn-soft: #fff4e0;
  --ok: #1e8a4c;
  --ok-soft: #e6f5ec;
  --radius: 10px;
  --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 {
    --bg: #12151b;
    --surface: #1b1f27;
    --surface-2: #232834;
    --border: #2e3442;
    --text: #e6e9ef;
    --muted: #97a0b3;
    --primary: #6d8dff;
    --primary-soft: #232d4d;
    --danger: #ff6b61;
    --danger-soft: #3a2020;
    --warn: #f0a93b;
    --warn-soft: #3a2e17;
    --ok: #4cc983;
    --ok-soft: #173325;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.boot { padding: 40px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- controls */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 7px 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.small, .btn.small { padding: 3px 8px; font-size: 12px; }
button.icon { border: none; background: none; padding: 4px 6px; color: var(--muted); }
button.icon:hover { color: var(--text); background: var(--surface-2); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: -1px;
}
input[type=checkbox] { width: 17px; height: 17px; margin: 0; accent-color: var(--primary); cursor: pointer; }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 12px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; }

/* ---------- layout */
.layout { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; display: flex; gap: 8px; align-items: center; }
.brand .logo { width: 22px; height: 22px; border-radius: 6px; background: var(--primary); display: inline-grid; place-items: center; color: #fff; font-size: 13px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { white-space: nowrap; padding: 8px 10px; border-radius: 8px; color: var(--text); display: flex; justify-content: space-between; }
.side nav a:hover { background: var(--surface-2); text-decoration: none; }
.side nav a.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side .badge { margin-left: auto; }
.side .me { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
main { min-width: 0; }
.top {
  display: flex; gap: 8px; align-items: center; padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.top form { flex: 1; max-width: 460px; }
#view { padding: 24px; max-width: 1400px; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card-head .actions { margin-left: auto; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.cols > .card + .card { margin-top: 0; }
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.empty { color: var(--muted); padding: 10px 0; font-size: 13px; }

/* ---------- tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; color: var(--muted); }
.tile .value { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--muted); }
.tile.danger { border-color: var(--danger); background: var(--danger-soft); }
.tile.danger .value { color: var(--danger); }
.tile.warn { border-color: var(--warn); background: var(--warn-soft); }
.tile.warn .value { color: var(--warn); }

/* ---------- badges */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }

/* ---------- lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: none; }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }
.group-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 4px; }
.group-title:first-child { margin-top: 0; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.notes { white-space: pre-wrap; font-size: 13px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-top: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; border-top: none; }
tbody tr:hover { background: var(--surface-2); }
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters input { max-width: 320px; }
.filters select { width: auto; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 5px 12px; }
.seg button.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ---------- pipeline */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.column { background: var(--surface-2); border-radius: var(--radius); width: 250px; flex: 0 0 250px; padding: 10px; min-height: 200px; }
.column.drop { outline: 2px dashed var(--primary); }
.column-head { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 2px; }
.column-sum { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.deal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow);
}
.deal-card:active { cursor: grabbing; }
.deal-card .title { font-weight: 600; display: block; margin-bottom: 2px; }
.deal-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; gap: 6px; }

.stagebar { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.stagebar button { flex: 1; justify-content: center; border-radius: 6px; font-size: 13px; }
.stagebar button.past { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.stagebar button.on { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.stagebar button.on.won { background: var(--ok); border-color: var(--ok); }
.stagebar button.on.lost { background: var(--danger); border-color: var(--danger); }

.bars .bar-row { display: grid; grid-template-columns: 95px 1fr 110px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.bars .track { background: var(--surface-2); border-radius: 4px; height: 10px; overflow: hidden; }
.bars .fill { background: var(--primary); height: 100%; border-radius: 4px; }
.bars .amt { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- activity */
.logform textarea { min-height: 64px; }
.logform .row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 8px; }
.logform .row label { flex: 0 0 auto; }
.logform .row label > input { display: block; }
.logform .row input[type=date] { width: 150px; }
.chips { display: flex; gap: 4px; }
.types { display: flex; gap: 4px; margin-bottom: 8px; }
.types label { margin: 0; }
.types input { display: none; }
.types span { display: inline-block; padding: 4px 12px; border-radius: 99px; border: 1px solid var(--border); cursor: pointer; font-size: 13px; color: var(--text); }
.types input:checked + span { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); font-weight: 600; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.err { background: var(--danger-soft); color: var(--danger); }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; margin-bottom: 10px; display: flex; gap: 8px; align-items: center; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.timeline li:first-child { border-top: none; }
.timeline .ico { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 14px; }
.timeline .body { white-space: pre-wrap; word-break: break-word; }
.timeline .when { font-size: 12px; color: var(--muted); margin-bottom: 2px; }

/* ---------- modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(10, 14, 22, .5); display: grid; place-items: start center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 620px; padding: 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; margin-top: 18px; }
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1e7a45; color: #fff; padding: 12px 16px; border-radius: 8px; max-width: 380px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); font-weight: 600; animation: toast-in .2s ease-out; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.toast.err { background: var(--danger); color: #fff; }

.auth { max-width: 380px; margin: 10vh auto; padding: 0 16px; }
.auth .card { padding: 26px; }
.auth h1 { margin-bottom: 4px; }
.auth form { display: grid; gap: 12px; margin-top: 18px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px; }
  .side nav { flex-direction: row; }
  .brand { padding: 4px 8px; }
  .side .me { display: none; }
  .top { position: static; padding: 10px 16px; flex-wrap: wrap; }
  .top form { flex: 1 1 100%; max-width: none; }
  #view { padding: 16px; }
  .cols, .detail { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- team report */
th.num, td.num { text-align: right; }
table.sortable th { cursor: pointer; user-select: none; }
table.sortable th:hover { color: var(--text); }
.chart { position: relative; }
.chart-plot { display: grid; grid-template-columns: 32px 1fr; gap: 8px; height: 160px; }
.chart-grid { display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: var(--muted); text-align: right; }
.chart-bars {
  display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid var(--border);
  background: linear-gradient(var(--border), var(--border)) 0 50% / 100% 1px no-repeat;
}
.chart-col { flex: 1; height: 100%; display: flex; align-items: flex-end; outline: none; cursor: default; min-width: 0; }
.chart-col:hover .chart-bar, .chart-col:focus .chart-bar { filter: brightness(1.15); }
.chart-bar { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 0; }
.chart-bar.weekend { opacity: .45; }
.chart-x { display: flex; gap: 2px; margin-left: 40px; font-size: 11px; color: var(--muted); margin-top: 4px; }
.chart-x span { flex: 1; min-width: 0; white-space: nowrap; overflow: visible; }
.chart-tip {
  position: absolute; top: -6px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none;
}

/* ---------- two-step verification */
.mfa-choices { display: grid; gap: 8px; margin-bottom: 12px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--text); }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice input { margin-top: 3px; width: auto; }
label.inline { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text); }
label.inline input { width: auto; }
.mfa-steps { padding-left: 20px; display: grid; gap: 10px; font-size: 14px; }
.qr { background: #fff; display: block; width: max-content; border-radius: 8px; margin: 8px 0 4px; line-height: 0; }
.qr svg { width: 180px; height: 180px; }
code.secret { font-size: 13px; word-break: break-all; }
.mfa-code-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.mfa-code-form input[name=code] { width: 140px; font-size: 18px; letter-spacing: 3px; }
.auth input[name=code] { font-size: 20px; letter-spacing: 4px; text-align: center; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; background: var(--surface-2); padding: 12px 16px; border-radius: 8px; margin: 10px 0; }
.codes code { font-size: 15px; letter-spacing: 1px; }
