:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --line: #e3e6ec;
  --brand: #2f5bea;
  --brand-soft: #e8eefe;
  --ok: #1f8a4c;
  --ok-soft: #e4f5ea;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --bad: #c0392b;
  --bad-soft: #fde8e6;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
pre { white-space: pre-wrap; word-break: break-word; font-family: inherit; margin: 0; }

.layout { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.sidebar { background: #161b26; color: #c9cfdb; padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar .logo { color: #fff; font-weight: 700; font-size: 16px; padding: 6px 10px 18px; }
.sidebar a { color: #c9cfdb; padding: 8px 10px; border-radius: 6px; display: flex; justify-content: space-between; }
.sidebar a:hover { background: #222a3a; text-decoration: none; }
.sidebar a.active { background: var(--brand); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar .user { font-size: 12px; padding: 8px 10px; color: #8a93a6; }
.main { padding: 24px 28px; min-width: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
@media (max-width: 1000px) { .cols-4, .cols-2, .cols-main { grid-template-columns: 1fr; } .layout { grid-template-columns: 1fr; } .sidebar { flex-direction: row; flex-wrap: wrap; } }

.kpi .value { font-size: 26px; font-weight: 700; }
.kpi .label { color: var(--muted); font-size: 12px; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8f9fc; }

input, select, textarea, button { font: inherit; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; color: var(--text); width: 100%; }
textarea { min-height: 140px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f3f4f7; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #eef0f4; color: var(--muted); }
.badge.new { background: var(--brand-soft); color: var(--brand); }
.badge.contacted, .badge.qualified, .badge.proposal { background: var(--warn-soft); color: var(--warn); }
.badge.won, .badge.processed, .badge.sent, .badge.rules { background: var(--ok-soft); color: var(--ok); }
.badge.lost, .badge.failed, .badge.high { background: var(--bad-soft); color: var(--bad); }
.badge.review, .badge.medium, .badge.fallback { background: var(--warn-soft); color: var(--warn); }
.badge.llm { background: #efe8fd; color: #6a3fd1; }

.board { display: grid; grid-template-columns: repeat(6, minmax(170px, 1fr)); gap: 12px; overflow-x: auto; }
.board .col { background: #eceef2; border-radius: var(--radius); padding: 8px; min-height: 300px; }
.board .col h3 { display: flex; justify-content: space-between; padding: 4px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 9px; margin-bottom: 8px; cursor: pointer; }
.card:hover { border-color: var(--brand); }
.card .t { font-weight: 600; margin-bottom: 4px; }
.card .s { color: var(--muted); font-size: 12px; }

.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 16px; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 14px 12px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.email-body { background: #fafbfc; border: 1px solid var(--line); border-radius: 6px; padding: 10px; max-height: 320px; overflow: auto; }
details summary { cursor: pointer; color: var(--brand); }

.login { max-width: 360px; margin: 12vh auto; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: #161b26; color: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.2); z-index: 10; }
.toast.error { background: var(--bad); }
.bar { height: 8px; background: var(--brand-soft); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
