:root {
  --navy: #1f3a5f;
  --navy-deep: #16293f;
  --sky: #cfe3f4;
  --ink: #1d232b;
  --muted: #5d6673;
  --line: #d9dee5;
  --paper: #f7f8fa;
  --white: #ffffff;
  --red: #b3261e;
  --red-bg: #fbe9e7;
  --amber: #8a5a00;
  --amber-bg: #fff3d6;
  --green: #1f6b3a;
  --green-bg: #e3f3e8;
  --purple: #5b3d9a;
  --purple-bg: #ece6f7;
  --radius: 6px;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); }
body { padding-bottom: env(safe-area-inset-bottom, 0); }
a { color: var(--navy); }
button, input, select, textarea { font: inherit; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 14px; }
h2 { font-size: 17px; font-weight: 600; margin: 22px 0 10px; }
h2.first { margin-top: 0; }
.mt0 { margin-top: 0; }
.pre { white-space: pre-wrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* top bar */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 14px; padding: 0 18px; height: 52px; padding-top: env(safe-area-inset-top, 0); position: sticky; top: 0; z-index: 5; }
.topbar .brand { font-weight: 600; letter-spacing: .01em; margin-right: 6px; white-space: nowrap; }
.topbar nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.topbar nav a { color: #d6e2f0; text-decoration: none; padding: 8px 10px; border-radius: 4px; white-space: nowrap; }
.topbar nav a.active { background: var(--navy-deep); color: #fff; }
.topbar nav a.cta { border: 1px solid #5a7aa0; }
.topbar .who { color: #c9d6e6; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.topbar .who button { background: none; border: 1px solid #5a7aa0; color: #fff; padding: 3px 9px; border-radius: 4px; cursor: pointer; }

main { max-width: 1280px; margin: 0 auto; padding: 22px 18px 60px; }

/* login */
.login { max-width: 380px; margin: 10vh auto; background: var(--white); border: 1px solid var(--line); padding: 28px; border-radius: 8px; }
.login h1 { margin-bottom: 4px; }
.login p { color: var(--muted); margin: 0 0 18px; }
.login .phi { font-size: 12.5px; color: var(--muted); margin-top: 18px; }

/* forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
label .req { color: var(--red); }
input[type=text], input[type=date], input[type=password], input[type=tel], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; color: var(--ink);
}
input:disabled, select:disabled, textarea:disabled { background: #f1f3f6; color: var(--muted); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--navy); outline-offset: 1px; }
textarea { min-height: 70px; resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 14px; color: var(--ink); }
.check input { width: 16px; height: 16px; flex: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
button.primary { background: var(--navy); color: #fff; border: 0; padding: 9px 16px; border-radius: var(--radius); cursor: pointer; font-weight: 500; }
button.primary:hover { background: var(--navy-deep); }
button.secondary { background: #fff; color: var(--navy); border: 1px solid var(--navy); padding: 8px 14px; border-radius: var(--radius); cursor: pointer; }
button.quiet { background: none; border: 1px solid var(--line); color: var(--ink); padding: 7px 12px; border-radius: var(--radius); cursor: pointer; }
button.quiet:hover { background: #f2f6fb; }
button.danger { background: var(--red-bg); color: var(--red); border: 1px solid #e6b3ae; padding: 8px 14px; border-radius: var(--radius); cursor: pointer; }
button.link { background: none; border: 0; color: var(--navy); text-decoration: underline; cursor: pointer; padding: 0; }
button.small { padding: 4px 9px; font-size: 13px; }
a.btnlink { display: inline-block; padding: 8px 12px; text-decoration: none; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: #fff; }
a.btnlink:hover { background: #f2f6fb; }
h3 { font-size: 14.5px; font-weight: 600; margin: 18px 0 4px; color: var(--navy-deep); }
form h3:first-child { margin-top: 0; }
button:disabled { opacity: .45; cursor: not-allowed; }
.error { color: var(--red); background: var(--red-bg); padding: 8px 10px; border-radius: var(--radius); margin: 10px 0; font-size: 14px; }
.notice { color: var(--amber); background: var(--amber-bg); padding: 8px 10px; border-radius: var(--radius); margin: 10px 0; font-size: 14px; }
.info { color: var(--navy-deep); background: var(--sky); padding: 8px 10px; border-radius: var(--radius); margin: 10px 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }
.warnbox { border: 1px solid #e6c98a; background: var(--amber-bg); border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.warnbox ul { margin: 6px 0 0; padding-left: 18px; }

/* panels */
.panel { background: var(--white); border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 16px; }
.panel.tight { padding: 12px 14px; }

/* toolbar & chips */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; }
.toolbar input[type=search] { min-width: 260px; }
.toolbar .spacer { flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 4px 10px; border-radius: 14px; font-size: 13px; cursor: pointer; }
.chip:hover { background: #f2f6fb; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip .n { opacity: .75; margin-left: 4px; }
.bulkbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--sky); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 10px; font-size: 14px; }
.bulkbar select { width: auto; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin: 10px 0; color: var(--muted); font-size: 13.5px; }

/* table */
table { width: 100%; border-collapse: collapse; background: var(--white); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tablewrap { overflow-x: auto; border-radius: 8px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
th { background: #eef2f7; color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sorted { color: var(--navy-deep); }
th.sorted::after { content: " ↑"; }
th.sorted.desc::after { content: " ↓"; }
tr:last-child td { border-bottom: 0; }
tr.row { cursor: pointer; }
tr.row:hover { background: #f2f6fb; }
tr.row.urgent td:first-child { box-shadow: inset 3px 0 0 var(--red); }
td .sub { display: block; color: var(--muted); font-size: 12.5px; }
td.sel, th.sel { width: 30px; padding-right: 0; }
td.sel input { width: 15px; height: 15px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td a.plain { color: inherit; text-decoration: none; font-weight: 600; }

/* pills & badges */
.pill { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.pill.new { background: var(--sky); color: var(--navy-deep); }
.pill.contacting { background: #e8ecf3; color: #33415a; }
.pill.under_review { background: var(--purple-bg); color: var(--purple); }
.pill.completed { background: #eceff3; color: var(--muted); }
.pill.scheduled { background: var(--green-bg); color: var(--green); }
.pill.unreachable, .pill.declined { background: var(--red-bg); color: var(--red); }
.pill.not_accepted { background: var(--purple-bg); color: var(--purple); }
.pill.rec_received, .pill.rec_not_needed { background: var(--green-bg); color: var(--green); }
.pill.rec_requested, .pill.rec_partial { background: var(--amber-bg); color: var(--amber); }
.pill.rec_not_requested { background: #eceff3; color: var(--muted); }
.flag.records_overdue { background: var(--red-bg); color: var(--red); }
.timeline li.office { border-left: 3px solid var(--sky); padding-left: 8px; }
.pill.redirected, .pill.duplicate, .pill.no_visit_needed { background: #eceff3; color: var(--muted); }
.flag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 6px; border-radius: 4px; margin: 2px 4px 0 0; white-space: nowrap; }
.flag.urgent { background: var(--red); color: #fff; }
.flag.overdue { background: var(--red-bg); color: var(--red); }
.flag.due_today { background: var(--amber-bg); color: var(--amber); }
.flag.stale_new, .flag.stale_contacting, .flag.stale_review { background: var(--amber-bg); color: var(--amber); }
.flag.review { background: var(--purple-bg); color: var(--purple); }
.due.overdue { color: var(--red); font-weight: 600; }
.due.today { color: var(--amber); font-weight: 600; }
.badge-internal { color: var(--muted); font-size: 12px; border: 1px solid var(--line); padding: 1px 6px; border-radius: 4px; }

/* detail */
.detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.detail-head h1 { margin: 0; }
.detail-head .meta { color: var(--muted); font-size: 13.5px; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.cols.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .cols, .cols.even { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 5px 12px; font-size: 14px; }
.kv .k { color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { color: var(--muted); font-size: 12.5px; }
.gate { padding: 10px 12px; border-radius: var(--radius); font-size: 13.5px; margin: 8px 0; }
.gate.blocked { background: var(--amber-bg); color: var(--amber); }
.gate.ok { background: var(--green-bg); color: var(--green); }
.outcome-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.outcome-buttons button { padding: 7px 12px; }
.legacy { background: #fbfbf6; border: 1px dashed var(--line); border-radius: var(--radius); padding: 8px 10px; font-size: 13px; white-space: pre-wrap; max-height: 180px; overflow: auto; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: 8px; padding: 14px; text-decoration: none; color: inherit; display: block; }
a.stat:hover { border-color: var(--navy); }
.stat .n { font-size: 28px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat.warn .n { color: var(--red); }
.stat.amber .n { color: var(--amber); }
.stat.good .n { color: var(--green); }
.chart { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; align-items: end; height: 150px; padding-top: 18px; }
.chart .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; }
.chart .bar { width: 100%; max-width: 46px; background: var(--navy); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .bar.sched { background: var(--green); }
.chart .val { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.chart .lbl { font-size: 11.5px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.chart .col:hover .bar { filter: brightness(1.15); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; background: var(--navy); }
.legend i.sched { background: var(--green); }

.empty { color: var(--muted); padding: 30px; text-align: center; background: var(--white); border: 1px dashed var(--line); border-radius: 8px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--red); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,30,45,.45); display: flex; align-items: center; justify-content: center; z-index: 8; padding: 16px; }
.modal { background: #fff; border-radius: 8px; padding: 22px; width: 100%; max-width: 540px; max-height: 92vh; overflow: auto; }
.modal.wide { max-width: 760px; }
.modal h2 { margin-top: 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-width: 640px) {
  main { padding: 14px 12px 50px; }
  .topbar { gap: 8px; padding: 0 12px; }
  .topbar .who span { display: none; }
  .kv { grid-template-columns: 110px 1fr; }
  .toolbar input[type=search] { min-width: 0; flex: 1 1 100%; }
  .chart .lbl { font-size: 10px; }
}
@media print {
  .topbar, .toolbar, .chips, .actions, .bulkbar, .pager, #toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .panel, table { border: 1px solid #999; }
}
