/* ==========================================================================
   Jumuiya System — interface styles
   Self-contained: no web fonts, no CDN, no build step. Works offline.
   ========================================================================== */
:root {
  /* Surfaces */
  --bg: #e9efeb;
  --surface: #ffffff;
  --surface-2: #f1f6f3;
  --surface-3: #e4eee9;
  --line: #e4ebe7;
  --line-strong: #cfdcd5;

  /* Text */
  --ink: #0d1a14;
  --ink-soft: #3c4b44;
  --muted: #5f716a;
  --faint: #8fa199;

  /* Brand */
  --green: #0d6b45;
  --green-mid: #128052;
  --green-dark: #0a4a30;
  --green-darker: #073626;
  --green-tint: #e6f2ec;
  --green-ring: rgba(13, 107, 69, 0.25);
  --lime: #8ec63f;
  --lime-dark: #6ba326;
  --gold: #e0ac36;

  /* Status */
  --danger: #c33a2c;
  --danger-bg: #fdecea;
  --warn: #9a6a06;
  --warn-bg: #fdf2d9;
  --info: #2f7fd4;
  --info-bg: #e9f2fc;
  --success: #0d6b45;
  --success-bg: #e6f2ec;

  /* Shape & depth */
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --shadow-xs: 0 1px 2px rgba(9, 32, 22, 0.06);
  --shadow: 0 1px 2px rgba(9, 32, 22, 0.04), 0 4px 14px rgba(9, 32, 22, 0.06);
  --shadow-md: 0 8px 26px rgba(9, 32, 22, 0.10);
  --shadow-green: 0 8px 20px rgba(13, 107, 69, 0.22);
  --shadow-lg: 0 30px 70px rgba(3, 22, 14, 0.38);

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --fast: 130ms;
  --slow: 220ms;

  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Inter, Roboto, Arial, sans-serif;

  --sidebar-w: 244px;
  font-size: 16px;

  /* Older names still referenced by inline styles in some templates */
  --color-bg: var(--bg);
  --color-surface: var(--surface);
  --color-border: var(--line);
  --color-text: var(--ink);
  --color-text-muted: var(--muted);
  --color-primary: var(--green);
  --color-primary-dark: var(--green-dark);
  --color-primary-light: var(--green-tint);
  --color-accent: var(--gold);
  --color-danger: var(--danger);
  --color-danger-bg: var(--danger-bg);
  --color-success: var(--success);
  --color-success-bg: var(--success-bg);
  --radius: var(--r);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { font-family: var(--display); letter-spacing: -0.025em; line-height: 1.2; }

a { color: var(--green); text-decoration: none; transition: color var(--fast) var(--ease); }
a:hover { color: var(--green-dark); text-decoration: underline; text-underline-offset: 3px; }

:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--green-tint); color: var(--green-darker); }

p { margin: 0 0 12px; }

.icon { width: 19px; height: 19px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ==========================================================================
   Layout — floating sidebar + content
   ========================================================================== */
.layout { display: flex; min-height: 100vh; gap: 16px; padding: 16px; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
  overflow-y: auto;
  border-radius: var(--r-lg);
  background: linear-gradient(168deg, var(--green-mid) 0%, var(--green) 38%, var(--green-darker) 100%);
  color: #dcece4;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  scrollbar-width: thin;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.25;
  color: #fff;
  letter-spacing: -0.015em;
}
.sidebar .brand small {
  display: block;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.72rem;
  margin-top: 3px;
  letter-spacing: 0.02em;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #a8dc5c, var(--lime) 60%, var(--lime-dark));
  box-shadow: 0 6px 16px rgba(142, 198, 63, 0.3);
  color: var(--green-darker);
}
.brand-mark svg { width: 20px; height: 20px; stroke-width: 2.6; }

.sidebar .nav-label {
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
  padding: 16px 14px 7px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 3px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.89rem;
  font-weight: 600;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.1); color: #fff; text-decoration: none; }
.sidebar nav a.active {
  background: linear-gradient(140deg, #a8dc5c, var(--lime));
  color: var(--green-darker);
  box-shadow: 0 6px 16px rgba(142, 198, 63, 0.28);
}

/* Collapsible menu — only shown once the sidebar goes horizontal */
.nav-toggle { display: none; }
.nav-toggle-btn { display: none; }

.sidebar .user-box {
  margin-top: auto;
  padding: 10px;
  border-radius: 15px;
  background: rgba(0, 0, 0, 0.22);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-box .avatar {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.8rem;
  color: var(--green-darker);
  background: linear-gradient(145deg, #f3d791, var(--gold));
}
.user-box .user-meta { min-width: 0; flex: 1; line-height: 1.3; }
.user-box .user-meta strong { display: block; color: #fff; font-size: 0.83rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .user-meta span { color: rgba(255, 255, 255, 0.55); font-size: 0.74rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar .user-box form { margin: 0; }
.sidebar .user-box button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.sidebar .user-box button:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 10px 20px;
}
.topbar h1 { font-size: 1.75rem; margin: 0; font-weight: 800; letter-spacing: -0.035em; }
.topbar .subtitle { color: var(--muted); font-size: 0.88rem; margin-top: 3px; }
.topbar > div:last-child:not(:first-child) { display: flex; gap: 10px; flex-wrap: wrap; }

.content { padding: 0 2px 56px; width: 100%; max-width: 1280px; }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 24px 26px;
  margin-bottom: 18px;
}
.card > p:last-child { margin-bottom: 0; }
.card > p + p { padding-top: 14px; border-top: 1px solid var(--line); }

/* ==========================================================================
   Stat tiles — first one filled, the rest white
   ========================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
  transition: transform var(--slow) var(--ease), box-shadow var(--slow) var(--ease);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-card:first-child {
  background: linear-gradient(155deg, var(--green-mid), var(--green) 55%, var(--green-dark));
  color: #fff;
  box-shadow: var(--shadow-green);
}
.stat-card:first-child .label { color: rgba(255, 255, 255, 0.82); }
.stat-card:first-child .value { color: #fff; }
.stat-card:first-child .sub { color: rgba(255, 255, 255, 0.78); }
.stat-card:first-child::after {
  content: "";
  position: absolute;
  right: -34px;
  bottom: -52px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 18px solid #fff;
  opacity: 0.1;
  pointer-events: none;
}

/* Tile tone, set explicitly by the page rather than by position:
   .owing = money owed (red), .clear = settled (green), .plain = no fill.
   These come after the :first-child rule so they win wherever they land. */
.stat-card.owing,
.stat-card.clear {
  color: #fff;
  border: none;
}
.stat-card.owing {
  background: linear-gradient(155deg, #d1503f, var(--danger) 55%, #93251a);
  box-shadow: 0 8px 20px rgba(195, 58, 44, 0.26);
}
.stat-card.clear {
  background: linear-gradient(155deg, var(--green-mid), var(--green) 55%, var(--green-dark));
  box-shadow: var(--shadow-green);
}
.stat-card.owing .label,
.stat-card.clear .label { color: rgba(255, 255, 255, 0.85); }
.stat-card.owing .value,
.stat-card.clear .value { color: #fff; }
.stat-card.owing .sub,
.stat-card.clear .sub { color: rgba(255, 255, 255, 0.82); }
.stat-card.owing .sub a,
.stat-card.clear .sub a { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
.stat-card.owing::after,
.stat-card.clear::after {
  content: "";
  position: absolute;
  right: -34px;
  bottom: -52px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 18px solid #fff;
  opacity: 0.1;
  pointer-events: none;
}
.stat-card.plain {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.stat-card.plain .label { color: var(--muted); }
.stat-card.plain .value { color: var(--ink); }
.stat-card.plain .sub { color: var(--muted); }
.stat-card.plain::after { display: none; }

/* An amount that is owed, wherever it appears in a table */
.amount-owed { color: var(--danger); font-weight: 700; }

/* A summing row at the foot of a table, so it doesn't read as another record */
tr.total-row td {
  background: var(--surface-3);
  font-weight: 750;
  color: var(--ink);
  border-top: 1px solid var(--line-strong);
}
tr.total-row:hover td { background: var(--surface-3); }
tr.is-owed td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

.stat-card .label { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.stat-card .value {
  font-family: var(--display);
  font-size: clamp(1.5rem, 2.2vw, 2.1rem);
  font-weight: 800;
  margin-top: 7px;
  color: var(--ink);
  letter-spacing: -0.04em;
  line-height: 1.1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.stat-card .sub { font-size: 0.79rem; color: var(--muted); margin-top: 4px; }

/* ==========================================================================
   Tables — spaced rows on a tinted block
   ========================================================================== */
table { width: 100%; border-collapse: separate; border-spacing: 0 7px; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
th {
  text-align: left;
  padding: 0 16px 4px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}
td {
  padding: 14px 16px;
  background: var(--surface-2);
  font-weight: 550;
  color: var(--ink-soft);
  white-space: nowrap;
  transition: background-color var(--fast) var(--ease);
}
td:first-child { border-radius: 12px 0 0 12px; }
td:last-child { border-radius: 0 12px 12px 0; }
tr:hover td { background: var(--surface-3); }
td a { color: var(--ink); font-weight: 700; }
td a:hover { color: var(--green); }
.table-wrap {
  overflow-x: auto;
  margin: 0 -6px;
  padding: 0 6px;
  /* Shadows appear at whichever edge still has content to scroll to, so a
     wide table reads as scrollable rather than cut off. */
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(255, 255, 255, 0)) left center,
    linear-gradient(to left, var(--surface) 30%, rgba(255, 255, 255, 0)) right center,
    radial-gradient(farthest-side at 0 50%, rgba(9, 32, 22, 0.14), rgba(9, 32, 22, 0)) left center,
    radial-gradient(farthest-side at 100% 50%, rgba(9, 32, 22, 0.14), rgba(9, 32, 22, 0)) right center;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(160deg, var(--green-mid), var(--green));
  color: #fff;
  border: none;
  padding: 11px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.87rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: var(--shadow-green);
  transition: background var(--fast) var(--ease), box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:hover { background: var(--green-dark); color: #fff; text-decoration: none; box-shadow: 0 10px 24px rgba(13, 107, 69, 0.3); }
.btn:active { transform: translateY(1px) scale(0.985); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--green-ring); }

.btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-xs);
}
.btn.secondary:hover { background: var(--surface-2); color: var(--ink); box-shadow: var(--shadow); }

.btn.danger { background: linear-gradient(160deg, #d6493a, var(--danger)); box-shadow: 0 8px 20px rgba(195, 58, 44, 0.24); }
.btn.danger:hover { background: #a02b20; box-shadow: 0 10px 24px rgba(195, 58, 44, 0.3); }
.btn.danger:focus-visible { box-shadow: 0 0 0 4px rgba(195, 58, 44, 0.28); }

.btn.small { padding: 7px 13px; font-size: 0.79rem; border-radius: 9px; box-shadow: none; }
.btn.small:hover { box-shadow: var(--shadow-xs); }

/* ==========================================================================
   Badges & pills
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 750;
  line-height: 1.4;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.active, .badge.present, .badge.ok { background: var(--success-bg); color: var(--success); }
.badge.inactive, .badge.absent { background: var(--danger-bg); color: var(--danger); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.neutral { background: var(--surface-3); color: var(--muted); }

.tag-pill {
  display: inline-block;
  background: #eef7e2;
  color: #4a7015;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  margin: 2px 4px 2px 6px;
  vertical-align: middle;
}

/* ==========================================================================
   Forms
   ========================================================================== */
form.stacked label { display: block; font-size: 0.8rem; font-weight: 700; margin: 16px 0 6px; color: var(--ink); }

form.stacked input:not([type="checkbox"]):not([type="radio"]),
form.stacked select,
form.stacked textarea,
.filters input,
.filters select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), background-color var(--fast) var(--ease);
}
form.stacked input:hover, form.stacked select:hover, form.stacked textarea:hover,
.filters input:hover, .filters select:hover { border-color: #b4c5bc; }
form.stacked input:focus, form.stacked select:focus, form.stacked textarea:focus,
.filters input:focus, .filters select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 4px var(--green-ring);
}
form.stacked input::placeholder, form.stacked textarea::placeholder { color: var(--faint); }
form.stacked select[multiple] { padding: 8px; }
form.stacked textarea { min-height: 110px; resize: vertical; }

input[type="checkbox"], input[type="radio"] { accent-color: var(--green); width: 17px; height: 17px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; }
.form-actions { margin-top: 26px; display: flex; gap: 12px; flex-wrap: wrap; }

.checkbox-row { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.checkbox-row input { width: auto; }
form.stacked .checkbox-row label { margin: 0; font-weight: 500; }

.filters {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  align-items: end;
  padding: 16px 18px;
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.filters .field { display: flex; flex-direction: column; gap: 6px; min-width: 160px; }
.filters label { font-size: 0.68rem; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.filters input, .filters select { padding: 9px 12px; font-size: 0.86rem; border-radius: 10px; }

/* ==========================================================================
   Feedback
   ========================================================================== */
.flash {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 18px;
  border-radius: var(--r);
  margin-bottom: 18px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-xs);
  animation: flash-in 280ms var(--ease);
}
.flash::before { content: ""; width: 9px; height: 9px; flex-shrink: 0; border-radius: 50%; background: currentColor; }
.flash.success { background: #dff0e7; color: #0b5537; }
.flash.error { background: var(--danger-bg); color: #9a2d22; }

@keyframes flash-in { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }

.empty-state { text-align: center; padding: 42px 20px; color: var(--muted); font-size: 0.9rem; white-space: normal; }
tr:hover td.empty-state { background: var(--surface-2); }

/* ==========================================================================
   Login
   ========================================================================== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(55% 45% at 82% 12%, rgba(142, 198, 63, 0.3), transparent 70%),
    radial-gradient(65% 55% at 8% 96%, rgba(18, 128, 82, 0.6), transparent 72%),
    linear-gradient(160deg, var(--green-dark), var(--green-darker));
}
.login-wrap > div { width: 100%; max-width: 400px; }
.login-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 38px 36px 34px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: rise-in 420ms var(--ease);
}
.login-card .brand-mark { width: 50px; height: 50px; border-radius: 16px; margin-bottom: 20px; }
.login-card .brand-mark svg { width: 24px; height: 24px; }
.login-card h1 { font-size: 1.5rem; margin: 0 0 5px; letter-spacing: -0.03em; }
.login-card p.tag { color: var(--muted); font-size: 0.87rem; margin: 0 0 22px; }
.login-card .btn { padding: 13px 18px; font-size: 0.93rem; }
.login-foot { text-align: center; margin-top: 20px; font-size: 0.76rem; color: rgba(255, 255, 255, 0.62); }
.login-foot a { color: #fff; font-weight: 600; text-decoration: none; border-bottom: 1px solid rgba(255, 255, 255, 0.4); padding-bottom: 1px; }
.login-foot a:hover { border-bottom-color: #fff; text-decoration: none; }

/* Discreet credit at the foot of every signed-in page */
.app-foot {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 0.74rem;
  color: var(--faint);
}
.app-foot a { color: var(--muted); font-weight: 600; }
.app-foot a:hover { color: var(--green); }

@keyframes rise-in { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Misc
   ========================================================================== */
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.section-title h2 { margin: 0; font-size: 1.1rem; font-weight: 750; }
.section-title > a { font-size: 0.83rem; font-weight: 700; }

.text-muted { color: var(--muted); }
.mt-0 { margin-top: 0; }

.tabs {
  display: inline-flex;
  gap: 3px;
  padding: 5px;
  margin-bottom: 20px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-xs);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 9px 18px;
  font-size: 0.86rem;
  font-weight: 650;
  color: var(--muted);
  border-radius: 10px;
  white-space: nowrap;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.tabs a:hover { color: var(--ink); text-decoration: none; background: var(--surface-2); }
.tabs a.active { background: linear-gradient(160deg, var(--green-mid), var(--green)); color: #fff; box-shadow: var(--shadow-green); }

.profile-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 16px; }
.profile-header h1 { margin: 0 0 4px; font-size: 1.6rem; letter-spacing: -0.03em; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 700px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .layout { flex-direction: column; padding: 10px; gap: 10px; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 12px 14px;
    border-radius: 18px;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
  }
  .sidebar .brand { padding: 0; flex: 1; min-width: 0; }
  .sidebar .brand small { display: none; }
  .sidebar .nav-label {
    display: block;
    padding: 12px 12px 4px;
    font-size: 0.6rem;
  }

  /* Menu button + collapsed menu */
  .nav-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 13px;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 650;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .nav-toggle-btn:hover { background: rgba(255, 255, 255, 0.18); }
  .nav-toggle:focus-visible + .nav-toggle-btn { outline: 2px solid #fff; outline-offset: 2px; }
  .nav-toggle:checked + .nav-toggle-btn { background: var(--lime); color: var(--green-darker); }

  .sidebar nav {
    order: 4;
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 2px;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }
  .nav-toggle:checked ~ nav { display: flex; }
  .sidebar nav a { padding: 11px 14px; font-size: 0.9rem; }

  .sidebar .user-box {
    order: 3;
    margin: 0;
    padding: 6px 8px;
    background: transparent;
    border: none;
  }
  .user-box .user-meta { display: none; }

  .topbar { padding: 8px 6px 14px; }
  .topbar h1 { font-size: 1.45rem; }
  .content { padding: 0 0 44px; }
  .form-row { grid-template-columns: 1fr; }
  .card { padding: 18px; }
  .filters { padding: 14px; gap: 10px; }
  .filters .field { min-width: 0; flex: 1 1 140px; }
  .section-title h2 { font-size: 1rem; }
}

@media (max-width: 520px) {
  .layout { padding: 8px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .stat-card { padding: 15px 14px; border-radius: 15px; }
  .stat-card .value { font-size: 1.45rem; }
  .stat-card .label { font-size: 0.65rem; letter-spacing: 0.07em; }
  .stat-card .sub { font-size: 0.72rem; }
  /* The lead tile carries the headline figure, so give it the full width */
  .stat-card:first-child,
  .stat-card.owing,
  .stat-card.clear { grid-column: 1 / -1; }
  .stat-card:first-child .value,
  .stat-card.owing .value,
  .stat-card.clear .value { font-size: 1.8rem; }

  .card { padding: 15px; border-radius: 15px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .topbar > div:last-child:not(:first-child) { width: 100%; }
  .topbar > div:last-child:not(:first-child) .btn { flex: 1; justify-content: center; }
  .topbar h1 { font-size: 1.3rem; }
  .section-title { gap: 8px; }
  table { font-size: 0.82rem; }
  th, td { padding: 10px 9px; }
  th { font-size: 0.62rem; letter-spacing: 0.06em; }
  .tabs a { padding: 8px 13px; font-size: 0.81rem; }
  .form-actions .btn { flex: 1; justify-content: center; }
  .login-card { padding: 28px 22px 26px; border-radius: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .stat-card:hover, .btn:active { transform: none; }
}

@media print {
  .app-foot { border: none; color: #666; }
  .sidebar, .topbar > div:last-child:not(:first-child), .btn, .filters, .tabs { display: none !important; }
  .layout { padding: 0; }
  .card, .stat-card { box-shadow: none; }
  body { background: #fff; }

  /* Print the page as a plain document: no page background, no tinted
     panels, black text throughout, and no table row split over two sheets.
     Written for the treasurer's report, but it suits every screen. */
  @page { margin: 14mm; }
  html, body, .layout, .main, .content, .card, .stat-card, .table-wrap,
  table, tr, th, td, .badge {
    background: #fff !important;
    background-image: none !important;
    color: #000 !important;
    print-color-adjust: economy;
    -webkit-print-color-adjust: economy;
  }
  .stat-card::after, .stat-card:first-child::after { display: none !important; }
  .stat-card .label, .stat-card .value, .stat-card .sub,
  .text-muted, .amount-owed, .empty-state, .app-foot { color: #000 !important; }
  .card, .stat-card { border: 1px solid #999; }
  .badge { border: 1px solid #999; }
  a { color: #000 !important; text-decoration: none; }
  .table-wrap { overflow: visible !important; }
  tr { page-break-inside: avoid; break-inside: avoid; }
  th { color: #000 !important; }
  tr.is-owed td:first-child { box-shadow: none; }
  tr.total-row td { border-top: 1px solid #000; }
  .section-title h2 { color: #000 !important; }
  .topbar { padding-left: 0; padding-right: 0; }
}
