:root {
  --bg: #f4f7f8;
  --panel: #ffffff;
  --ink: #15262d;
  --muted: #5d7079;
  --line: #dde5e8;
  --brand: #0b7a75;
  --brand-dark: #075955;
  --brand-soft: #e3f3f1;
  --sea: #1d5c8c;
  --ok: #1f8a4c;
  --ok-soft: #e4f4ea;
  --warn: #b26a00;
  --warn-soft: #fdf1dc;
  --bad: #c0392b;
  --bad-soft: #fbe6e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 48, .06), 0 2px 8px rgba(16, 40, 48, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #08403f 0%, #0b5f5b 100%);
  color: #dff1ef; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 20px; flex: none;
}
.brand-name { font-weight: 700; line-height: 1.15; font-size: .95rem; color: #fff; }
.brand-sub { font-size: .75rem; opacity: .75; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: #d3ebe8; padding: 9px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center;
  font-size: .93rem;
}
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: #fff; color: var(--brand-dark); font-weight: 600; }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.nav-label { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; opacity: .55; margin: 14px 12px 4px; }
.nav .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.12); font-size: .85rem; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot a { color: #bfe3df; }

.main { min-width: 0; }
.topbar {
  display: none; background: var(--brand-dark); color: #fff; padding: 10px 14px; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 20;
}
.topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
.content { padding: 24px 28px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }

/* ---------- Panels & cards ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: block; color: inherit; }
a.kpi:hover { text-decoration: none; border-color: var(--brand); }
.kpi .label { font-size: .8rem; color: var(--muted); }
.kpi .value { font-size: 1.7rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.bad .value { color: var(--bad); }
.kpi.warn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #f8fafb; position: sticky; top: 0; }
tbody tr:hover { background: #f6fbfa; }
tr.clickable { cursor: pointer; }
tfoot td { font-weight: 700; background: #f8fafb; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eef2f3; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: #e4eef7; color: var(--sea); }
.badge.brand { background: var(--brand-soft); color: var(--brand-dark); }
.nav .badge.bad { background: #e8574a; color: #fff; }

/* ---------- Forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-size: .92rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #b9c8cc; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--bad); border-color: #efc4bf; }
.btn.small { padding: 4px 9px; font-size: .82rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-size: .83rem; font-weight: 600; color: #34484f; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #c9d5d8; border-radius: 8px; font: inherit; font-size: .93rem;
  background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11,122,117,.25); border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field-hint { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.filters > div { min-width: 150px; }
.filters .grow { flex: 1; min-width: 200px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: #fff; padding: 6px 12px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .85rem; color: var(--muted); }
.tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* line-entry table */
.lines td { padding: 6px 6px; vertical-align: top; }
.lines input, .lines select { padding: 6px 8px; }
.lines .del { color: var(--bad); background: none; border: 0; font-size: 18px; cursor: pointer; padding: 6px; }

/* combobox */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + 2px); background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px; overflow-y: auto; min-width: 280px;
}
.combo-list div { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #f0f3f4; font-size: .9rem; }
.combo-list div:hover, .combo-list div.hl { background: var(--brand-soft); }
.combo-list .meta { font-size: .78rem; color: var(--muted); }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 30, 36, .45); display: grid; place-items: start center; padding: 5vh 12px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: min(760px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(1000px, 100%); }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal-head .x { margin-left: auto; background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #15262d; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: .92rem; max-width: 90vw; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, #bfe6e1 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #cfe0ef 0%, transparent 60%), var(--bg); }
.auth-card { width: min(420px, 100%); background: #fff; border-radius: 14px; box-shadow: 0 10px 40px rgba(16,40,48,.12); padding: 28px; }
.auth-card .brand-mark { background: var(--brand); color: #fff; width: 48px; height: 48px; font-size: 24px; margin-bottom: 14px; }
.auth-card h1 { font-size: 1.3rem; }
.auth-card form { display: grid; gap: 12px; margin-top: 18px; }
.err { background: var(--bad-soft); color: var(--bad); padding: 9px 12px; border-radius: 8px; font-size: .9rem; }
.info-box { background: var(--brand-soft); color: var(--brand-dark); padding: 10px 12px; border-radius: 8px; font-size: .9rem; }

.detail-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: .92rem; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; }

.print-head { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  body { overflow-x: hidden; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .topbar { display: flex; }
  .content { padding: 16px 12px 60px; }
  .grid-2, .grid-3, .grid[style] { grid-template-columns: minmax(0, 1fr) !important; }
}

/* ---------- Print ---------- */

/* ---------- Duty roster ---------- */
.week-nav { align-items: center; }
.week-nav input[type=date] { width: auto; padding: 5px 8px; }
.roster-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line); }
.roster-sheet { color: #111; }
.roster-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 10px; }
.roster-org { font-size: .72rem; font-weight: 700; line-height: 1.3; }
.roster-title { font-family: Georgia, 'Times New Roman', serif; font-weight: 700; font-size: 1.15rem; text-decoration: underline; text-align: center; letter-spacing: .02em; }
.roster-logo { justify-self: end; width: 34px; height: 34px; border-radius: 50%; border: 2px solid #c0392b; color: #1e8449; font-weight: 800; display: grid; place-items: center; }
.roster-period { font-size: .75rem; font-weight: 700; font-style: italic; margin: 6px 0 4px; }
table.roster { border: 1.5px solid #333; min-width: 760px; }
table.roster th, table.roster td { border: 1px solid #555; padding: 4px 6px; text-align: center; font-size: .82rem; text-transform: none; letter-spacing: 0; position: static; }
table.roster thead th { background: #a9d18e; color: #111; font-weight: 600; }
table.roster thead th.r-des, table.roster thead th.r-name { font-weight: 700; }
table.roster th.r-fri-h { color: #c0392b; }
table.roster td.r-des { font-weight: 500; background: #fff; width: 130px; }
table.roster td.r-name { text-align: left; white-space: nowrap; width: 190px; position: relative; padding-right: 26px; }
table.roster td.r-off { background: #f8cbad; }
table.roster td.r-leave { background: #fff2cc; font-weight: 700; }
table.roster td.r-oncall { color: #c0392b; font-weight: 600; }
table.roster td.r-fri { background-color: #f1f1f1; }
table.roster td.r-fri.r-off { background: #f8cbad; }
table.roster td.r-fri.r-leave { background: #fff2cc; }
table.roster tr.r-extra td { background: #e7e6e6; color: #2e6b2e; }
table.roster tr.r-extra td.r-off { background: #f8cbad; }
table.roster tr.r-extra td.r-oncall, table.roster tr.r-extra td.r-xlabel { color: #c0392b; }
table.roster td.r-xlabel { font-weight: 700; font-size: .75rem; position: relative; }
table.roster.editing td.r-in { padding: 0; }
table.roster.editing td.r-in input { width: 100%; min-width: 58px; border: 0; background: transparent; text-align: center; padding: 6px 2px; font: inherit; color: inherit; border-radius: 0; box-shadow: none; }
table.roster.editing td.r-in input:focus { outline: 2px solid var(--brand); outline-offset: -2px; background: #fff; }
table.roster td.r-saving { opacity: .55; }
table.roster td.r-err { outline: 2px solid var(--bad); outline-offset: -2px; }
.r-fill { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); border: 1px solid var(--line); background: #fff; border-radius: 5px; cursor: pointer; font-size: .8rem; line-height: 1; padding: 2px 5px; color: var(--muted); }
.r-fill:hover { color: var(--brand); border-color: var(--brand); }
table.roster.editing button.r-cell { width: 100%; min-width: 58px; min-height: 28px; border: 0; background: transparent; font: inherit; color: inherit; cursor: pointer; padding: 4px 2px; }
table.roster.editing button.r-cell:hover { background: rgba(11,122,117,.08); }
table.roster.editing button.r-cell:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.shift-picker { position: fixed; z-index: 1000; display: flex; flex-direction: column; background: #fff; border: 1.5px solid #333; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-height: 70vh; overflow-y: auto; }
.shift-picker .sp-opt { border: 0; border-bottom: 1px solid rgba(0,0,0,.15); padding: 7px 14px; font: inherit; font-weight: 600; font-size: .9rem; color: #222; cursor: pointer; text-align: center; background: #fff; }
.shift-picker .sp-opt:hover, .shift-picker .sp-opt:focus { outline: 2px solid #1f3f8f; outline-offset: -2px; filter: brightness(.95); }
.shift-picker .sp-cur { box-shadow: inset 0 0 0 2px #1f3f8f; }
.shift-picker .sp-clear { color: var(--muted); }
.shift-picker .sp-other { font-weight: 500; font-size: .8rem; color: var(--muted); }
.shift-picker .sp-input { width: 110px; margin: 6px; padding: 5px 7px; }
.roster-legend { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin: 16px 0 6px; }
.roster-legend table { width: auto; min-width: 200px; border: 1.5px solid #333; }
.roster-legend th, .roster-legend td { border: 1px solid #777; padding: 2px 10px; text-align: center; font-size: .72rem; text-transform: none; letter-spacing: 0; color: #111; position: static; }
.roster-legend th { background: #a9d18e; font-weight: 700; }
.roster-note { text-align: center; font-size: .75rem; margin-top: 4px; }
.roster-sigs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 34px; text-align: center; font-size: .78rem; }
.roster-sigs .sig-line { border-bottom: 1px solid #444; width: 60%; margin: 0 auto 4px; height: 28px; }
.staff-edit td { padding: 5px 6px; }
.staff-edit input { min-width: 0; }
.sig-fields { display: grid; grid-template-columns: 1fr 1.3fr 2fr; gap: 6px; }
table.roster tbody td { height: 24px; }
.roster-sigs .small { font-size: inherit; }
@media (max-width: 700px) {
  .sig-fields { grid-template-columns: 1fr; } .roster-sigs { grid-template-columns: 1fr; }
  .roster-top { grid-template-columns: 1fr auto; } .roster-org { grid-column: 1 / -1; font-size: .65rem; } .roster-title { text-align: left; }
  table.roster td.r-des { width: 80px; font-size: .72rem; } table.roster td.r-name { white-space: normal; min-width: 130px; }
}
body:has(.roster-sheet) { page: roster; }
@page roster { size: A4 landscape; margin: 10mm; }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; font-size: 11pt; }
  .sidebar, .topbar, .no-print, .btn, .filters, .tabs, #toast { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  .panel { border: 0; box-shadow: none; }
  .print-head { display: block; margin-bottom: 12px; border-bottom: 2px solid #000; padding-bottom: 8px; }
  th { background: #eee !important; position: static; }
  th, td { padding: 5px 6px; font-size: 9.5pt; }
  tr { page-break-inside: avoid; }
  .roster-sheet .table-wrap { overflow: visible; }
  table.roster { min-width: 0; }
  table.roster th, table.roster td { padding: 3px 4px; font-size: 8.5pt; }
  table.roster thead th, .roster-legend th { background: #a9d18e !important; }
  .roster-legend th, .roster-legend td { font-size: 7.5pt; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
