:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1b1f24;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --good: #12805c;
  --warn: #b54708;
  --bad: #c01048;
  --hot: #d92d20;
  --radius: 10px;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --ink: #e6e9ee;
    --muted: #98a2b3;
    --line: #2a3039;
    --accent: #5b8def;
  }
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: wait; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; color: var(--muted); padding: 6px 0; text-align: left; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--panel); width: 100%;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
label.inline { display: flex; align-items: center; gap: 8px; color: var(--ink); }
label.inline input { width: auto; }

.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; width: min(360px, 92vw); display: grid; gap: 14px; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }

.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { font-weight: 700; padding: 4px 10px 14px; }
.sidebar a { padding: 8px 10px; border-radius: 8px; color: var(--ink); display: flex; justify-content: space-between; align-items: center; }
.sidebar a.active { background: var(--bg); font-weight: 600; }
.sidebar a:hover { text-decoration: none; background: var(--bg); }
.sidebar #logout { margin-top: auto; padding-left: 10px; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; min-width: 20px; text-align: center; }
.badge.hot { background: var(--hot); }
main { padding: 0 28px 40px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); margin-bottom: 20px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--muted); }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 420px; z-index: 10; }
.toast.bad { background: var(--bad); color: #fff; }

.pill { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; border: 1px solid var(--line); white-space: nowrap; }
.pill.good { color: var(--good); border-color: currentColor; }
.pill.warn { color: var(--warn); border-color: currentColor; }
.pill.bad { color: var(--bad); border-color: currentColor; }
.pill.hot { color: #fff; background: var(--hot); border-color: var(--hot); }
.pill.accent { color: var(--accent); border-color: currentColor; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.two { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .shell { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; } main { padding: 0 14px 40px; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .value { font-size: 26px; font-weight: 700; }
.card .label { color: var(--muted); font-size: 13px; }
.card.alert { border-color: var(--hot); }
.banner { border: 1px solid var(--warn); color: var(--warn); background: var(--panel); border-radius: var(--radius); padding: 10px 14px; }
.banner.hot { border-color: var(--hot); color: var(--hot); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.events { list-style: none; margin: 0; padding: 0; }
.events li { display: grid; grid-template-columns: 74px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot-email { background: var(--accent); } .dot-reply { background: var(--hot); } .dot-approval { background: var(--warn); }
.dot-lead { background: var(--good); } .dot-project { background: #7a5af8; } .dot-budget, .dot-settings { background: var(--bad); }

.chart svg { width: 100%; height: 160px; display: block; }
.chart .legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bars .bar { display: grid; grid-template-columns: 120px 1fr 48px; gap: 8px; align-items: center; margin: 4px 0; font-size: 13px; }
.bars .track { background: var(--bg); border-radius: 4px; height: 10px; overflow: hidden; }
.bars .fill { background: var(--accent); height: 100%; }

.approval { display: grid; gap: 14px; }
.approval .head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--bg); border-radius: 6px; padding: 2px 8px; font-size: 12px; }
.quote table td { padding: 4px 6px; border: 0; }
.quote .total { font-size: 18px; font-weight: 700; }
.quote input.amount { text-align: right; width: 110px; }
.email { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; }
.message { border-left: 3px solid var(--line); padding: 4px 0 4px 12px; margin: 10px 0; }
.message.in { border-color: var(--hot); }
.message pre, .pre { white-space: pre-wrap; word-break: break-word; font: inherit; margin: 6px 0 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 180px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.settings label { max-width: 360px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.live .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.live.on .pulse { animation: pulse 1.6s ease-in-out infinite; }
.live.busy .pulse { background: var(--warn); }
@keyframes pulse { 50% { opacity: .25; } }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--accent); color: var(--accent-ink); }
.meter { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; align-items: center; margin: 6px 0; font-size: 13px; }
.meter .track { background: var(--bg); border-radius: 4px; height: 10px; overflow: hidden; }
.meter .fill { height: 100%; background: var(--good); }
.meter .fill.warn { background: var(--warn); } .meter .fill.bad { background: var(--bad); }
tr.new-row td { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 22%, transparent); } to { background: transparent; } }
.kind { font-size: 11px; font-weight: 600; border-radius: 4px; padding: 1px 6px; color: #fff; }
.kind.jev { background: #7a5af8; } .kind.writer { background: var(--accent); }

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--ink); }
th.sortable::after { content: attr(data-ind); margin-left: 4px; font-size: 10px; color: var(--accent); }
th.sortable:not([data-ind])::after, th.sortable[data-ind=""]::after { content: "⇅"; opacity: .3; }
.table-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.table-tools input { width: auto; min-width: 220px; }
.bars a { text-decoration: none; }
.event-widget .filters { margin-bottom: 4px; }
.event-widget .ev-q { width: auto; min-width: 200px; }
.event-widget select { width: auto; }
.filters select { width: auto; }
