:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1f2933; --muted: #616e7c; --line: #dde2e8;
  --accent: #1d4ed8; --accent-soft: #e8eefc; --danger: #b42318; --warn: #b54708; --ok: #067647;
  --radius: 6px;
}
* { box-sizing: border-box; }
html { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
body { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; word-break: break-all; }

.top { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: #111827; color: #e5e7eb; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.top a, .top .link { color: #e5e7eb; }
.brand { font-weight: 700; letter-spacing: .01em; }
nav { display: flex; gap: .15rem; flex-wrap: wrap; }
nav a { padding: .35rem .6rem; border-radius: var(--radius); color: #cbd5e1; }
nav a.on, nav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.search { flex: 1; min-width: 12rem; }
.search input { width: 100%; max-width: 26rem; border: 0; background: #1f2937; color: #fff; }
.search input::placeholder { color: #9ca3af; }
.who { font-size: .85rem; white-space: nowrap; }

main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1rem; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } .who { display: none; } }

input, select, textarea, button { font: inherit; }
input, select, textarea { border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem .55rem; background: #fff; color: var(--text); min-width: 0; }
textarea { width: 100%; min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button, .btn { border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: var(--radius); padding: .4rem .75rem; cursor: pointer; display: inline-block; line-height: 1.3; }
button:hover, .btn:hover { border-color: #b8c1cc; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button.sm, .btn.sm { padding: .2rem .5rem; font-size: .85rem; }

form.stack { display: grid; gap: .6rem; }
form.stack label { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }
form.stack label > input, form.stack label > select, form.stack label > textarea { color: var(--text); font-size: 1rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .6rem; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .5rem; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: .45rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; margin-bottom: 1rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 1rem; color: var(--muted); }

.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; background: #eef0f3; color: #374151; white-space: nowrap; }
.pill.lead { background: #eef0f3; }
.pill.contacted { background: var(--accent-soft); color: #1e40af; }
.pill.active_client { background: #dcfae6; color: var(--ok); }
.pill.do_not_call { background: #fee4e2; color: var(--danger); }
.pill.overdue { background: #fee4e2; color: var(--danger); }
.pill.snoozed { background: #fef0c7; color: var(--warn); }
.pill.done { background: #dcfae6; color: var(--ok); }
.tag { display: inline-block; padding: 0 .4rem; margin: 0 .2rem .2rem 0; border-radius: 4px; background: #f2f4f7; font-size: .8rem; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { font-size: .8rem; color: var(--muted); }
.timeline .body { white-space: pre-wrap; margin-top: .15rem; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .9rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; word-break: break-word; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; }
.stat b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }

.picker { position: relative; }
.picker input { width: 100%; }
.picker ul { position: absolute; left: 0; right: 0; top: 100%; z-index: 10; list-style: none; margin: 2px 0 0; padding: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); max-height: 16rem; overflow: auto; box-shadow: 0 6px 18px rgba(0,0,0,.08); }
.picker li { padding: .4rem .6rem; cursor: pointer; }
.picker li:hover, .picker li.on { background: var(--accent-soft); }

dialog { border: 1px solid var(--line); border-radius: 8px; padding: 1.1rem; width: min(44rem, 94vw); max-height: 90vh; overflow: auto; }
dialog::backdrop { background: rgba(17, 24, 39, .4); }
.secret { background: #fffbeb; border: 1px solid #fcd34d; border-radius: var(--radius); padding: .6rem; margin: .5rem 0; }
.notice { background: var(--accent-soft); border-radius: var(--radius); padding: .6rem .8rem; margin: .5rem 0; }
.warn-box { background: #fef3f2; border: 1px solid #fecdca; border-radius: var(--radius); padding: .6rem .8rem; margin: .5rem 0; }

#toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: .55rem .9rem; border-radius: var(--radius); opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; z-index: 50; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); }

.login { max-width: 26rem; margin: 12vh auto; }
.login input { width: 100%; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: .75rem; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: .4rem .7rem; }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent); }
.overdue-text { color: var(--danger); }
