:root {
  --bg: #f6f7f9; --surface: #fff; --ink: #111827; --ink2: #374151; --muted: #6b7280; --line: #e5e7eb; --line2: #eef0f3;
  --brand: #2563eb; --brand-ink: #fff; --brand-soft: #eaf0fe; --orange: #ea8a00;
  --red: #c62828; --red-soft: #fdecec; --amber: #92580a; --amber-soft: #fdf1c9;
  --green: #1f7a3a; --green-soft: #e6f4ea; --blue: #2563eb; --blue-soft: #eaf0fe; --grey-soft: #eef1f5;
  --radius: 10px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 34px; line-height: 1.15; margin: 0; letter-spacing: -.02em; font-weight: 800; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 12px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 12px; } .hidden { display: none; }
.ico { width: 18px; height: 18px; flex: none; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 28px; background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 20px; height: 64px; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-size: 19px; font-weight: 700; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--orange); }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; }
.brand .logo .ico { width: 17px; height: 17px; }
.toptabs { display: flex; gap: 6px; flex: 1; overflow-x: auto; }
.toptabs a { color: var(--ink2); padding: 9px 14px; border-radius: 8px; white-space: nowrap; font-size: 15px; }
.toptabs a:hover { background: var(--grey-soft); text-decoration: none; }
.toptabs a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.me { display: flex; gap: 8px; align-items: center; }
.me .status { display: flex; align-items: center; gap: 6px; color: var(--ink2); font-size: 13px; margin-right: 4px; white-space: nowrap; }
.me .status i { width: 8px; height: 8px; border-radius: 50%; background: #22a35a; }
.linkish { background: none; border: 0; cursor: pointer; font: inherit; color: var(--blue); }

/* Shell: sidebar + content */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: calc(100vh - 64px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 10px; position: sticky; top: 64px; height: calc(100vh - 64px); overflow-y: auto; }
.sidehead { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 10px; }
.sidehead span { font-size: 12.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink); }
.sideitem { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; color: var(--ink); margin-bottom: 2px; border-left: 3px solid transparent; }
.sideitem:hover { background: var(--grey-soft); text-decoration: none; }
.sideitem .ico { color: var(--muted); }
.sideitem .txt { flex: 1; font-size: 14.5px; line-height: 1.25; min-width: 0; }
.sideitem .txt small { display: block; font-size: 12px; color: var(--muted); }
.sideitem .n { font-weight: 500; font-size: 13px; color: var(--ink2); }
.sideitem .n.tone-red { color: var(--red); } .sideitem .n.tone-amber { color: #c2410c; }
.sideitem.on { background: var(--brand-soft); border-left-color: var(--brand); }
.sideitem.on .txt, .sideitem.on .ico, .sideitem.on .n { color: var(--brand); }
.sideitem.on .txt { font-weight: 600; }
.sidebar hr { border: 0; border-top: 1px solid var(--line); margin: 14px 6px; }
main { padding: 30px 28px 40px; min-width: 0; }
body.bare main.center { display: grid; place-items: center; min-height: 100vh; }

.eyebrow { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--brand); letter-spacing: .18em; text-transform: uppercase; font-size: 12.5px; margin-bottom: 8px; }
.subtitle { color: var(--ink2); font-size: 15px; margin: 8px 0 0; }
.subtitle .late { color: var(--red); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 520px; margin: 40px auto; }
.flash { background: var(--green-soft); border: 1px solid #b9dfbb; color: #1b5e20; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.error { background: var(--red-soft); border: 1px solid #f3c1c1; color: var(--red); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; }

.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #d6dae1; background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn.big { padding: 11px 20px; font-size: 15px; font-weight: 600; }
.btn:hover { border-color: #c4c9d4; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--red); border-color: #f0b5b5; }
.btn.ghost { border-color: transparent; background: none; }
.btn.small, select.small, input.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; }
form.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
form.inline select, form.inline input { width: auto; }

input, select, textarea { font: inherit; border: 1px solid #d6dae1; border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 3px solid #c7d7fd; outline-offset: 0; border-color: var(--brand); }
input[type=checkbox] { width: auto; }
label > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.stack { display: grid; gap: 10px; }
.stack label { display: grid; gap: 4px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--ink); border-color: var(--brand); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters { margin: 22px 0 18px; } .filters input.search { max-width: 420px; padding: 12px 16px; font-size: 15px; border-radius: 10px; } .filters select { max-width: 200px; } .filters input[type=date] { width: auto; }
.filters label { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.count { margin-left: auto; }
.chip { background: var(--blue-soft); color: var(--blue); padding: 4px 8px; border-radius: 99px; font-size: 12px; }

.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table.grid { border-collapse: collapse; width: 100%; }
.grid th { text-align: left; font-size: 11.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--ink2); font-weight: 700; padding: 11px 10px; border-bottom: 1px solid var(--line); background: var(--surface); white-space: nowrap; }
.grid th a::after { content: ' \21C5'; color: #b8bec9; font-weight: 400; }
.grid th a { color: inherit; }
.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line2); vertical-align: middle; color: var(--ink2); }
.grid tbody tr:nth-child(even) td { background: #fbfbfc; }
.grid.compact td { padding: 10px 12px; }
.grid.compact th { padding: 10px 12px; }
.grid tr.row { cursor: pointer; } .grid tr.row:hover td { background: #fafbfd; }
.grid td.name { font-weight: 700; color: var(--ink); white-space: nowrap; }
.grid td.t-date { white-space: nowrap; }
.grid tr.lv-overdue td:first-child { box-shadow: inset 3px 0 var(--red); }
.grid tr.lv-red td:first-child { box-shadow: inset 3px 0 #ef9a9a; }
.grid tr.lv-amber td:first-child { box-shadow: inset 3px 0 #f5c451; }
.grid tr.inactive td { opacity: .5; }
.clip { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.empty { text-align: center; padding: 30px !important; color: var(--muted); }
.grid td.needs { min-width: 240px; line-height: 1.5; }
.grid td.needs .flag { display: inline-block; background: var(--amber-soft); color: #7a4a00; border-radius: 4px; padding: 1px 6px; margin: 1px 4px 1px 0; font-size: 12px; }
.grid td.needs .flag + .flag::before { content: none; }
.grid td.needs .note { display: block; font-size: 12px; color: var(--muted); }
.flag { display: inline-block; color: var(--ink2); font-size: 13px; margin: 1px 0; }
.flag + .flag::before { content: '· '; color: var(--muted); }

.due { white-space: nowrap; }
.duepill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--grey-soft); color: var(--ink2); white-space: nowrap; margin-top: 4px; }
.duepill.lv-overdue { background: var(--red-soft); color: var(--red); }
.duepill.lv-red { background: #fde8e8; color: #b42318; }
.duepill.lv-amber { background: var(--amber-soft); color: var(--amber); }
.duepill { margin-top: 0; margin-left: 4px; padding: 1px 7px; font-size: 11.5px; }
.pill, .pillselect { display: inline-block; border-radius: 99px; padding: 2px 9px; font-size: 12px; background: var(--grey-soft); color: var(--ink); white-space: nowrap; }
.pillselect { width: auto; border: 1px solid transparent; padding: 3px 6px; cursor: pointer; }
.pillselect:hover { border-color: #cdd2dc; }
.v-pending, .v-not-started, .v-on-hold { background: var(--amber-soft); color: #7a4a00; }
.v-done, .v-admitted, .v-exported, .v-rec, .v-new { background: var(--green-soft); color: var(--green); }
.v-locked { background: var(--blue-soft); color: var(--blue); }
.v-dc, .v-tdc { background: #ede7f6; color: #5e35b1; }
.v-cancelled, .v-no-admit, .v-error { background: var(--red-soft); color: var(--red); }
.v-na, .v-not-required, .v-none, .v-dup { background: var(--grey-soft); color: var(--muted); }

.formlayout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.recordform fieldset { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0 0 14px; }
.recordform legend { font-weight: 700; padding: 0 6px; color: var(--brand); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; }
.fields .f-multi, .fields .f-textarea { grid-column: 1 / -1; }
.fields .newrow { grid-column-start: 1; }
.fields .wide { grid-column: span 2; }
.f-attachments { grid-column: span 2; display: grid; gap: 6px; align-content: start; }
.f-attachments .lbl { font-size: 12px; color: var(--muted); }
.f-attachments input[type=file] { padding: 5px; }
.filerow { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.linkish.danger { color: var(--red); padding: 0; }
.clip-file { font-size: 12px; margin-left: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.check { display: inline-flex !important; gap: 5px; align-items: center; color: var(--ink); }
.checks input.short { width: 160px; }
.formactions { display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; }
.side .card { padding: 14px; }
.logline { border-top: 1px solid var(--line); padding: 7px 0; font-size: 13px; }
.headstatus { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 4px; color: var(--ink); border-top: 4px solid var(--line); }
.tile:hover { text-decoration: none; border-color: #c4c9d4; }
.tile b { font-size: 28px; } .tile span { color: var(--muted); font-size: 13px; }
.tile.tone-red:not(.zero) { border-top-color: var(--red); } .tile.tone-red:not(.zero) b { color: var(--red); }
.tile.tone-amber:not(.zero) { border-top-color: #f5b041; }
.tile.tone-info:not(.zero) { border-top-color: var(--blue); }
.tile.zero b { color: #b7bcc7; }
.cols { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.cols .grow { flex: 1 1 560px; min-width: 0; } .cols .side-narrow { flex: 0 1 340px; }
.chase { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 6px; color: var(--ink); border-left: 4px solid var(--line); margin-bottom: 4px; background: #fafbfc; }
.chase:hover { text-decoration: none; background: var(--grey-soft); }
.chase.lv-overdue { border-left-color: var(--red); } .chase.lv-red { border-left-color: #e57373; } .chase.lv-amber { border-left-color: #f5b041; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); }
.tag { font-size: 11px; background: var(--grey-soft); padding: 2px 6px; border-radius: 4px; color: var(--muted); white-space: nowrap; }
.grouphead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.grouphead h2 { margin: 0; }

.kpis { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.kpis > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; min-width: 140px; }
.kpis b { display: block; font-size: 22px; } .kpis span { color: var(--muted); font-size: 12px; }
.kpis .good b { color: var(--green); } .kpis .bad b { color: var(--red); }
.tallies { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.bar { display: grid; grid-template-columns: 120px 1fr 34px; gap: 8px; align-items: center; font-size: 13px; padding: 2px 0; }
.bar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { background: var(--grey-soft); border-radius: 3px; height: 10px; } .bar i { display: block; height: 100%; background: var(--brand); border-radius: 3px; }
.bar b { text-align: right; }
.mapgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.imp-duplicate td, .imp-dup-file td { color: var(--muted); }
details summary { cursor: pointer; font-weight: 600; }

@media (max-width: 900px) {
  .formlayout { grid-template-columns: 1fr; }
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; position: static; }
  .toptabs { order: 3; width: 100%; }
  .me .status { display: none; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  main { padding: 16px; }
  h1 { font-size: 26px; }
}
@media print {
  .topbar, .sidebar, .noprint, .actions, .tabs, .filters, .formactions { display: none !important; }
  .shell { display: block; }
  body { background: #fff; } .card { border: 0; padding: 0; }
  .grid tr { break-inside: avoid; }
}

/* Sub-menu tabs under the page title */
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 22px; }
.subtabs a { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 8px; color: var(--ink2); background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.subtabs a:hover { text-decoration: none; border-color: #c9ced8; }
.subtabs a b { font-weight: 600; font-size: 12px; color: var(--muted); background: var(--grey-soft); border-radius: 99px; padding: 1px 8px; }
.subtabs a b.tone-red { color: var(--red); background: var(--red-soft); }
.subtabs a b.tone-amber { color: var(--amber); background: var(--amber-soft); }
.subtabs a.on { background: var(--brand-soft); border-color: #bcd0fb; color: var(--brand); font-weight: 600; }
.subtabs a.on b { background: #fff; color: var(--brand); }
.filters { margin-top: 14px; }
main { max-width: 1680px; margin: 0 auto; }
.me .btn.on { background: var(--brand-soft); color: var(--brand); border-color: #bcd0fb; }

/* Dark top bar (original colors) */
.topbar { background: #1d2433; border-bottom: 0; }
.brand { color: #f5b041; font-weight: 500; }
.brand b { color: #fff; font-weight: 700; }
.brand .logo { background: rgba(255,255,255,.12); color: #f5b041; }
.toptabs a { color: #cfd5e1; }
.toptabs a:hover { background: rgba(255,255,255,.08); color: #fff; }
.toptabs a.on { background: rgba(255,255,255,.14); color: #fff; }
.me .status { color: #cfd5e1; }
.me .btn { background: transparent; color: #cfd5e1; border-color: rgba(255,255,255,.22); }
.me .btn:hover { color: #fff; border-color: rgba(255,255,255,.45); }
.me .btn.on { background: rgba(255,255,255,.14); color: #fff; border-color: transparent; }

/* Sign-in page */
body.bare { background: #1d2433; }
body.bare main.center { max-width: none; padding: 24px 16px; }
.loginwrap { width: 100%; max-width: 400px; display: grid; gap: 18px; }
.loginbrand { display: flex; align-items: center; justify-content: center; gap: 10px; color: #f5b041; font-size: 22px; }
.loginbrand b { color: #fff; font-weight: 700; }
.loginbrand .logo { width: 36px; height: 36px; border-radius: 9px; background: rgba(255,255,255,.12); color: #f5b041; display: grid; place-items: center; }
.card.login { padding: 30px 28px; margin: 0; border: 0; border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.card.login h1 { font-size: 26px; color: var(--ink); }
.card.login > p.muted { margin: 6px 0 22px; }
.card.login .stack { gap: 16px; }
.card.login .stack label > span { font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 6px; }
.card.login input { padding: 11px 12px; font-size: 15px; }
.card.login .btn.wide { justify-content: center; margin-top: 6px; }
.loginfoot { text-align: center; color: #9aa3b5; margin: 0; }

/* Tables scroll inside their own box so the sideways scrollbar is always on screen */
.tablewrap { overflow: auto; max-height: calc(100vh - 150px); }
.grid thead th { position: sticky; top: 0; z-index: 2; }
.grid td.name, .grid th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.grid th:first-child { z-index: 3; }
