:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1a2330;
  --muted: #586374;
  --line: #d6dce4;
  --brand: #1d5fa8;
  --brand-dark: #154a85;
  --brand-soft: #e6eff9;
  --ok: #1d7a46; --ok-soft: #e3f4ea;
  --warn: #8a5a00; --warn-soft: #fff3d6;
  --danger: #b3261e; --danger-soft: #fde8e6;
  --info-soft: #e6eff9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d; --surface: #1a212b; --text: #e8edf3; --muted: #a3afbf; --line: #2e3947;
    --brand: #6aa8f0; --brand-dark: #8dbcf4; --brand-soft: #1f3048;
    --ok: #6fd39a; --ok-soft: #173326; --warn: #f2c25b; --warn-soft: #3a2f14;
    --danger: #ff8b82; --danger-soft: #42201e; --info-soft: #1f3048;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 18px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; line-height: 1.5; }
a { color: var(--brand); }
a:hover { color: var(--brand-dark); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
h1 { font-size: 1.75rem; margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.25rem; margin: 0 0 .75rem; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }
.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.pre { white-space: pre-wrap; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }
code { font-size: .85em; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; min-height: 64px; padding-top: 8px; padding-bottom: 8px; }
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand-mark { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: var(--brand); color: #fff; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { padding: .5rem .8rem; border-radius: 8px; text-decoration: none; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--brand-soft); }
.nav a.active { background: var(--brand); color: #fff; }
.who { display: flex; align-items: center; gap: .75rem; }
.who a { color: var(--muted); text-decoration: none; }

main { padding-top: 24px; padding-bottom: 32px; }
.foot { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; padding-bottom: 24px; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.card.narrow { max-width: 620px; margin-left: auto; margin-right: auto; }
.card-warn { border-left: 6px solid var(--warn); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.crumbs { margin: 0 0 .25rem; }
.crumbs a { text-decoration: none; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 20px; }
.grid-2.top { align-items: start; gap: 20px; }
.grid-2.top .card { margin-bottom: 0; }
.grid-2.top + * { margin-top: 20px; }
.lead { font-size: 1.1rem; }
.empty { color: var(--muted); font-size: 1.05rem; margin: .5rem 0; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; display: flex; align-items: center; gap: 16px; box-shadow: var(--shadow); }
.stat-num { font-size: 2.25rem; font-weight: 700; line-height: 1; min-width: 2ch; }
.stat-label { color: var(--muted); line-height: 1.3; }
.stat-warn { border-left: 6px solid var(--warn); }
.stat-danger { border-left: 6px solid var(--danger); }
.stat-danger .stat-num { color: var(--danger); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem 1.1rem; min-height: 48px; border-radius: 8px; border: 2px solid var(--brand); background: var(--surface); color: var(--brand); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--brand-soft); color: var(--brand-dark); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-ghost { border-color: var(--line); color: var(--text); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-large { font-size: 1.1rem; padding: .8rem 1.5rem; min-height: 56px; }
.btn-small { min-height: 40px; padding: .35rem .8rem; font-size: .9rem; }
.btn-block { width: 100%; }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.form .actions { margin-top: 1rem; }
.danger-zone { margin-top: 8px; }

/* Forms */
.form label, .filters label { display: block; font-weight: 600; margin-bottom: 1rem; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: .85rem; }
legend .hint { display: inline; }
input, select, textarea { display: block; width: 100%; margin-top: .35rem; padding: .65rem .75rem; font: inherit; color: var(--text); background: var(--surface); border: 2px solid var(--line); border-radius: 8px; min-height: 48px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
input[type=checkbox], input[type=radio] { display: inline-block; width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--brand); flex: none; }
fieldset { border: 0; padding: 0; margin: 0 0 1.25rem; }
legend { font-weight: 700; margin-bottom: .5rem; padding: 0; }
.choices { display: flex; flex-wrap: wrap; gap: .5rem; }
.form label.choice, .filters label.choice, label.choice { display: inline-flex; align-items: center; gap: .55rem; font-weight: 500; margin: 0; padding: .55rem .9rem; border: 2px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; min-height: 48px; }
label.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.wb-choice.wb-good:has(input:checked) { border-color: var(--ok); background: var(--ok-soft); }
.wb-choice.wb-concern:has(input:checked) { border-color: var(--warn); background: var(--warn-soft); }
.wb-choice.wb-urgent:has(input:checked) { border-color: var(--danger); background: var(--danger-soft); }
.followup-box { background: var(--bg); border-radius: var(--radius); padding: 16px; }
.followup-box > label.choice { margin-bottom: 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0 16px; align-items: flex-end; }
.filters label { flex: 1 1 160px; }
.filters label.grow { flex: 3 1 260px; }
.filters label.choice { flex: none; margin-bottom: 1rem; }
.filter-actions { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; }

/* Alerts */
.alert { padding: 14px 18px; border-radius: var(--radius); margin-bottom: 20px; border-left: 6px solid; }
.alert ul { margin: .25rem 0 0; padding-left: 1.25rem; }
.alert-success { background: var(--ok-soft); border-color: var(--ok); }
.alert-error { background: var(--danger-soft); border-color: var(--danger); }
.alert-info { background: var(--info-soft); border-color: var(--brand); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
tr.inactive td { opacity: .6; }
td.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tel { font-weight: 600; white-space: nowrap; }
.big-phone { font-size: 1.6rem; margin: 0 0 1rem; }

/* Badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 700; vertical-align: middle; border: 1px solid transparent; white-space: nowrap; }
.wb-good, .st-ok, .oc-contact { background: var(--ok-soft); color: var(--ok); }
.wb-ok { background: var(--brand-soft); color: var(--brand); }
.wb-concern, .st-due { background: var(--warn-soft); color: var(--warn); }
.wb-urgent, .st-overdue { background: var(--danger-soft); color: var(--danger); }
.wb-na, .oc-missed, .st-inactive { background: var(--bg); color: var(--muted); border-color: var(--line); }

/* Details lists */
.details { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1.25rem; margin: 0; }
.details dt { color: var(--muted); font-weight: 600; }
.details dd { margin: 0; }
.note { margin-top: 1rem; background: var(--warn-soft); padding: 12px 14px; border-radius: 8px; }
.note p { margin: .25rem 0 0; }

/* Follow-ups & timeline */
.followups { list-style: none; margin: 0; padding: 0; }
.followup { display: flex; gap: 16px; justify-content: space-between; align-items: center; flex-wrap: wrap; padding: 14px 0; border-bottom: 1px solid var(--line); }
.followup:last-child { border-bottom: 0; }
.followup.is-urgent { border-left: 6px solid var(--danger); padding-left: 12px; }
.followup p { margin: .25rem 0; }
.followup-main { flex: 1 1 320px; }
.followup-done { display: flex; gap: .5rem; align-items: center; flex: 0 1 380px; }
.followup-done input { margin: 0; min-height: 40px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 3px solid var(--line); padding: 0 0 1rem 1rem; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -8px; top: 6px; width: 13px; height: 13px; border-radius: 50%; background: var(--brand); }
.tl-head { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.timeline p { margin: .35rem 0 0; }

.toggle { display: inline-flex; border: 2px solid var(--line); border-radius: 8px; overflow: hidden; }
.toggle a { padding: .35rem .8rem; text-decoration: none; color: var(--text); }
.toggle a.on { background: var(--brand); color: #fff; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1rem; }

.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 20px; }
.menu-tile { display: flex; flex-direction: column; gap: .35rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.menu-tile strong { font-size: 1.1rem; color: var(--brand); }
.menu-tile span { color: var(--muted); }
.menu-tile:hover { border-color: var(--brand); }
.secret { font-size: 1.3rem; background: var(--bg); padding: .3rem .6rem; border-radius: 6px; user-select: all; }
.login { margin-top: 6vh; }

@media (max-width: 640px) {
  html { font-size: 17px; }
  .who { width: 100%; justify-content: space-between; }
  .details { grid-template-columns: 1fr; gap: 0; }
  .details dd { margin-bottom: .6rem; }
  .followup-done { flex-basis: 100%; }
}
@media print {
  .topbar, .foot, .actions, .filters, .btn, form { display: none !important; }
  body { background: #fff; }
  .card { border: 0; box-shadow: none; }
}

/* Super admin "viewing tenant" bar */
.tenant-bar { background: #3b2a7a; color: #fff; }
.tenant-bar-inner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
.tenant-bar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }
.tenant-bar .btn:hover { background: rgba(255,255,255,.15); color: #fff; }

/* Call-backs */
.nav a.nav-primary { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.nav a.nav-primary.active { background: var(--brand); color: #fff; }
.count { display: inline-block; min-width: 1.5em; padding: 0 .4em; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: .8rem; font-weight: 700; text-align: center; }
.count-urgent { background: var(--danger); color: #fff; }
.nav a.active .count { background: #fff; color: var(--brand); }
a.stat-link { text-decoration: none; color: inherit; }
a.stat-link:hover { border-color: var(--brand); }
.take-message { max-width: 860px; margin-left: auto; margin-right: auto; }
.big-label { font-size: 1.25rem; font-weight: 700; display: block; }
.search-row { display: flex; gap: .5rem; align-items: center; }
.search-row input { font-size: 1.25rem; margin: 0; min-height: 56px; }
.search-row .btn { min-height: 56px; }
.results { list-style: none; margin: .5rem 0 1rem; padding: 0; max-height: 360px; overflow-y: auto; }
.results:empty { display: none; }
.result { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; padding: .7rem .9rem; border: 2px solid var(--line); border-radius: 8px; margin-bottom: .4rem; text-decoration: none; color: var(--text); background: var(--surface); }
.result:hover, .result.is-active { border-color: var(--brand); background: var(--brand-soft); }
.result-new { color: var(--brand); font-weight: 600; border-style: dashed; }
.selected-caller { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: 14px 16px; border: 2px solid var(--brand); background: var(--brand-soft); border-radius: var(--radius); margin-bottom: 1.25rem; }
.selected-name { font-size: 1.4rem; font-weight: 700; }
.warn-text { color: var(--warn); font-weight: 600; margin: .4rem 0 0; }
.new-caller { border: 2px dashed var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 1.25rem; }
.new-caller[open] { border-color: var(--brand); }
.new-caller summary { cursor: pointer; font-weight: 700; color: var(--brand); padding: .25rem 0; }
.new-caller .grid-3 { margin-top: .75rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.urgent-box { display: flex; align-items: center; padding-top: 1.6rem; margin-bottom: 1rem; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a { padding: .5rem 1rem; border-radius: 8px; text-decoration: none; color: var(--text); border: 2px solid var(--line); background: var(--surface); font-weight: 600; }
.tabs a.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs a.on .count { background: #fff; color: var(--brand); }
.cb-list { list-style: none; margin: 0; padding: 0; }
.cb { display: flex; gap: 16px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; padding: 14px 0; border-bottom: 1px solid var(--line); }
.cb:last-child { border-bottom: 0; }
.cb.is-urgent { border-left: 6px solid var(--danger); padding-left: 12px; }
.cb.is-closed { opacity: .75; }
.cb-main { flex: 1 1 360px; }
.cb-head { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.cb-message { margin: .35rem 0; white-space: pre-wrap; font-size: 1.05rem; }
.cb-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-start; }
.cb-more { position: relative; }
.cb-more summary { list-style: none; }
.cb-more summary::-webkit-details-marker { display: none; }
.cb-more[open] .cb-form:first-of-type { margin-top: .5rem; }
.cb-form { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; margin-top: .5rem; }
.cb-form label { font-weight: 600; font-size: .9rem; margin: 0; }
.cb-form input, .cb-form select { min-height: 40px; }
.callback-banner .cb-message { font-size: 1.1rem; }

/* Two fields per line (one on small screens) */
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
@media (max-width: 640px) { .pairs { grid-template-columns: 1fr; } }

/* Size choice and short fields to their content instead of the full line */
.form select { width: auto; min-width: 14rem; max-width: 100%; }
.form input[type=number] { width: 9rem; }
.form input[type=date], .form input[type=datetime-local] { width: auto; max-width: 100%; }
.assign-form select { margin: 0; min-height: 40px; padding: .3rem .5rem; width: auto; font-size: .95rem; }
