/* Design tokens.
   Light and dark are the same variable names with different values, so no
   component below ever needs to know which mode it is in. */
:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --ink: #16191d;
  --ink-2: #3d4450;
  --muted: #697180;
  --line: #e2e6ea;
  --line-strong: #cfd5dc;

  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #eff4ff;

  --good: #14713f;
  --good-bg: #e7f5ec;
  --bad: #b4231a;
  --bad-bg: #fdecea;
  --warn: #8a5a00;
  --warn-bg: #fdf3e2;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 4px 12px rgba(16, 24, 40, 0.08);
  --sidebar: 232px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1c212880;
    --ink: #e8ebef;
    --ink-2: #c2c9d2;
    --muted: #8e98a6;
    --line: #272d36;
    --line-strong: #333b46;

    --accent: #5b8dff;
    --accent-ink: #0b1020;
    --accent-soft: #1a2440;

    --good: #6ee7a5;
    --good-bg: #10281c;
    --bad: #ff8a80;
    --bad-bg: #2c1512;
    --warn: #f0c274;
    --warn-bg: #2a2011;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 6px 20px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- shell ---------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 1.1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: block;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  padding: 0.35rem 0.6rem 0.9rem;
  line-height: 1.25;
}
.brand:hover { text-decoration: none; }
.brand small { display: block; font-weight: 500; font-size: 0.72rem; color: var(--muted); }

.sidebar nav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar nav a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-weight: 500;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sidebar nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar nav a .ico { width: 1.1rem; text-align: center; opacity: 0.8; flex: none; }

.sidebar .spacer { flex: 1; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 0.7rem; font-size: 0.85rem; }
.sidebar-foot .who { color: var(--ink-2); font-weight: 600; display: block; }
.sidebar-foot .role { color: var(--muted); font-size: 0.78rem; text-transform: lowercase; }
.sidebar-foot a { display: inline-block; margin-top: 0.35rem; margin-right: 0.75rem; font-size: 0.85rem; }

.content { flex: 1; min-width: 0; }
main { max-width: 1240px; margin: 0 auto; padding: 1.6rem 1.75rem 4rem; }

/* Mobile: the sidebar becomes a scrolling strip across the top. */
@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: auto; flex: none; height: auto; position: static;
    border-right: none; border-bottom: 1px solid var(--line);
    padding: 0.7rem 0.9rem;
  }
  .brand { padding-bottom: 0.6rem; }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: 0.25rem; padding-bottom: 0.2rem; }
  .sidebar nav a { white-space: nowrap; padding: 0.4rem 0.7rem; }
  .sidebar nav a .ico { display: none; }
  .sidebar .spacer { display: none; }
  .sidebar-foot { margin-top: 0.6rem; padding-top: 0.6rem; display: flex; align-items: baseline; gap: 0.75rem; }
  .sidebar-foot .role { display: none; }
  main { padding: 1.1rem 1rem 3rem; }
}

/* --- type ----------------------------------------------------------------- */
h1 { font-size: 1.55rem; letter-spacing: -0.015em; margin: 0 0 0.2rem; }
h2 { font-size: 1rem; margin: 0 0 0.85rem; letter-spacing: -0.005em; }
h3 { font-size: 0.9rem; margin: 1.4rem 0 0.5rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.muted { color: var(--muted); font-size: 0.88rem; }
.nowrap { white-space: nowrap; }
.overdue { color: var(--bad); font-weight: 600; }
.danger { color: var(--bad); }

/* --- surfaces ------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.3rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 400px; margin: 12vh auto; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 1.25rem; align-items: start; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.9rem; margin-bottom: 1.4rem; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.95rem 1.05rem; box-shadow: var(--shadow);
}
.stat .value { display: block; font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.stat .label { color: var(--muted); font-size: 0.8rem; }

.banner { padding: 0.9rem 1.15rem; border-radius: var(--radius); margin-bottom: 1.3rem; font-weight: 600; border: 1px solid transparent; }
.banner.granted { background: var(--good-bg); color: var(--good); border-color: color-mix(in srgb, var(--good) 25%, transparent); }
.banner.denied { background: var(--bad-bg); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }

.flash { padding: 0.75rem 1.05rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-weight: 500; }
.flash.success { background: var(--good-bg); color: var(--good); }
.flash.error { background: var(--bad-bg); color: var(--bad); }
.flash.info { background: var(--warn-bg); color: var(--warn); }

/* --- tables --------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; }
table.card { padding: 0; overflow: hidden; }
th, td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.scroll-x { overflow-x: auto; }

dl { margin: 0; }
dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-top: 0.85rem; }
dd { margin: 0.15rem 0 0; }
ul.prose { margin: 0.5rem 0; padding-left: 1.1rem; }
ul.prose li { margin-bottom: 0.35rem; }

.pill {
  display: inline-block; padding: 0.12rem 0.55rem; border-radius: 999px;
  font-size: 0.73rem; font-weight: 600; background: var(--line); color: var(--ink-2);
  text-transform: lowercase; white-space: nowrap;
}
.pill.granted, .pill.allowed, .pill.active, .pill.paid { background: var(--good-bg); color: var(--good); }
.pill.denied, .pill.refused, .pill.cancelled, .pill.unpaid, .pill.expired { background: var(--bad-bg); color: var(--bad); }
.pill.frozen, .pill.partial, .pill.void { background: var(--warn-bg); color: var(--warn); }

/* --- forms ---------------------------------------------------------------- */
label { display: block; margin-bottom: 0.8rem; font-size: 0.82rem; color: var(--muted); font-weight: 500; }
input, select, textarea {
  display: block; width: 100%; margin-top: 0.3rem; padding: 0.55rem 0.65rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font: inherit; color: var(--ink); background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.75; }
textarea { resize: vertical; }
fieldset { border: none; border-top: 1px solid var(--line); padding: 1.1rem 0 0; margin: 0 0 0.5rem; }
fieldset:first-of-type { border-top: none; padding-top: 0; }
legend { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 0 1rem; }

.checkbox { display: flex; gap: 0.6rem; align-items: flex-start; color: var(--ink); }
.checkbox input { width: auto; margin-top: 0.3rem; }

button, .button {
  display: inline-block; padding: 0.55rem 0.95rem; border: 1px solid var(--accent);
  border-radius: var(--radius-sm); background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(1.07); text-decoration: none; }
button:active, .button:active { transform: translateY(1px); }
.button.ghost, button.ghost {
  background: var(--surface); color: var(--accent); border-color: var(--line-strong);
}
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.link {
  background: none; border: none; color: var(--accent); padding: 0;
  font-weight: 500; text-decoration: underline; cursor: pointer;
}
button.link.danger { color: var(--bad); background: none; border: none; }

form.inline, .actions, .filters { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
form.inline label, .filters label { margin-bottom: 0; }
form.inline input, form.inline select, .filters input, .filters select { width: auto; margin-top: 0; }
.filters { margin-bottom: 1.3rem; }
.filters input[name="q"] { min-width: 260px; }
.actions { margin-top: 0.5rem; }

/* --- attendance bars ------------------------------------------------------ */
.bars { display: flex; align-items: flex-end; gap: 0.6rem; height: 150px; margin: 0.5rem 0 0.25rem; }
.bar {
  flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
  align-items: center; height: 100%;
}
.bar-fill {
  width: 100%; min-height: 3px; border-radius: 5px 5px 0 0;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 65%, transparent));
}
.bar:hover .bar-fill { filter: brightness(1.12); }
.bar-value { font-size: 0.78rem; font-weight: 700; order: -1; margin-bottom: 0.3rem; }
.bar-label { font-size: 0.72rem; color: var(--muted); margin-top: 0.4rem; }

/* --- empty states --------------------------------------------------------- */
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 1rem; margin-bottom: 0.3rem; }
