/* MIL Statistics — application styles. No external fonts, no inline styles (strict CSP). */

:root {
  --green: #83bf48;
  --green-dark: #6ea53a;
  --navy: #001737;
  --navy-soft: #1b2f52;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7686;
  --line: #e2e7ef;
  --danger: #c62828;
  --danger-bg: #fdecec;
  --warn: #9a6b00;
  --warn-bg: #fff6dc;
  --ok: #1f7a3a;
  --ok-bg: #e6f5ea;
  --info-bg: #e8f0fe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--navy-soft); }
h1, h2, h3 { margin: 0 0 .35em; line-height: 1.2; color: var(--navy); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding-inline: 16px; }
.main { flex: 1; padding-block: 24px 40px; }

/* Top bar ----------------------------------------------------------------- */
.topbar { background: var(--navy); color: #fff; box-shadow: var(--shadow); }
.topbar-inner { display: flex; align-items: center; gap: 20px; min-height: 58px; flex-wrap: wrap; padding-block: 6px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .3px; }
.brand img { border-radius: 6px; background: #fff; padding: 2px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { color: rgba(255,255,255,.85); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: .93rem; }
.nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav a.active { background: var(--green); color: #fff; font-weight: 600; }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-name { color: #fff; text-decoration: none; font-size: .9rem; }
.user-name small { color: rgba(255,255,255,.65); text-transform: uppercase; font-size: .7em; margin-left: 4px; }
.user-menu form { margin: 0; }

.nav-panel { display: flex; align-items: center; gap: 20px; flex: 1; min-width: 0; }
.nav-public { margin-left: auto; }
.nav-toggle { display: none; margin-left: auto; width: 44px; height: 40px; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; background: transparent; cursor: pointer; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0; }
.nav-toggle-bar { display: block; width: 20px; height: 2px; background: #fff; border-radius: 1px; transition: transform .2s, opacity .2s; }
.topbar.nav-open .nav-toggle-bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.topbar.nav-open .nav-toggle-bar:nth-child(2) { opacity: 0; }
.topbar.nav-open .nav-toggle-bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.footer { display: flex; justify-content: space-between; padding-block: 14px; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); }

/* Buttons ------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .93rem; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn-primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--line); }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.btn-ghost:hover { background: rgba(0,23,55,.06); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: .85rem; }
.btn-block { width: 100%; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--navy-soft); text-decoration: underline; cursor: pointer; }
button.link.danger { color: var(--danger); }

/* Alerts ------------------------------------------------------------------- */
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: #cfe9d6; }
.alert-error, .alert-danger { background: var(--danger-bg); color: var(--danger); border-color: #f5c6c6; }
.alert-warning { background: var(--warn-bg); color: var(--warn); border-color: #f1dfa6; }
.alert-info { background: var(--info-bg); color: var(--navy); border-color: #c9d9f7; }
.temp-password { display: inline-block; font-size: 1.1em; padding: 2px 8px; background: #fff; border: 1px dashed var(--warn); border-radius: 6px; user-select: all; margin-left: 6px; }

/* Page head ---------------------------------------------------------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; color: var(--muted); margin: 0 0 2px; font-weight: 600; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px; border-radius: 999px; background: var(--info-bg); color: var(--navy); vertical-align: middle; }
.badge-admin { background: var(--navy); color: #fff; }
.badge-matron { background: var(--info-bg); color: var(--navy); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-muted { background: #eceff3; color: var(--muted); }

/* Cards -------------------------------------------------------------------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card-soft { background: #fbfcfe; border: 1px dashed var(--line); box-shadow: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* KPIs --------------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; border-top: 4px solid var(--green); }
.kpi:first-child { border-top-color: var(--navy); }
.kpi-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 2rem; font-weight: 700; color: var(--navy); line-height: 1.1; margin: 4px 0; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: .5em; color: var(--muted); font-weight: 500; }
.kpi-sub { font-size: .82rem; color: var(--muted); }

/* Charts ------------------------------------------------------------------- */
.chart-box { position: relative; height: 320px; max-width: 100%; }
.legend { display: flex; align-items: center; gap: 6px 14px; font-size: .85rem; color: var(--muted); flex-wrap: wrap; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.swatch-patients { background: var(--navy); }
.swatch-staff { background: var(--green); }
.swatch-capacity { background: transparent; border: 2px dashed #b23a3a; height: 0; width: 18px; border-width: 0 0 2px; vertical-align: 3px; }

/* Chips / reviews ---------------------------------------------------------- */
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-block; padding: 5px 12px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); text-decoration: none; font-size: .88rem; font-weight: 600; border: 1px solid #f1dfa6; }
.chip:hover { background: #fff0c2; }
.reviews { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.review { border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: 8px; padding: 12px 14px; background: #fbfcfe; }
.review h3 { margin-bottom: 4px; }
.review p { margin: 0; white-space: normal; overflow-wrap: anywhere; }

/* Public board tweaks --------------------------------------------------------- */
body.public .kpi-value { font-size: 2.4rem; }
body.public .chart-box { height: 380px; }
body.public .review p { font-size: 1.05rem; }

/* Forms -------------------------------------------------------------------- */
.form.narrow { max-width: 560px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field.grow { flex: 1; }
label { font-weight: 600; font-size: .9rem; color: var(--navy); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="month"], input[type="search"], select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid #cfd6e0; border-radius: 8px; background: #fff; color: var(--text); width: 100%; max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(131,191,72,.45); outline-offset: 1px; border-color: var(--green); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }
textarea { resize: vertical; min-height: 80px; }
.hint { font-size: .82rem; color: var(--muted); margin: 0; }
.field-error { color: var(--danger); font-size: .85rem; margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filters .field { margin-bottom: 0; min-width: 150px; }

fieldset.checks { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
fieldset.checks legend { font-weight: 600; font-size: .9rem; color: var(--navy); padding: 0; margin-bottom: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; color: var(--text); padding: 6px 0; cursor: pointer; }
.check input { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--green); flex: none; }

/* Reports ------------------------------------------------------------------ */
.report-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 18px; }
.report-card { display: flex; flex-direction: column; margin-bottom: 0; border-top: 4px solid var(--green); }
.report-card > .muted { min-height: 3.2em; }
.report-pick { display: flex; flex-direction: column; gap: 5px; margin: 4px 0 14px; }
.report-pick .inline-form { width: 100%; }
.report-pick input { flex: 1; min-width: 0; }
.report-period { margin-top: 2px; }
.report-status { list-style: none; padding: 0; margin: 0 0 16px; flex: 1; }
.report-status li { position: relative; padding: 5px 0 5px 20px; font-size: .9rem; border-bottom: 1px dashed var(--line); }
.report-status li:last-child { border-bottom: 0; }
.report-status li::before { content: ""; position: absolute; left: 2px; top: 11px; width: 9px; height: 9px; border-radius: 50%; background: #c3cad6; }
.report-status li.ok::before { background: var(--green); }
.report-status li.warn::before { background: #e0a100; }
.report-card .form-actions { margin-top: auto; }
.report-card .hint { margin-top: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Notifications / offline ------------------------------------------------------ */
.push-box { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #fbfcfe; margin-bottom: 14px; }
.push-status { font-weight: 600; color: var(--navy); }
.push-test { margin-top: 0; }
.notif-grid { gap: 0 18px; }
.offline { max-width: 520px; margin: 40px auto; text-align: center; }
.offline-logo { width: 180px; max-width: 60%; height: auto; margin-bottom: 12px; }

/* Auth --------------------------------------------------------------------- */
.auth { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; align-items: center; max-width: 900px; margin: 30px auto; }
.auth-logo { max-width: 100%; height: auto; }
.auth-card { padding: 28px; }
.auth-card h1 { font-size: 1.4rem; }
.auth-card input { margin-bottom: 14px; }

/* Tables ------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table.small { font-size: .82rem; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #f8fafc; }
.table tbody tr:hover { background: #f8fafc; }
.table tr.inactive td { color: var(--muted); }
.review-cell { max-width: 320px; overflow-wrap: anywhere; }
.details { max-width: 420px; overflow-wrap: anywhere; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .78rem; color: var(--muted); }
.row-actions { white-space: nowrap; }
.row-actions a, .row-actions button { margin-right: 10px; }
.row-actions form.inline { display: inline; margin: 0; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 14px; }

/* Error page ---------------------------------------------------------------- */
.error-page { max-width: 560px; margin: 60px auto; text-align: center; }

/* Installed app / notched phones: keep content out of the status bar and home indicator. */
.topbar { padding-top: env(safe-area-inset-top, 0); }
.wrap { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.footer { padding-bottom: max(14px, env(safe-area-inset-bottom, 0px)); }

/* Touch screens: comfortable tap targets. */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .row-actions a, .row-actions button.link { display: inline-block; padding: 6px 0; }
  .check { padding: 9px 0; }
  .check input { width: 20px; height: 20px; margin-top: 1px; }
}

/* Responsive ----------------------------------------------------------------- */
@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }
  .nav-panel { display: none; flex: 0 0 100%; width: 100%; flex-direction: column; align-items: stretch; gap: 8px; padding: 4px 0 12px; }
  .topbar.nav-open .nav-panel { display: flex; }
  .nav-panel .nav { flex-direction: column; gap: 2px; }
  .nav-panel .nav a { padding: 11px 12px; font-size: 1rem; border-radius: 8px; }
  .nav-panel .user-menu { margin-left: 0; justify-content: space-between; border-top: 1px solid rgba(255,255,255,.15); padding-top: 10px; }
  .notif-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .auth { grid-template-columns: 1fr; gap: 16px; }
  .auth-brand { text-align: center; }
  .auth-logo { max-width: 260px; }
  .grid-3 { grid-template-columns: 1fr; }
  .report-grid { grid-template-columns: 1fr; }
  .report-card > .muted { min-height: 0; }
}
@media (max-width: 600px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 1.6rem; }
  body.public .kpi-value { font-size: 1.8rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .chart-box { height: 260px; }
  h1 { font-size: 1.3rem; }
  /* 16px stops iOS zooming into a field on focus. */
  input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="month"], input[type="search"], select, textarea { font-size: 16px; }
  .main { padding-block: 16px 28px; }
  .card { padding: 16px; }
  .page-head { align-items: stretch; }
  .page-head .actions { width: 100%; }
  .inline-form { flex-wrap: wrap; }
  .inline-form input { width: auto; flex: 1 1 140px; min-width: 0; }
  .page-head .actions > .btn { flex: 1 1 auto; }
  .table th, .table td { padding: 8px 8px; }
  .footer { flex-direction: column; gap: 4px; }
  .form-actions .btn { flex: 1 1 auto; }
  .hide-sm { display: none; }
}
@media print {
  .topbar, .footer, .actions, .row-actions, .filters { display: none !important; }
  .card, .kpi { box-shadow: none; border: 1px solid #ccc; }
}
