:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --sidebar: #0f172a;
  --sidebar-ink: #cbd5e1;
  --sidebar-active: #1e293b;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.06);
  --radius: 12px;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0; color: var(--ink);
  background-color: #0f172a;  /* base so scrolled areas never flash white */
  background-image:
    linear-gradient(rgba(15,23,42,.80), rgba(15,23,42,.88)),
    url('/static/img/background-3d.jpg');
  background-size: cover;
  background-position: center center;
  background-attachment: fixed;
  background-repeat: no-repeat;
}

.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 20px 14px;
}
.brand {
  padding: 0; margin: 0 -10px 8px;
}
.brand-logo { width: 100%; display: block; }
.brand-sub {
  color: #cbd5e1; font-size: 11px; text-align: center; letter-spacing: 1.5px;
  text-transform: uppercase; margin-bottom: 16px; font-weight: 600;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: var(--sidebar-ink); text-decoration: none; font-size: 14px; font-weight: 500;
}
.sidebar nav a:hover { background: var(--sidebar-active); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar nav a .ico { width: 18px; text-align: center; opacity: .9; }
.sidebar-foot { margin-top: auto; font-size: 11px; color: #64748b; padding: 12px 8px 0; }

/* Content */
.content { flex: 1; padding: 32px 40px; max-width: 960px; }
.page-head { margin-bottom: 24px; }
.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.page-head h1 { margin: 0; font-size: 26px; color: #f8fafc; text-shadow: 0 1px 3px rgba(0,0,0,.4); }
.page-head .sub { margin: 6px 0 0; color: #cbd5e1; font-size: 14px; text-shadow: 0 1px 2px rgba(0,0,0,.4); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.5; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 30px; font-weight: 700; }
.stat-note { font-size: 12px; color: var(--muted); }

.empty { text-align: center; padding: 48px 24px; }
.empty-mark { font-size: 40px; margin-bottom: 8px; }

/* Forms */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #334155; }
input[type=text], input[type=number] {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
  background: #fff; color: var(--ink); font-family: inherit;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
input.small { max-width: 120px; }
textarea, select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
  background: #fff; color: var(--ink); font-family: inherit; width: 100%; resize: vertical;
}
textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.full { grid-column: 1 / -1; }
.inline { display: flex; gap: 8px; align-items: stretch; }
.inline input { flex: 1; }
.small-btn { padding: 8px 12px; white-space: nowrap; }
.hint { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.hint.warn { color: #b45309; }
.quote-box { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 13px; line-height: 1.5; background: #f8fafc; }
.total-row td { font-size: 18px; font-weight: 800; border-top: 2px solid var(--border); border-bottom: none; padding-top: 12px; }
.toast.info { background: #dbeafe; color: #1e40af; }
.toast.warnbox { background: #fef3c7; color: #92400e; }
.table-scroll { overflow-x: auto; }
.history { min-width: 760px; }
.history td { vertical-align: top; }
.muted-sm { font-size: 11px; color: var(--muted); margin-top: 2px; }
.tag { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .4px; background: #dcfce7; color: #166534; padding: 1px 6px; border-radius: 6px; margin-left: 4px; }
.status-form { margin: 0; }
.status-form select { padding: 6px 8px; font-size: 13px; min-width: 150px; }
.ac-wrap { position: relative; }
.ac-wrap input { width: 100%; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 30; background: #fff;
  border: 1px solid var(--border); border-top: none; border-radius: 0 0 8px 8px;
  box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; }
.ac-item { padding: 9px 12px; font-size: 13px; cursor: pointer; color: var(--ink); }
.ac-item:hover, .ac-item.active { background: #eff6ff; }
.accept-cell { margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.copybtn { font-size: 11px; padding: 2px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: #f8fafc; color: var(--muted); cursor: pointer; }
.copybtn:hover { background: #eef2f7; color: var(--ink); }
.approved-item { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border); }
.approved-item:last-child { border-bottom: none; }
.approved-item .who { font-weight: 600; }
.approved-item .amt { font-weight: 800; color: var(--success); white-space: nowrap; }
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.tl-item:last-child { border-bottom: none; }
.tl-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.tl-text { font-size: 14px; color: var(--ink); }
.tl-note .tl-text { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 8px 10px; }
.del-form { margin: 6px 0 0; }
.linkdel { background: none; border: none; padding: 0; cursor: pointer; font-size: 15px;
  line-height: 1; opacity: .65; }
.linkdel:hover { opacity: 1; }
.appraiser-row { padding: 14px 0; border-bottom: 1px solid var(--border); }
.appraiser-row:last-child { border-bottom: none; }
.appraiser-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.tag.owner { background: #dbeafe; color: #1e40af; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #f1f5f9; border: 1px solid var(--border);
  border-radius: 14px; padding: 3px 6px 3px 10px; font-size: 12px; color: #334155; }
.chip-x { margin: 0; display: inline; }
.chip-x button { background: none; border: none; cursor: pointer; color: #94a3b8; font-size: 14px;
  line-height: 1; padding: 0 2px; }
.chip-x button:hover { color: #dc2626; }
.row-actions { display: flex; align-items: center; gap: 12px; }
.edit-details summary { cursor: pointer; font-size: 12px; color: var(--primary); font-weight: 600; }
.edit-details[open] { width: 100%; }
.edit-form { margin-top: 12px; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.lead-card { padding: 16px 20px; }
.lead-card.is-handled { opacity: .6; }
.lead-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.lead-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag.type { background: #e0e7ff; color: #3730a3; }
.tag.done { background: #e2e8f0; color: #475569; }
.tag.nocov { background: #fee2e2; color: #991b1b; }
.nocov-details { margin-top: 6px; }

/* Leads view tabs (Active / Handled / All) — pill buttons like the sidebar nav */
.tabs { display: flex; gap: 8px; margin: 0 0 18px; }
.tabs .tab { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px;
  border-radius: 8px; font-size: 14px; font-weight: 600; color: #334155;
  background: #eef2f7; text-decoration: none; border: 1px solid #e2e8f0; }
.tabs .tab:hover { background: #e2e8f0; color: #1e293b; }
.tabs .tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tabs .tab .count { display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 20px; font-size: 12px; font-weight: 700; background: #fff;
  color: #475569; border-radius: 10px; padding: 0 6px; }
.tabs .tab.active .count { color: var(--primary); }

/* Per-lead activity log */
.lead-history .log { list-style: none; margin: 8px 0 0; padding: 0; }
.log-item { display: flex; gap: 9px; padding: 6px 0; align-items: flex-start; }
.log-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: 0 0 auto;
  background: #94a3b8; }
.log-received { background: #3730a3; }
.log-county { background: #0369a1; }
.log-edited { background: #b45309; }
.log-nocoverage { background: #991b1b; }
.log-handled { background: #166534; }
.log-note { background: #7c3aed; }
.log-text { font-size: 13px; color: #0f172a; }
.log-when { font-size: 11px; color: var(--muted); margin-top: 1px; }
.note-form { display: flex; gap: 6px; margin-top: 10px; }
.note-form input { flex: 1; }

/* Lead action row — Edit / Mark handled / History as matching pill buttons */
.route-note { margin-top: 10px; }
.lead-actions summary,
.lead-actions .pill-btn,
.lead-actions .open-quote {
  display: inline-flex; align-items: center; gap: 6px; list-style: none;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; box-sizing: border-box;
  font-family: inherit; font-size: 13px; font-weight: 600; line-height: 1.4; color: #334155;
  background: #eef2f7; border: 1px solid #e2e8f0; text-decoration: none;
}
.lead-actions .open-quote { color: #166534; }  /* green, matching the Local / texts badges */
.lead-actions summary::-webkit-details-marker { display: none; }  /* hide disclosure triangle */
.lead-actions summary::marker { content: ""; }
.lead-actions summary:hover,
.lead-actions .pill-btn:hover { background: #e2e8f0; color: #1e293b; }
.lead-actions .open-quote:hover { background: #dcfce7; border-color: #bbf7d0; }
.lead-actions details[open] > summary { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.lead-actions .decline-details > summary { color: #991b1b; }
.lead-actions .refer-details > summary { color: #1e40af; }
.lead-actions .del-right { margin-left: auto; }
.tag.declined { background: #ffedd5; color: #9a3412; }
.tag.referred { background: #dbeafe; color: #1e40af; }
.cls { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 10px; }
.cls-local { background: #dcfce7; color: #166534; }
.cls-referral { background: #dbeafe; color: #1e40af; }
.cls-needs_info { background: #fef3c7; color: #92400e; }
.cls-unassigned { background: #fee2e2; color: #991b1b; }
.lead-body { margin: 10px 0; font-size: 14px; }
.lead-body .muted-sm { display: block; margin-top: 2px; }
.lead-msg { margin-top: 8px; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; color: #334155; line-height: 1.5; }
.lead-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 6px;
  padding-top: 12px; border-top: 1px solid var(--border); }
.inline-form { margin: 0; }
.inline-set { display: flex; gap: 6px; align-items: center; margin: 0; }
.inline-set select { padding: 6px 8px; font-size: 13px; }
.inline-set input { padding: 6px 8px; font-size: 13px; max-width: 130px; }
.linktext { background: none; border: none; padding: 0; cursor: pointer; color: var(--primary);
  font-size: 13px; font-weight: 600; }
.linktext:hover { text-decoration: underline; }
.deleted-row { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border); }
.deleted-row:last-child { border-bottom: none; }
.map-wrap { margin-top: 14px; }
.route-map { width: 100%; height: 320px; border: 0; border-radius: 10px; display: block; }
.bd-num { width: 110px; text-align: right; padding: 6px 8px; font-size: 14px; }
.bd-table td { vertical-align: middle; }

.fee-table { width: 100%; border-collapse: collapse; }
.fee-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--border); }
.fee-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
.fee-table .right, th.right { text-align: right; }

.form-actions { display: flex; gap: 12px; align-items: center; margin-top: 4px; }
.btn {
  display: inline-block; background: var(--primary); color: #fff; border: none; cursor: pointer;
  padding: 11px 18px; border-radius: 8px; font-size: 14px; font-weight: 600; text-decoration: none;
  font-family: inherit;
}
.btn:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f8fafc; color: var(--ink); }
.btn.back-btn { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.45);
  padding: 8px 14px; font-size: 13px; }
.btn.back-btn:hover { background: rgba(255,255,255,.24); }

.toast { padding: 12px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; margin-bottom: 20px; }
.toast.success { background: var(--success-bg); color: #166534; }

@media (max-width: 820px) {
  .grid, .cards { grid-template-columns: 1fr; }
  .content { padding: 24px 20px; }
}

/* Billing page */
.bill-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 10px; }
.card-title { margin: 0; font-size: 15px; }
.bill-total { text-align: right; }
.bill-amount { font-size: 22px; font-weight: 800; color: #1e3a8a; line-height: 1.1; }
.table-wrap { overflow-x: auto; }
.bill-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bill-table th { text-align: left; padding: 8px 10px; border-bottom: 2px solid #1e3a8a; color: #1e3a8a; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
.bill-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.bill-table tfoot td { border-bottom: none; padding-top: 10px; }
.bill-table .r { text-align: right; }
.nowrap { white-space: nowrap; }
.bill-send { margin-top: 14px; }

/* Billing: statement status + filters */
.tag.st-paid { background: #dcfce7; color: #166534; }
.tag.st-unpaid { background: #fef3c7; color: #b45309; }
.tag.st-voided { background: #e2e8f0; color: #64748b; }
.bill-table tr.st-row-voided { opacity: .55; }
.st-actions { display: flex; gap: 14px; align-items: center; }
.st-actions form { display: inline-block; margin: 0; }
.st-link { background: none; border: none; padding: 0; cursor: pointer; font-family: inherit;
  font-size: 12px; font-weight: 500; color: #2563eb; }   /* blue, like a link */
.st-link:hover { text-decoration: underline; }
.st-link-void { color: #dc2626; }                        /* red — cancel/undo */
.outstanding { font-size: 14px; color: #334155; }
.outstanding strong { color: #b45309; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.filter-bar label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: #475569; }
.filter-bar select, .filter-bar input { padding: 7px 9px; font-size: 13px; }
.filter-actions { display: flex; gap: 12px; align-items: center; }
.period-link { color: var(--muted); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; }
.period-link:hover { color: #1e293b; text-decoration-style: solid; }

/* Auth pages (login / setup) */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 30px 30px 34px; width: 100%; max-width: 380px; text-align: center; }
.auth-logo { max-width: 210px; margin: 0 auto 4px; display: block; }
.auth-sub { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 18px; }
.auth-title { font-size: 20px; margin: 0 0 16px; color: var(--ink); }
.auth-hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 0 0 18px; }
.auth-form { display: flex; flex-direction: column; gap: 13px; text-align: left; }
.auth-form label { font-size: 13px; font-weight: 600; color: #334155; gap: 6px; }
.auth-form input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--ink); }
.auth-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.auth-btn { margin-top: 8px; width: 100%; justify-content: center; }
.auth-error { background: #fee2e2; color: #991b1b; border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 14px; }
/* Sidebar user footer */
.user-foot { margin-top: auto; padding: 14px 8px 0; display: flex; flex-direction: column; gap: 6px; }
.user-name { font-size: 12px; color: #cbd5e1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn { background: none; border: 1px solid #334155; color: #cbd5e1; border-radius: 7px; padding: 6px 10px; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; text-align: left; }
.logout-btn:hover { background: #1e293b; color: #fff; }
.auth-alt { margin: 16px 0 0; font-size: 13px; text-align: center; }
.auth-alt a { color: var(--primary); text-decoration: none; }
.auth-alt a:hover { text-decoration: underline; }

/* ---- Mobile / small screens (phones) ---- */
@media (max-width: 720px) {
  body { background-attachment: scroll; }          /* iOS: fixed bg causes zoom/jank */
  .layout { flex-direction: column; min-height: auto; }
  .sidebar { width: 100%; flex-direction: column; padding: 12px 12px 10px; }
  .brand { margin: 0 auto 4px; }
  .brand-logo { max-width: 190px; margin: 0 auto; }
  .brand-sub { margin-bottom: 8px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 2px; }
  .sidebar nav a { padding: 8px 11px; font-size: 13px; gap: 7px; }
  .user-foot { flex-direction: row; align-items: center; justify-content: space-between;
    margin-top: 10px; padding: 10px 4px 0; }
  .content { padding: 18px 14px; max-width: 100%; }
  .page-head h1 { font-size: 22px; }
  .page-head .sub { font-size: 13px; }
  .head-row { flex-direction: column; align-items: stretch; gap: 12px; }
  .card { padding: 18px 16px; }
  .grid { grid-template-columns: 1fr; }             /* forms: one field per row */
  .cards { grid-template-columns: 1fr; }            /* dashboard stat cards stack */
  .bill-head { flex-direction: column; gap: 8px; align-items: flex-start; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .lead-actions { gap: 8px; }
}
