:root {
  --navy: #0b1f3a;
  --navy-2: #16345e;
  --amber: #f5b301;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1b2430;
  --muted: #5f6b7a;
  --border: #dde3ea;
  --danger: #c0392b;
  --success: #1e8e5a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 31, 58, .06), 0 4px 12px rgba(11, 31, 58, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--navy);
  color: #fff;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav-icon { display: none; }
.logout {
  color: #dbe4f0;
  font: inherit;
  font-size: .9rem;
  background: none;
  border: 1px solid rgba(255, 255, 255, .25);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.logout:hover { background: var(--navy-2); color: #fff; }
.nav a {
  color: #dbe4f0;
  text-decoration: none;
  font-size: .9rem;
  padding: 6px 10px;
  border-radius: 8px;
}
.nav a:hover { background: var(--navy-2); color: #fff; }
.nav a.active { background: var(--navy-2); color: #fff; }

/* Phones: the menu becomes a bottom tab bar, within reach of the thumb. */
@media (max-width: 640px) {
  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    margin: 0;
    gap: 0;
    background: var(--navy);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, .15);
  }
  .nav:empty { display: none; }
  .nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 2px 7px;
    font-size: .72rem;
    border-radius: 0;
    min-height: 56px;
  }
  .nav a.active { background: none; color: var(--amber); }
  .nav a:hover { background: none; }
  .nav-icon { display: block; height: 22px; }
  body.has-tabbar .container { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  body.has-tabbar .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* Typography */
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid > .card + .card { margin-top: 0; } /* the grid gap already spaces them */
.grid + .card { margin-top: 16px; }
.tile { display: block; text-decoration: none; color: inherit; }
.tile:hover { border-color: var(--navy-2); }
.tile strong { display: block; font-size: 1.05rem; margin-bottom: 4px; }

/* Forms */
.form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
label { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; }
input, select, textarea {
  font: inherit;
  font-weight: 400;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  width: 100%;
  min-height: 44px;
}
textarea { min-height: 88px; resize: vertical; }
.hint { font-size: .85rem; font-weight: 500; color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--amber); outline-offset: 1px; border-color: var(--navy-2); }
.pw-field { position: relative; display: block; }
.pw-field input { padding-right: 48px; }
.pw-toggle {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 46px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
}
.pw-toggle:hover { color: var(--navy); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; min-height: 0; }
.field-error { color: var(--danger); font-size: .82rem; font-weight: 500; }
.form-error {
  color: var(--danger);
  background: #fdecea;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
}

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  background: var(--navy);
  color: #fff;
}
.btn:hover { background: var(--navy-2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.secondary { background: #fff; color: var(--navy); border-color: var(--border); }
.btn.secondary:hover { border-color: var(--navy-2); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: .85rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Tables: become stacked cards on narrow screens */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
  text-align: left;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .row-actions { text-align: right; white-space: nowrap; }

@media (max-width: 640px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .table td { border: 0; padding: 3px 0; }
  .table td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--muted);
    font-size: .82rem;
  }
  .table .num, .table .row-actions { text-align: left; }
  .table .row-title { font-size: 1.05rem; padding-bottom: 6px; }
  .table .row-actions { padding-top: 8px; }
}

.badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e8edf3;
  color: var(--navy);
}
.badge.ok { background: #e3f5ec; color: var(--success); }
.badge.off { background: #f1f2f4; color: var(--muted); }
.badge.warn { background: #fff4d6; color: #8a6100; }

/* Dialog */
dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(11, 31, 58, .45); }
dialog {
  max-height: calc(100dvh - 32px);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog .card { border: 0; box-shadow: none; }
/* Long dialogs scroll, but their buttons stay visible at the bottom. */
dialog .actions {
  position: sticky;
  bottom: -20px;
  background: var(--surface);
  padding: 12px 0 20px;
  margin-bottom: -20px;
  border-top: 1px solid var(--border);
}
.form > h2, .form > p { margin: 0; }

@media (max-width: 640px) {
  dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .form .actions .btn { flex: 1; }
}

/* Login */
.auth-wrap {
  min-height: calc(100vh - 80px);
  display: grid;
  place-items: center;
}
.auth-card { width: min(400px, 100%); }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth-logo strong { font-size: 1.2rem; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
  z-index: 50;
}
.toast.error { background: var(--danger); }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

/* Weekly report */
.status-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.facts { display: grid; gap: 0; margin: 0; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.facts div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.notice {
  background: #fff8e1;
  border: 1px solid #f3dd9b;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
}
.corrections { display: grid; gap: 12px; }
.correction { border-left: 3px solid var(--amber); padding: 4px 0 4px 12px; }
.correction ul { margin: 6px 0; padding-left: 18px; }
.correction p { margin: 6px 0 0; }
.summary-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  min-width: 130px;
}
.stat span { display: block; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list a { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; color: inherit; text-decoration: none; }
.list a:hover strong { text-decoration: underline; }
