:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --text-faint: #6e6e73;
  --line: #e5e5ea;
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --danger: #d70015;
  --ok: #1f8a4c;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e; --surface: #2c2c2e; --text: #f5f5f7; --text-faint: #a1a1a6;
    --line: #3a3a3c; --accent: #2997ff; --accent-soft: rgba(41, 151, 255, 0.16);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--text-faint); }
.mono { font-variant-numeric: tabular-nums; }

/* Login */
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border-radius: 18px; padding: 32px 28px; display: grid; gap: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08); }
.login-card h1 { font-size: 24px; }
label { display: grid; gap: 6px; font-size: 12.5px; color: var(--text-faint); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.form-error { color: var(--danger); min-height: 18px; font-size: 13px; }

/* Buttons */
.btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 7px 16px; cursor: pointer; }
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 11px; font-size: 12.5px; }
.btn.danger { color: var(--danger); }

/* Shell */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 17px; padding: 0 10px 16px; }
#nav { display: grid; gap: 2px; }
#nav .nav-group { font-size: 11.5px; color: var(--text-faint); padding: 14px 10px 4px; }
#nav button { text-align: left; font: inherit; color: var(--text); background: none; border: 0; border-radius: 8px; padding: 8px 10px; cursor: pointer; }
#nav button:hover { background: var(--accent-soft); }
#nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#nav button:disabled { color: var(--text-faint); cursor: default; background: none; }
.main { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar h2 { font-size: 20px; }
.user-menu { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page { padding: 24px; display: grid; gap: 18px; }

/* Content */
.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h3 { font-size: 15px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 18px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--text-faint); }
tr:last-child td { border-bottom: 0; }
td.actions { display: flex; gap: 6px; }
.empty-state { padding: 28px 18px; text-align: center; color: var(--text-faint); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; background: var(--accent-soft); color: var(--accent); }
.badge.off { background: rgba(215, 0, 21, 0.1); color: var(--danger); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 4px; }
.tile b { font-size: 26px; font-weight: 600; }
.tile span { color: var(--text-faint); font-size: 12.5px; }

/* Dialog + toast */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(460px, calc(100% - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
#dialog-form { padding: 22px; display: grid; gap: 12px; }
#dialog-form h3 { font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 13px; z-index: 10; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  #nav { grid-auto-flow: column; overflow-x: auto; gap: 4px; }
  #nav .nav-group { display: none; }
  .page { padding: 16px; }
  .topbar { padding: 12px 16px; }
}

/* Document control */
.badge.warn { background: rgba(199, 95, 12, 0.14); color: #b8570a; }
.badge.muted { background: var(--line); color: var(--text-faint); }
button.tile { font: inherit; color: inherit; text-align: left; border: 0; cursor: pointer; }
.tile.bad b { color: var(--danger); }
.tile.warn b { color: #c75f0c; }
button.tile:hover { box-shadow: 0 0 0 2px var(--accent-soft) inset; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; align-items: start; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--accent-soft); }
tr.selected td { background: var(--accent-soft); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.filters input { flex: 1 1 220px; }
.filters select { width: auto; flex: 0 1 190px; }
td.wrap { white-space: normal; min-width: 200px; }
.back { justify-self: start; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px 24px; margin: 0; padding: 16px 18px; }
.facts div { display: grid; gap: 3px; }
.facts .wide { grid-column: 1 / -1; }
.facts dt { font-size: 12px; color: var(--text-faint); }
.facts dd { margin: 0; }
.note { margin: 0; padding: 0 18px 16px; color: var(--text-faint); }
.steps { list-style: none; margin: 0; padding: 4px 18px 18px; display: grid; gap: 10px; }
.steps li { display: grid; gap: 2px; padding-left: 14px; border-left: 3px solid var(--accent-soft); }
.steps li em { color: var(--text-faint); }
.checks { display: flex; gap: 14px; flex-wrap: wrap; }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13.5px; }
label.check input { width: auto; }
dialog small { font-size: 12px; }
.dialog-message { margin: 0; font-size: 13px; }
dialog textarea { resize: vertical; }
/* Reminders (the bell) */
.bell { position: relative; }
.bell-count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11.5px; line-height: 18px; text-align: center; }
.bell-panel { position: absolute; right: 24px; top: 62px; z-index: 5; width: min(420px, calc(100% - 32px)); max-height: 70vh; overflow-y: auto; background: var(--surface); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22); }
.bell-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.notice { display: grid; gap: 2px; padding: 11px 16px; border-bottom: 1px solid var(--line); border-left: 4px solid var(--accent-soft); cursor: pointer; }
.notice:hover { background: var(--accent-soft); }
.notice.unread b { color: var(--text); }
.notice:not(.unread) { opacity: 0.62; }
.notice.WARNING { border-left-color: #c75f0c; }
.notice.OVERDUE { border-left-color: var(--danger); }
.notice small { color: var(--text-faint); }
.topbar { position: relative; }.main { position: relative; }

/* Incidents */
.tiles.inner { padding: 16px 18px; }
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 130px; padding: 8px 18px 14px; }
.bar { position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bar span { display: block; width: 100%; max-width: 34px; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 2px; opacity: 0.85; }
.bar b { font-size: 11px; position: absolute; top: 0; }
.bar small { color: var(--text-faint); font-size: 11px; margin-top: 4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
/* Registers */
.editor-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; padding: 14px 18px 4px; }
.editor-head .wide { grid-column: 1 / -1; }
table.editor th, table.editor td { padding: 6px 8px; vertical-align: top; white-space: normal; }
table.editor input, table.editor select, table.editor textarea { font-size: 12.5px; padding: 6px 7px; min-width: 100px; }
table.editor textarea { min-width: 170px; }
table.editor td:nth-child(5) select, table.editor td:nth-child(6) select, table.editor td:nth-child(9) select, table.editor td:nth-child(10) select { min-width: 150px; }
/* People and training */
.cell { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.cell.OK { background: rgba(31, 138, 76, 0.14); color: #1f7a44; }
.cell.DONE { background: var(--line); color: var(--text-faint); }
.cell.DUE_SOON { background: rgba(199, 95, 12, 0.14); color: #b8570a; }
.cell.EXPIRED, .cell.MISSING { background: rgba(215, 0, 21, 0.12); color: var(--danger); }
.cell.NA { color: var(--text-faint); }
.legend { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 18px; border-bottom: 1px solid var(--line); }
table.matrix th, table.matrix td { text-align: center; }
table.matrix th:first-child, table.matrix td:first-child { text-align: left; }
.sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.induct { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; padding: 14px 18px 18px; }
.induct-group { display: grid; gap: 6px; align-content: start; }
table.plan td.mcell { text-align: center; width: 38px; font-weight: 600; }
table.plan td.mcell.P { background: rgba(0, 113, 227, 0.16); color: var(--accent); }
table.plan td.mcell.I { background: rgba(31, 138, 76, 0.2); color: #1f7a44; }
table.plan td[data-month] { cursor: pointer; }
table.plan input { min-width: 140px; }
.eval-form { border-top: 1px solid var(--line); }
.eval-form summary { padding: 12px 18px; cursor: pointer; }
.eval-form .note { margin: 8px 18px 14px; }
