/* Deák Koli — internal operations platform.
 *
 * One stylesheet, no framework, no webfont (spec sections 50, 67, 68): the
 * app is used on the dormitory's own network, so every byte is served from
 * here and nothing phones home.
 *
 * Mobile-first: layout starts single-column with large touch targets and
 * widens at 768px / 1100px. Teachers walk the floors with a phone in one
 * hand, so tap targets never shrink below --tap and the round screens stay
 * usable one-handed.
 */

/* ==========================================================================
   1. Tokens
   ========================================================================== */

:root {
  color-scheme: light;

  /* Surfaces, from the page backdrop up to raised cards. */
  --bg: #f4f7fb;
  --bg-accent: #eaf0f8;
  --surface: #ffffff;
  --surface-2: #f2f5fa;
  --surface-3: #e7edf5;
  --border: #dce4ee;
  --border-strong: #c3cfdd;

  /* Ink. */
  --text: #101c2b;
  --text-2: #3a4a5e;
  --muted: #64748b;
  --muted-2: #8496ab;

  /* Brand: the school's navy. */
  --brand: #1f4e79;
  --brand-hover: #1a4269;
  --brand-dark: #163a5a;
  --brand-ink: #1a4269;
  --brand-soft: #e8f0f8;
  --brand-soft-2: #d7e5f3;

  /* Semantic. */
  --ok: #15784c;
  --ok-soft: #e2f4ec;
  --ok-border: #b6e0cb;
  --warn: #92600a;
  --warn-soft: #fdf3e0;
  --warn-border: #f0dcb6;
  --bad: #b3261e;
  --bad-soft: #fdecea;
  --bad-border: #f3c9c6;
  --info: #1f4e79;
  --info-soft: #e8f0f8;
  --info-border: #c9dcee;

  /* Shape. */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* Depth: two soft layers rather than one hard drop. */
  --shadow-xs: 0 1px 2px rgba(15, 28, 43, .06);
  --shadow: 0 1px 2px rgba(15, 28, 43, .05), 0 4px 12px rgba(15, 28, 43, .05);
  --shadow-md: 0 2px 4px rgba(15, 28, 43, .06), 0 8px 24px rgba(15, 28, 43, .08);
  --shadow-lg: 0 12px 32px rgba(15, 28, 43, .18);
  --ring: 0 0 0 3px rgba(31, 78, 121, .28);

  /* Rhythm. */
  --tap: 46px;
  --topbar-h: 56px;
  --sidebar-w: 252px;
}

/* Dark mode is opt-in by the operating system only. Every colour below is a
   token swap: no component redefines a colour of its own, so the two themes
   can never drift apart. */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0c1420;
    --bg-accent: #111c2b;
    --surface: #14202f;
    --surface-2: #1a293a;
    --surface-3: #223448;
    --border: #26374b;
    --border-strong: #35495f;

    --text: #e8eef6;
    --text-2: #bccbdb;
    --muted: #93a5ba;
    --muted-2: #74899f;

    --brand: #4f92cf;
    --brand-hover: #6aa5db;
    --brand-dark: #3f7fba;
    --brand-ink: #a9cdec;
    --brand-soft: #17304a;
    --brand-soft-2: #1d3d5e;

    --ok: #4ec08c;
    --ok-soft: #10301f;
    --ok-border: #1d5138;
    --warn: #e0a340;
    --warn-soft: #33260f;
    --warn-border: #59421a;
    --bad: #f0837a;
    --bad-soft: #351917;
    --bad-border: #5c2b27;
    --info: #4f92cf;
    --info-soft: #17304a;
    --info-border: #24486d;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 12px rgba(0, 0, 0, .3);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .38);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
    --ring: 0 0 0 3px rgba(79, 146, 207, .35);
  }
}

/* ==========================================================================
   2. Base
   ========================================================================== */

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  font-feature-settings: "kern" 1;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-hover); }

/* One consistent focus ring everywhere, and only for keyboard users. */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}
:focus:not(:focus-visible) { outline: none; }

/* Respect the reader's motion preference. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* Keyboard users land here first and can jump the navigation. */
.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transition: top .15s ease;
}
.skip-link:focus { top: 8px; }

/* Icons come from the inline sprite in _icons.html. Stroke and size are set
   here so an icon always matches the text it sits beside. */
.ico {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==========================================================================
   3. Typography
   ========================================================================== */

h1 {
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: -.02em;
  margin: 0 0 4px;
  font-weight: 700;
}
h2 {
  font-size: 16px;
  line-height: 1.3;
  letter-spacing: -.01em;
  margin: 0 0 12px;
  font-weight: 650;
}
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; }

@media (min-width: 768px) {
  h1 { font-size: 26px; }
  h2 { font-size: 17px; }
}

.subtitle {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

/* ==========================================================================
   4. Layout: topbar, sidebar, shell
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 12px;
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-xs);
}
@media (min-width: 768px) {
  .topbar { padding: 0 20px; gap: 14px; }
}
.topbar a { color: #fff; text-decoration: none; }
.topbar .spacer { flex: 1; }

/* Brand lockup: a small mark plus the wordmark. */
.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -.01em;
  padding: 6px 6px 6px 2px;
  border-radius: var(--radius-sm);
}
.topbar .brand:hover { color: #fff; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: rgba(255, 255, 255, .16);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .02em;
  flex: none;
}

/* The signed-in user, shown as initials on phones and in full from tablet up. */
.topbar .who {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 6px 5px 5px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .1);
  white-space: nowrap;
}
.who-avatar {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .22);
  font-size: 11px;
  font-weight: 700;
  flex: none;
}
.who-name { display: none; padding-right: 4px; }
@media (min-width: 560px) { .who-name { display: inline; } }

/* Ghost button on the navy bar: legible without competing with the brand. */
.topbar .btn {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 13px;
  background: rgba(255, 255, 255, .12);
  border-color: rgba(255, 255, 255, .26);
  color: #fff;
  box-shadow: none;
}
.topbar .btn:hover { background: rgba(255, 255, 255, .22); }
.topbar form { display: flex; }

.menu-toggle {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .1);
  color: #fff;
  cursor: pointer;
  transition: background .15s ease;
}
.menu-toggle:hover { background: rgba(255, 255, 255, .2); }
.menu-toggle svg { width: 18px; height: 18px; }

.shell { display: block; }

/* ---- Sidebar ---- */
.sidebar {
  display: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 10px 24px;
}
.sidebar.open { display: block; }

.sidebar .group { margin-bottom: 2px; }

.sidebar a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-height: var(--tap);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  transition: background .13s ease, color .13s ease;
}
.sidebar a:hover { background: var(--surface-2); color: var(--text); }

/* The icon column keeps every label on the same optical grid. */
.sidebar .ico {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--muted);
  transition: color .13s ease;
}
.sidebar a:hover .ico { color: var(--text-2); }

/* Current page: tinted, brand-inked, with a flush accent bar. */
.sidebar a.active {
  background: var(--brand-soft);
  color: var(--brand-ink);
}
.sidebar a.active .ico { color: var(--brand-ink); }
.sidebar a.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}

/* The header of the section the user is inside: inked, but without the fill
   or the accent bar, so it never competes with the active child below it. */
.sidebar a.in-section { color: var(--brand-ink); }
.sidebar a.in-section .ico { color: var(--brand-ink); }

/* Children sit under a hairline guide, one indent in. */
.sidebar .sub {
  margin: 2px 0 6px;
  padding-left: 26px;
  border-left: 1px solid var(--border);
  margin-left: 21px;
}
.sidebar .sub a {
  font-weight: 500;
  font-size: 13.5px;
  padding: 8px 10px;
  min-height: 38px;
  color: var(--muted);
}
.sidebar .sub a:hover { color: var(--text); }
.sidebar .sub a.active {
  color: var(--brand-ink);
  font-weight: 600;
  background: var(--brand-soft);
}
.sidebar .sub a.active::before { display: none; }

/* A rule above the account links at the foot of the nav. */
.sidebar .group.nav-foot { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

/* The drawer's scrim on phones; visibility is the [hidden] attribute, which
   app.js toggles, so there is one source of truth for "is the drawer open". */
.nav-scrim {
  position: fixed;
  inset: var(--topbar-h) 0 0;
  z-index: 15;
  background: rgba(10, 20, 32, .45);
  backdrop-filter: blur(1px);
}

/* Below the breakpoint the sidebar is a drawer: it lifts out of the flow and
   sits *above* the scrim, which otherwise dims the very menu it is meant to
   set apart from the page. */
@media (max-width: 767.98px) {
  .sidebar.open {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 20;
    width: min(82vw, 310px);
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: var(--shadow-lg);
    animation: drawer-in .18s cubic-bezier(.4, 0, .2, 1);
  }
}

@keyframes drawer-in {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

main {
  padding: 16px;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 768px) {
  .shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    align-items: start;
    min-height: calc(100vh - var(--topbar-h));
  }
  .sidebar {
    display: block;
    position: sticky;
    top: var(--topbar-h);
    max-height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .menu-toggle, .nav-scrim { display: none !important; }
  main { padding: 24px 28px 48px; }
}

/* ==========================================================================
   5. Page head
   ========================================================================== */

.page-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.page-head > div:first-child { min-width: 0; }

/* ==========================================================================
   6. Cards & grid
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
@media (min-width: 768px) { .card { padding: 18px 20px; } }

/* A card heading doubles as its toolbar: title left, action right. */
.card h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* Cards nest on a few screens (the reports index puts one worksheet card per
   export inside a section card). The inner ones drop their shadow so the
   stack reads as one raised surface rather than three. */
.card .card {
  box-shadow: none;
  background: var(--surface-2);
}
.card .card:last-child { margin-bottom: 0; }

/* Many list screens hand the whole card over to one table (the card is set
   to padding:0 there). Round the table into the card's corners so it reads
   as one object rather than a table sitting on top of a box. */
.card > .table-wrap:only-child {
  border-radius: inherit;
}
.card > .table-wrap:only-child th:first-child { border-top-left-radius: inherit; }
.card > .table-wrap:only-child th:last-child { border-top-right-radius: inherit; }

.grid { display: grid; gap: 14px; }
@media (min-width: 700px) { .grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ==========================================================================
   7. Stats
   ========================================================================== */

.stat {
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: 18px 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}
/* A hairline of colour states the reading at a glance, before the number. */
.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--border-strong);
}
.stat.ok::before { background: var(--ok); }
.stat.warn::before { background: var(--warn); }
.stat.bad::before { background: var(--bad); }

.stat .value {
  font-size: 32px;
  font-weight: 750;
  line-height: 1.05;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.stat .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 650;
  margin-top: 6px;
}
.stat.ok .value { color: var(--ok); }
.stat.bad .value { color: var(--bad); }
.stat.warn .value { color: var(--warn); }

/* ==========================================================================
   8. Tables
   ========================================================================== */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 650;
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
}
/* Only a real column header pins. Several screens (Profil, a student's data
   sheet) use <th> as the *row* label of a key/value table; pinning those to
   the top of the viewport would tear the label off its own row. */
thead th { position: sticky; top: 0; z-index: 1; }

tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child > * { border-bottom: none; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   9. Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background .14s ease, border-color .14s ease,
              box-shadow .14s ease, transform .06s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted-2); color: var(--text); }
.btn:active { transform: translateY(1px); box-shadow: none; }

.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }

.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { filter: brightness(1.08); color: #fff; }

.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); color: #fff; }

.btn.small { min-height: 34px; padding: 5px 11px; font-size: 13px; }

.btn[disabled], .btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn .ico { width: 16px; height: 16px; flex: none; }

/* The student self-service actions: thumb-sized, unmissable. */
.btn-huge {
  display: flex;
  width: 100%;
  min-height: 76px;
  font-size: 20px;
  font-weight: 750;
  letter-spacing: .01em;
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ==========================================================================
   10. Forms
   ========================================================================== */

input[type=text], input[type=search], input[type=email], input[type=password],
input[type=date], input[type=time], input[type=number], input[type=datetime-local],
input[type=tel], input[type=url], select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color .14s ease, box-shadow .14s ease;
}
textarea { min-height: 76px; resize: vertical; }

input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) {
  border-color: var(--muted-2);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}

/* Native select gets a chevron so it does not read as a text field. */
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%2364748b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px;
  padding-right: 34px;
}
select[multiple] { background-image: none; padding-right: 12px; }

/* The chevron is a data URI, so its colour cannot come from a token: the
   dark theme needs its own copy. */
@media (prefers-color-scheme: dark) {
  select {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%2393a5ba' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  }
  select[multiple] { background-image: none; }
}

label {
  display: block;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-2);
  margin-bottom: 5px;
}

.field { margin-bottom: 15px; }
.field .helptext {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
  font-weight: 400;
}
.field .errorlist {
  color: var(--bad);
  font-size: 13px;
  font-weight: 500;
  margin: 5px 0 0;
  padding-left: 18px;
}

.filters { display: grid; gap: 10px; margin-bottom: 16px; }
@media (min-width: 700px) {
  .filters { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: end; }
}

.checkline {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
}
.checkline input { width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--brand); }
.checkline label { margin: 0; font-weight: 500; color: var(--text); }

input[type=checkbox], input[type=radio] { accent-color: var(--brand); }

/* ==========================================================================
   11. Badges & status
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.5;
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-border); }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-border); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.badge.info { background: var(--info-soft); color: var(--info); border-color: var(--info-border); }

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: -1px;
  box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 12%, transparent);
  flex: none;
}

.status-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.status-hero .big {
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -.02em;
}
.status-hero.inside { background: var(--ok-soft); border-color: var(--ok-border); }
.status-hero.outside { background: var(--warn-soft); border-color: var(--warn-border); }

/* ==========================================================================
   12. Messages & notices
   ========================================================================== */

.messages { margin-bottom: 16px; display: grid; gap: 8px; }
.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid;
  box-shadow: var(--shadow-xs);
}
.message.success { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.message.error { background: var(--bad-soft); border-color: var(--bad-border); color: var(--bad); }
.message.warning { background: var(--warn-soft); border-color: var(--warn-border); color: var(--warn); }
.message.info, .message.debug { background: var(--info-soft); border-color: var(--info-border); color: var(--info); }

.notice {
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  color: var(--warn);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 15px;
}

/* ==========================================================================
   13. Progress
   ========================================================================== */

.progress {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width .35s cubic-bezier(.4, 0, .2, 1);
}
.progress.done > span { background: var(--ok); }

/* ==========================================================================
   14. Utilities
   ========================================================================== */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .95em;
}
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: 10px; }

.empty {
  padding: 32px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 18px;
  flex-wrap: wrap;
}

/* Shown only on paper (see the print block). */
.print-only { display: none; }

/* A dead end (403/404/500) reads as a message, not as a broken page. */
.error-state {
  max-width: 460px;
  margin: 6vh auto 0;
  padding: 8px 16px 40px;
  text-align: center;
}
.error-state .error-code {
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
  color: var(--border-strong);
  font-variant-numeric: tabular-nums;
}
.error-state h1 { margin: 12px 0 6px; }
.error-state .subtitle { margin-bottom: 22px; }
.error-state .actions { justify-content: center; }

/* ==========================================================================
   15. Sign-in
   ========================================================================== */

.auth-page {
  max-width: 408px;
  margin: 0 auto;
  padding: 7vh 16px 40px;
  min-height: 100vh;
}
/* A soft brand wash behind the sign-in card, so the first screen is not
   a bare grey rectangle. */
body:has(> .auth-page) {
  background:
    radial-gradient(1100px 520px at 50% -12%, var(--brand-soft) 0%, transparent 62%),
    var(--bg);
}
.auth-page .card { padding: 26px 24px; box-shadow: var(--shadow-md); }
.auth-page .btn { width: 100%; }
.auth-page .field:last-of-type { margin-bottom: 20px; }

.auth-logo { text-align: center; margin-bottom: 22px; }
.auth-logo .brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  margin-bottom: 12px;
  background: var(--brand);
  color: #fff;
  font-size: 17px;
  box-shadow: var(--shadow-md), inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.auth-logo .name {
  font-size: 21px;
  font-weight: 750;
  letter-spacing: -.02em;
  color: var(--text);
}
.auth-logo .tagline { font-size: 14px; color: var(--muted); margin-top: 2px; }

.auth-foot { text-align: center; margin-top: 18px; font-size: 13px; }

/* ==========================================================================
   16. Confirmation dialog
   --------------------------------------------------------------------------
   Drawn in the page rather than via window.confirm, which browsers and
   webviews are free to suppress (a suppressed confirm returns false and would
   silently cancel the action).
   ========================================================================== */

.confirm-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(400px, calc(100% - 32px));
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.confirm-dialog::backdrop { background: rgba(10, 20, 32, .5); }
.confirm-panel { padding: 22px; }
.confirm-question {
  margin: 0 0 20px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
}
.confirm-actions { display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap; }
.confirm-actions .btn { min-width: 118px; }

/* Fallback for browsers without <dialog>: the element is the overlay. */
.confirm-dialog-fallback {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  border: none;
  border-radius: 0;
  background: rgba(10, 20, 32, .5);
  box-shadow: none;
}
.confirm-dialog-fallback .confirm-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: min(400px, calc(100% - 32px));
  box-shadow: var(--shadow-lg);
}
.confirm-dialog[hidden] { display: none !important; }

/* Row flash after an inline save. */
tr.saved > td { background: var(--ok-soft); transition: background .6s ease; }

/* ==========================================================================
   17. Monthly worksheet
   --------------------------------------------------------------------------
   A spreadsheet-shaped grid: labels down the side, days across the top, one
   table per floor. Scrolls horizontally on screen; each floor starts a new
   page when printed.
   ========================================================================== */

.sheet-section { margin-bottom: 22px; }
.sheet-heading { font-size: 15px; margin: 0 0 8px; font-weight: 650; }

table.sheet { font-size: 12px; }
table.sheet th, table.sheet td { padding: 4px 6px; }
table.sheet th.day, table.sheet td.day {
  width: 26px;
  min-width: 26px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
table.sheet th.weekend, table.sheet td.weekend { background: var(--surface-2); }
table.sheet .sticky-label {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
  white-space: nowrap;
}
table.sheet thead .sticky-label { background: var(--surface-2); z-index: 3; }
table.sheet tbody tr:hover .sticky-label { background: var(--surface-2); }

/* The room number cell is united down over its residents (rowspan), so it is
   centred in the block it covers; the rule marks where the next room starts. */
table.sheet td.united { vertical-align: middle; font-weight: 650; }
table.sheet tr.room-start > td { border-top: 1px solid var(--muted); }

/* ==========================================================================
   18. Print (weekend roster & worksheets, A4 landscape)
   ========================================================================== */

@media print {
  @page { size: A4 landscape; margin: 10mm; }

  /* Paper is always light. Resetting the tokens themselves (not just body)
     matters because prefers-color-scheme still reports "dark" while
     printing from a dark-themed screen, and anything drawn from a token -
     the worksheet's sticky room labels, for one - would print near-black. */
  :root {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f1f4f9;
    --surface-3: #e7edf5;
    --border: #c9c9c9;
    --border-strong: #999999;
    --text: #000000;
    --text-2: #222222;
    --muted: #555555;
    --muted-2: #777777;
  }

  .topbar, .sidebar, .nav-scrim, .no-print, .messages, .skip-link,
  .pagination, .filters { display: none !important; }

  /* Paper is always light, whatever the screen was set to. */
  body {
    background: #fff !important;
    color: #000 !important;
    font-size: 11px;
  }
  .shell { display: block !important; }
  main { padding: 0; max-width: none; }

  .card {
    box-shadow: none;
    border: none;
    padding: 0;
    background: #fff !important;
    margin-bottom: 8px;
  }
  .card > .table-wrap:last-child { margin: 0; }

  a { color: #000 !important; text-decoration: none; }

  table { font-size: 10px; }
  th, td { padding: 4px 6px; border: 1px solid #999; color: #000 !important; }
  th {
    background: #e8e8e8 !important;
    color: #000 !important;
    position: static;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  tbody tr { page-break-inside: avoid; }
  tbody tr:hover { background: transparent; }

  /* Badges must survive losing their background fill. */
  .badge {
    border: 1px solid #999 !important;
    background: transparent !important;
    color: #000 !important;
  }

  /* The inline style on these headings hides them on screen; paper needs
     them back, and only !important outranks an inline declaration. */
  .print-only { display: block !important; }

  .sheet-heading { font-size: 12px; margin: 0 0 4px; }
  .sheet-section { page-break-after: always; margin-bottom: 0; }
  .sheet-section:last-of-type { page-break-after: auto; }
  .sheet-legend { page-break-before: avoid; }
  table.sheet { font-size: 8px; }
  table.sheet th, table.sheet td { padding: 2px 3px; }
  table.sheet th.day, table.sheet td.day { width: auto; min-width: 0; }
  table.sheet .sticky-label { position: static; }
  table.sheet th.weekend, table.sheet td.weekend {
    background: #eceff3 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  table.sheet tr.room-start > td { border-top: 1px solid #666; }
  table.sheet td.united { vertical-align: middle; }
}
