:root {
  --bg: #f6f7fb; --surface: #fff; --ink: #172033; --muted: #5b6478; --line: #dde2ec;
  --accent: #2563eb; --accent-soft: #e8f0fe; --good: #047857; --good-soft: #e4f5ee;
  --warn: #b45309; --warn-soft: #fdf3e3; --bad: #b91c1c; --bad-soft: #fdeaea;
  font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
[hidden] { display: none !important; }
a { color: var(--accent); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.top { display: flex; align-items: center; gap: 24px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; }
.brand span { color: var(--muted); font-weight: 500; }
.top nav { display: flex; gap: 4px; }
.top nav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 6px; font-weight: 500; }
.top nav a.on { background: var(--accent-soft); color: var(--accent); }
.who { margin-left: auto; display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 13px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.head .sp { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-block; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .6; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.tbl { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; background: #fafbfd; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8faff; }
td select { width: auto; min-width: 118px; padding: 5px 8px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: #eef1f6; color: var(--muted); white-space: nowrap; }
.pill.active, .pill.won, .pill.sent { background: var(--good-soft); color: var(--good); }
.pill.draft, .pill.new, .pill.handed_off { background: var(--accent-soft); color: var(--accent); }
.pill.paused, .pill.contacted { background: var(--warn-soft); color: var(--warn); }
.pill.lost, .pill.failed, .pill.over { background: var(--bad-soft); color: var(--bad); }
.meter { height: 6px; background: #eef1f6; border-radius: 3px; overflow: hidden; margin-top: 4px; min-width: 90px; }
.meter i { display: block; height: 100%; background: var(--accent); }
.meter i.over { background: var(--bad); }
.form { display: grid; gap: 18px; }
.section { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
label { display: grid; gap: 4px; align-content: start; font-weight: 500; font-size: 13.5px; min-width: 0; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%; min-width: 0; }
input[type=color] { padding: 2px; height: 38px; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
textarea.kb { min-height: 280px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; line-height: 1.5; }
.checks { display: flex; gap: 16px; align-items: center; font-weight: 400; }
.checks label { display: flex; gap: 6px; align-items: center; font-weight: 400; }
.err { color: var(--bad); background: var(--bad-soft); border-radius: 8px; padding: 8px 12px; }
.bar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 0; display: flex; gap: 12px; align-items: center; }
pre.code { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; margin: 0; white-space: pre-wrap; word-break: break-all; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs a.on { color: var(--accent); border-color: var(--accent); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters label { width: auto; }
.chat { display: grid; gap: 8px; max-width: 760px; }
.msg { padding: 9px 12px; border-radius: 10px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { background: var(--accent); color: #fff; justify-self: end; }
.msg.assistant { background: var(--surface); border: 1px solid var(--line); justify-self: start; }
.msg small { display: block; opacity: .7; font-size: 11px; margin-top: 3px; }
.login { max-width: 380px; margin: 10vh auto; }
.login .card { display: grid; gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile .big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.empty { padding: 32px; text-align: center; color: var(--muted); }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
