/* ==========================================================================
   Library — design tokens
   Light palette on :root, dark overrides in one media block so every colour
   has a definition in both themes.
   ========================================================================== */

/*
 * Palette taken from the Sri Sathya Sai International Organisation emblem:
 * blue #004c97 and orange #ea7600, sampled from the artwork itself.
 *
 * Blue carries every interactive element — at 8.47:1 on white it is safe for
 * body text, links and button fills. The orange only reaches 2.96:1, so it is
 * never used for text or as a button background; it appears as the decorative
 * brand rule, and a darkened #9a4f00 stands in wherever orange must be read.
 * Every foreground/background pair in this file is verified against WCAG AA.
 */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --surface-3: #eef1f5;
  --border: #e0e5ec;
  --border-strong: #818b99;

  --text: #1a1e26;
  --text-muted: #5c6470;
  --text-faint: #6a7280;

  --accent: #004c97;
  --accent-hover: #003a78;
  --accent-soft: #e4edf7;
  --accent-text: #ffffff;

  /* Brand orange: decorative fills only — never text, never a button. */
  --brand-orange: #ea7600;
  /* Readable orange, for text that must carry the brand tone. */
  --brand-orange-text: #9a4f00;
  --brand-orange-soft: #fdf0e0;

  --warn: #9a4f00;
  --warn-soft: #fdf0e0;
  --danger: #a8321f;
  --danger-soft: #fbeae6;
  --info: #004c97;
  --info-soft: #e4edf7;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(20, 25, 18, 0.05), 0 4px 14px rgba(20, 25, 18, 0.05);
  --shadow-lg: 0 2px 6px rgba(20, 25, 18, 0.07), 0 16px 40px rgba(20, 25, 18, 0.09);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --maxw: 1120px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --surface: #161b23;
    --surface-2: #1b212a;
    --surface-3: #232b36;
    --border: #2a323d;
    --border-strong: #5f6a79;

    --text: #e6eaf0;
    --text-muted: #9fa9b8;
    --text-faint: #8b95a4;

    /* The brand colours lightened for a dark ground, same hues. */
    --accent: #7fb2ea;
    --accent-hover: #9cc5f2;
    --accent-soft: #152538;
    --accent-text: #08121f;

    --brand-orange: #f59637;
    --brand-orange-text: #f0a45a;
    --brand-orange-soft: #2e2011;

    --warn: #f0a45a;
    --warn-soft: #2e2011;
    --danger: #ef8f79;
    --danger-soft: #3a1d16;
    --info: #7fb2ea;
    --info-soft: #152538;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.35), 0 16px 40px rgba(0, 0, 0, 0.4);
  }
}

/* ==========================================================================
   Base
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.4em;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 1.7rem;
}
h2 {
  font-size: 1.2rem;
}
h3 {
  font-size: 1rem;
}

p {
  margin: 0 0 1em;
}

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

a:hover {
  text-decoration: underline;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

code,
kbd {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-3);
  padding: 0.12em 0.4em;
  border-radius: 4px;
}

/* Visible focus for keyboard users, everywhere. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

main {
  flex: 1;
  padding: 28px 0 64px;
}

.site-header {
  background: var(--surface);
  /* Decorative brand stripe — carries no information on its own. */
  border-top: 3px solid var(--brand-orange);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 60px;
  flex-wrap: wrap;
  /* Anchor for the mobile dropdown menu. */
  position: relative;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  flex-shrink: 0;
  min-width: 0;
}

.brand:hover {
  text-decoration: none;
}

.brand:hover .brand-org {
  color: var(--accent);
}

.brand-mark {
  width: 34px;
  height: 34px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-org {
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-sub {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-orange-text);
  white-space: nowrap;
}

/*
 * One awkward band: 781–900px. The navigation is still a horizontal row of
 * links (the hamburger only appears at 780px and below) and an admin has eight
 * of them, so the centre's full name would push the row onto a second line.
 * Drop it here and promote the short label instead.
 *
 * Below 780px the nav collapses behind the toggle, the space comes back, and
 * the full name returns — see the phone block further down.
 */
@media (min-width: 781px) and (max-width: 900px) {
  .brand-org {
    display: none;
  }
  .brand-sub {
    font-size: 0.85rem;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text);
    font-weight: 700;
  }
}

.nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  flex-wrap: wrap;
}

.nav a {
  color: var(--text-muted);
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.925rem;
  white-space: nowrap;
}

.nav a:hover {
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}

.nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-account {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.nav-account-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

.nav-account-link:hover {
  text-decoration: none;
  color: var(--text);
}

/* The member's name only has room once the menu is stacked. */
.nav-account-name {
  display: none;
  font-weight: 600;
  font-size: 0.95rem;
}

/* --- Hamburger ------------------------------------------------------------ */

.nav-toggle {
  display: none;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  min-height: 44px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  cursor: pointer;
}

.nav-toggle:hover {
  background: var(--surface-3);
}

.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  content: "";
}

.nav-toggle-bars {
  position: relative;
}

.nav-toggle-bars::before {
  position: absolute;
  top: -6px;
}

.nav-toggle-bars::after {
  position: absolute;
  top: 6px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-3);
}

.avatar-fallback {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  color: var(--text-faint);
  font-size: 0.85rem;
  background: var(--surface);
}

.site-footer .wrap {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-copy a,
.footer-meta a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer-copy a:hover,
.footer-meta a:hover {
  color: var(--accent);
}

/*
 * Honeypot. Kept out of the layout without `display:none`, which some bots
 * check for. `aria-hidden` and tabindex="-1" keep it away from real users and
 * assistive tech.
 */
.honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Truncate long contact-form messages in the admin table. */
.clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  font-size: 0.88rem;
  line-height: 1.45;
}

/* ==========================================================================
   Page header
   ========================================================================== */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.page-head h1 {
  margin: 0;
}

.page-head .sub {
  color: var(--text-muted);
  margin: 4px 0 0;
  font-size: 0.95rem;
}

.page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ==========================================================================
   Cards / panels
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad {
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.card-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
}

.section {
  margin-bottom: 28px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .split {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Stat tiles — the "Currently Out" dashboard
   ========================================================================== */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
}

.stat .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 650;
  margin-bottom: 6px;
}

.stat .value {
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat.is-alert .value {
  color: var(--danger);
}

.stat.is-good .value {
  color: var(--accent);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 0.925rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
  color: var(--accent-text);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--surface-3);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-3);
  color: var(--text);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--border-strong);
}

.btn-danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-sm {
  padding: 5px 11px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
}

.btn-google {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-google:hover {
  background: var(--surface-3);
  color: var(--text);
}

.btn-google svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

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

.inline-form {
  display: inline;
}

/* ==========================================================================
   Forms
   ========================================================================== */

.field {
  margin-bottom: 15px;
}

.field label,
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  min-height: 78px;
  resize: vertical;
}

select {
  cursor: pointer;
}

.field .hint {
  font-size: 0.8rem;
  color: var(--text-faint);
  margin-top: 4px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 15px;
}

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 0.92rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox input {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.checkbox span {
  font-weight: 500;
}

/* ==========================================================================
   Search bar
   ========================================================================== */

.searchbar {
  display: grid;
  grid-template-columns: minmax(200px, 2.2fr) repeat(3, minmax(120px, 1fr)) auto;
  gap: 9px;
  align-items: end;
}

/* Search-bar reflow lives in the consolidated phone block near the end. */

/* ==========================================================================
   Tables
   ========================================================================== */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

thead th {
  text-align: left;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface-2);
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: var(--surface-2);
}

td .muted,
.muted {
  color: var(--text-muted);
}

.faint {
  color: var(--text-faint);
}

.nowrap {
  white-space: nowrap;
}

.num {
  font-variant-numeric: tabular-nums;
}

.right {
  text-align: right;
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-muted);
}

.badge-out {
  background: var(--info-soft);
  color: var(--info);
}

.badge-overdue {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-returned {
  background: var(--surface-3);
  color: var(--text-muted);
}

.badge-available {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-none {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-admin {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-due-soon {
  background: var(--warn-soft);
  color: var(--warn);
}

.ref {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-faint);
}

/* ==========================================================================
   Book cards
   ========================================================================== */

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.book-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.book-card .top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.book-card h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
}

.book-card h3 a {
  color: var(--text);
}

.book-card .author {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 2px 0 0;
}

.book-card .meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--text-faint);
  margin-top: auto;
  padding-top: 4px;
}

.book-card .copies {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.book-card .copies strong {
  color: var(--text);
}

/* ==========================================================================
   Book images
   ========================================================================== */

/*
 * Book covers are portrait (roughly 2:3), but a library also collects
 * landscape shots of spines and shelves. `contain` inside a portrait-leaning
 * box shows every image whole — a `cover` crop would slice the top and bottom
 * off a standard cover and hide the title.
 */
.book-cover {
  display: block;
  position: relative;
  margin: -16px -16px 2px;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  background: var(--surface-3);
  aspect-ratio: 3 / 4;
  padding: 8px;
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.book-cover:hover img {
  opacity: 0.92;
}

.cover-count {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(12, 16, 10, 0.72);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 650;
  padding: 2px 8px;
  border-radius: 999px;
  backdrop-filter: blur(2px);
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.image-grid-lg {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.image-tile {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}

.image-tile img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  display: block;
  padding: 6px;
  background: var(--surface-3);
}

.image-grid-lg .image-tile img {
  aspect-ratio: 3 / 4;
  padding: 10px;
}

.image-tile figcaption {
  padding: 7px 9px;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

input[type="file"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

input[type="file"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="file"]::file-selector-button {
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  margin-right: 10px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: var(--surface-3);
}

/* ==========================================================================
   Flash messages
   ========================================================================== */

.flashes {
  margin-bottom: 18px;
  display: grid;
  gap: 8px;
}

.flash {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.92rem;
  display: flex;
  gap: 9px;
  align-items: flex-start;
}

.flash-success {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.flash-error {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.flash-info {
  background: var(--info-soft);
  border-color: var(--info);
  color: var(--info);
}

.flash-warning {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}

.alert {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  margin-bottom: 15px;
}

.notice {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn);
  margin-bottom: 15px;
}

/* ==========================================================================
   Auth pages
   ========================================================================== */

.auth-wrap {
  max-width: 400px;
  margin: 40px auto;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-lg);
}

.auth-card h1 {
  font-size: 1.4rem;
  margin-bottom: 4px;
}

.auth-card .sub {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 22px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-faint);
  font-size: 0.8rem;
  margin: 18px 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-alt {
  text-align: center;
  margin-top: 18px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Empty states, pagination, misc
   ========================================================================== */

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

.empty .icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 10px;
  opacity: 0.6;
}

.empty h3 {
  color: var(--text);
  margin-bottom: 6px;
}

.empty p {
  margin: 0 auto 14px;
  max-width: 380px;
  font-size: 0.92rem;
}

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

.pagination a,
.pagination span {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text-muted);
  background: var(--surface);
}

.pagination a:hover {
  background: var(--surface-3);
  text-decoration: none;
  color: var(--text);
}

.pagination .current {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 650;
}

.pagination .disabled {
  opacity: 0.45;
}

.chips {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.chip {
  padding: 5px 13px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-size: 0.86rem;
  color: var(--text-muted);
  background: var(--surface);
  font-weight: 550;
}

.chip:hover {
  text-decoration: none;
  background: var(--surface-3);
  color: var(--text);
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 18px;
  font-size: 0.92rem;
  margin: 0;
}

.dl dt {
  color: var(--text-faint);
  font-weight: 600;
}

.dl dd {
  margin: 0;
  font-weight: 550;
}

.list-plain {
  list-style: none;
  padding: 0;
  margin: 0;
}

.list-plain li {
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.list-plain li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.hero {
  text-align: center;
  padding: 42px 20px 34px;
}

.hero h1 {
  font-size: 2.1rem;
  margin-bottom: 10px;
}

.hero p {
  color: var(--text-muted);
  font-size: 1.02rem;
  max-width: 520px;
  margin: 0 auto 22px;
}

/* --- Centre branding on the home page ------------------------------------ */

.portal-hero {
  padding-top: 30px;
}

.portal-emblem {
  width: 118px;
  height: auto;
  display: block;
  margin: 0 auto 16px;
}

.portal-org {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--brand-orange-text);
  margin: 0 0 2px;
  max-width: none;
}

/* Short brand rule under the hero heading, echoing the header stripe. */
.portal-hero h1::after {
  content: "";
  display: block;
  width: 64px;
  height: 3px;
  border-radius: 2px;
  background: var(--brand-orange);
  margin: 14px auto 0;
}

.hero h1 {
  margin-bottom: 12px;
}

/*
 * The portrait sits beside the text at its own aspect ratio — never cropped,
 * never used as a backdrop with text laid over it.
 */
.portal-welcome {
  display: grid;
  grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}

.portal-portrait {
  margin: 0;
}

.portal-portrait img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

@media (max-width: 720px) {
  .portal-welcome {
    grid-template-columns: 1fr;
  }
  .portal-portrait {
    max-width: 340px;
    margin: 0 auto;
  }
}

.feature-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.feature-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 0.93rem;
  color: var(--text-muted);
}

.feature-list .tick {
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

/* ==========================================================================
   Phones and small tablets
   ========================================================================== */

@media (max-width: 780px) {
  /* --- Brand ---------------------------------------------------------------
   * With the links behind the toggle there is room for the centre's name
   * again. It is too long for one line on a phone, so let it wrap rather than
   * truncating or hiding it — the header grows by a line and stays legible.
   */
  .brand-org {
    display: block;
    white-space: normal;
    font-size: 0.82rem;
    line-height: 1.2;
  }

  .brand-sub {
    font-size: 0.66rem;
  }

  .brand {
    flex: 1 1 auto;
    min-width: 0;
    padding: 6px 0;
  }

  /* --- Collapsible menu --------------------------------------------------- */
  .nav-toggle:not([hidden]) {
    display: inline-flex;
  }

  /* Icon only — the word "Menu" costs ~45px that the brand name needs. The
     button keeps its accessible name from aria-label. */
  .nav-toggle-text {
    display: none;
  }

  .nav-toggle {
    min-width: 44px;
    padding: 0 12px;
    flex-shrink: 0;
  }

  .site-header[data-nav="collapsed"] .nav {
    display: none;
  }

  /*
   * The open menu is a dropdown panel, not another flex row.
   *
   * As an in-flow flex item it inherited `flex: 1` from the base rule, whose
   * `flex-basis: 0` overrides `width: 100%` — so it stayed on the header's
   * first line and got squeezed to nothing beside the brand. Taking it out of
   * flow removes that whole class of problem: no sibling can compress it, and
   * the header keeps a constant height whether the menu is open or shut.
   */
  .site-header[data-nav="open"] .nav {
    display: flex;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 30;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 8px 20px 14px;
    max-height: calc(100vh - 72px);
    overflow-y: auto;
  }

  .nav {
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    width: auto;
    gap: 2px;
    padding: 6px 0 12px;
  }

  .nav a {
    /* Comfortable, unambiguous tap targets in the stacked menu. */
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 10px 12px;
    font-size: 1rem;
  }

  .nav-account {
    margin: 8px 0 0;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
  }

  .nav-account-link {
    min-height: 44px;
    padding: 0 4px;
  }

  .nav-account-name {
    display: inline;
  }

  /* --- Touch targets ------------------------------------------------------ */
  .btn {
    min-height: 44px;
    padding: 10px 18px;
  }

  .btn-sm {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 0.9rem;
  }

  /*
   * 16px is the threshold below which iOS Safari zooms the page when a field
   * receives focus, leaving the user scrolled sideways. Everything that can be
   * typed into has to clear it.
   */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="date"],
  input[type="search"],
  input[type="file"],
  select,
  textarea {
    font-size: 16px;
    padding: 11px 12px;
  }

  .checkbox input {
    width: 20px;
    height: 20px;
  }

  /* --- Tables become stacked cards --------------------------------------- */
  /*
   * Only once JS has copied the column headings onto each cell — without that
   * the labels would be missing, so the table stays scrollable instead.
   */
  .table-scroll table.table-labelled thead {
    display: none;
  }

  .table-scroll table.table-labelled,
  .table-scroll table.table-labelled tbody,
  .table-scroll table.table-labelled tr,
  .table-scroll table.table-labelled td {
    display: block;
    width: 100%;
  }

  .table-scroll table.table-labelled tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin: 0 0 10px;
    padding: 6px 12px;
    background: var(--surface);
  }

  .table-scroll table.table-labelled tr:hover {
    background: var(--surface);
  }

  .table-scroll table.table-labelled td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    text-align: left;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
  }

  .table-scroll table.table-labelled td:last-child {
    border-bottom: 0;
  }

  /* Cells under a blank heading (action buttons) get no label and full width. */
  .table-scroll table.table-labelled td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 38%;
    color: var(--text-faint);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .table-scroll table.table-labelled td:not([data-label]) {
    justify-content: flex-end;
  }

  .table-scroll table.table-labelled td.right {
    text-align: right;
  }

  /* Give the action buttons room to breathe once stacked. */
  .table-scroll table.table-labelled .btn-row {
    justify-content: flex-end;
  }

  /* --- Search bar --------------------------------------------------------- */
  .searchbar {
    grid-template-columns: 1fr 1fr;
  }

  .searchbar .search-q,
  .searchbar .search-go {
    grid-column: 1 / -1;
  }

  /* --- Odds and ends ------------------------------------------------------ */
  .page-head {
    align-items: flex-start;
  }

  h1 {
    font-size: 1.45rem;
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .stat .value {
    font-size: 1.55rem;
  }

  .card-pad {
    padding: 16px;
  }
}

@media (max-width: 420px) {
  .wrap {
    padding: 0 14px;
  }

  .searchbar {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Stop a lone button sitting awkwardly beside a wrapped heading. */
  .page-actions .btn {
    flex: 1 1 auto;
  }

  .table-scroll table.table-labelled td[data-label]::before {
    flex-basis: 45%;
  }
}

@media print {
  .site-header,
  .site-footer,
  .page-actions,
  .nav-toggle,
  .btn {
    display: none !important;
  }
}
