:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --text: #1b1d24;
    --muted: #646b7a;
    --border: #e3e6ee;
    --accent: #e0287a;
    --badge-bg: #fde7f1;
    --badge-text: #a3195a;
    --alert-bg: #fff4e5;
    --alert-text: #8a4b00;
    --notice-bg: #e7f6ec;
    --notice-text: #17663a;
    --danger: #c62828;
    --accent-text: #ffffff;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
:root[data-theme="dark"] {
    --bg: #0f1117;
    --surface: #181b24;
    --text: #e8eaf0;
    --muted: #9aa1b2;
    --border: #2a2f3c;
    --accent: #ff4f9d;
    --badge-bg: #3a1528;
    --badge-text: #ff9cc8;
    --alert-bg: #3a2a10;
    --alert-text: #ffcf8a;
    --notice-bg: #12301f;
    --notice-text: #8ee0ad;
    --danger: #ff6b6b;
    --accent-text: #14060d;
    --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }

.topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: .6rem 16px; background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
.nav { display: flex; gap: .75rem; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a:hover { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.user { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; }
.inline { display: inline; margin: 0; }

.container { max-width: 1280px; margin: 0 auto; padding: 24px 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-top: 1.5rem; }
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 20px; box-shadow: var(--shadow);
}
.center { display: flex; justify-content: center; padding-top: 8vh; }
.narrow { width: 100%; max-width: 420px; text-align: center; }

.btn, .icon-btn {
    font: inherit; cursor: pointer; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    padding: .45rem .9rem; text-decoration: none; display: inline-flex; align-items: center; gap: .5rem;
}
.btn:hover, .icon-btn:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; }
.icon-btn { padding: .35rem .55rem; }
.btn-google { width: 100%; justify-content: center; padding: .7rem 1rem; margin-top: 1rem; font-weight: 600; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--badge-bg); color: var(--badge-text); }
.alert { background: var(--alert-bg); color: var(--alert-text); padding: .6rem .8rem; border-radius: 8px; }

.notice { background: var(--notice-bg); color: var(--notice-text); padding: .6rem .8rem; border-radius: 8px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-small { padding: .25rem .6rem; font-size: .85rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.small { font-size: .8rem; }

.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); flex: 1 1 200px; }
.form-row label.check { flex-direction: row; align-items: center; flex: 0 0 auto; gap: 6px; padding-bottom: .5rem; }
.form-row input[type=email], .form-row input:not([type]), .form-row input[type=text] {
    font: inherit; color: var(--text); background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem;
}
.field-error { color: var(--danger); font-size: .8rem; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.table td.actions { text-align: right; }
.table td.actions form + form { margin-left: 6px; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-warn td { background: var(--alert-bg); }
code { font-size: .85em; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 .3em; word-break: break-all; }
details summary { cursor: pointer; color: var(--muted); margin-bottom: .5rem; }

/* ---------- Leads ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 16px 0; }
.tab { padding: .4rem .8rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); text-decoration: none; font-weight: 600; font-size: .9rem; }
.tab.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.tab .count { font-size: .75rem; opacity: .75; margin-left: 2px; }
.tab .count.hot { background: var(--danger); color: #fff; opacity: 1; border-radius: 999px; padding: 0 .4rem; }
.tab-search { margin-left: auto; flex: 1 1 220px; max-width: 320px; }
.tab-search input, .lead-form input, .lead-form select, .lead-form textarea {
    width: 100%; font: inherit; color: var(--text); background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem;
}
.leads { display: flex; flex-direction: column; gap: 10px; }
.lead { display: flex; gap: 16px; justify-content: space-between; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.lead.due { border-left-color: #f59e0b; }
.lead.overdue { border-left-color: var(--danger); }
.lead.nocontract { border-left-color: var(--danger); background: linear-gradient(90deg, var(--alert-bg), var(--surface) 60%); }
.lead-main { flex: 1 1 320px; min-width: 0; }
.lead-title { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lead-name { font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.lead-name:hover { color: var(--accent); }
.lead-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: .9rem; }
.lead-notes { margin-top: 6px; font-size: .9rem; color: var(--muted); white-space: pre-line; max-height: 4.5em; overflow: hidden; }
.late { color: var(--danger); font-weight: 600; }
.lead-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; flex: 0 1 auto; }
.lead-actions .contact { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.inline-row { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; margin: 0; }
.pill { font-size: .72rem; font-weight: 700; padding: .12rem .55rem; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.st-new { background: #dbeafe; color: #1d4ed8; }
.st-contacted { background: #ede9fe; color: #6d28d9; }
.st-waiting { background: #fef3c7; color: #b45309; }
.st-booked { background: #d1fae5; color: #047857; }
.st-lost { background: #e5e7eb; color: #4b5563; }
.warn-pill { background: #fde047; color: #b91c1c; border: 1px solid #ef4444; }
.ok-pill { background: var(--notice-bg); color: var(--notice-text); }
.btn-good { color: #047857; }
.empty { text-align: center; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 12px 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.form-grid .span2 { grid-column: 1 / -1; }
.lead-form { margin-top: 12px; }
@media (max-width: 600px) {
    .lead-actions { align-items: stretch; width: 100%; }
    .lead-actions .contact, .inline-row { justify-content: flex-start; }
    .tab-search { max-width: none; margin-left: 0; }
}

@media (max-width: 600px) {
    .user { display: none; }
    .topbar { flex-wrap: wrap; row-gap: .4rem; }
    .topbar-right { margin-left: auto; }
    .nav { order: 3; width: 100%; flex: none; gap: 1rem; }
}
