/* Shared layout + component design layer. Linked LAST in every template's <head> (after the
   page's own inline <style>), so these rules win over the per-page defaults at equal
   specificity - which means anything touched here must also carry its own mobile override
   below, since a page's inline @media rule no longer wins by coming later. Colors come from
   the theme variables in static/theme.css. */

:root {
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-soft: #f0f1f4;
  --surface: #ffffff;
  --radius: 12px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 18px rgba(16, 24, 40, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Page shell ---------- */
html, body { height: auto; min-height: 100%; }
body {
  margin: 0; padding: 0 0 48px;
  font-family: var(--font); color: var(--ink-2);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
}
.page {
  width: min(1300px, calc(100% - 48px)); box-sizing: border-box;
  margin: 24px auto 0; padding: 28px 32px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
/* The topbar replaced whatever used to sit above a page's first block, so drop that block's
   top margin instead of leaving an empty band at the top of the card. */
.page > :first-child { margin-top: 0; }
h1 { color: var(--ink); font-size: 1.45rem; font-weight: 650; letter-spacing: -0.015em; }
h2 { color: var(--ink); font-weight: 620; letter-spacing: -0.01em; }

/* Page title row (student/family detail pages, public student/family pages). */
.page-header { display: flex; align-items: center; gap: 12px; margin: 0 0 1.25rem; padding: 0; background: none; }
.page-header h1 { margin: 0; color: var(--ink); text-shadow: none; }

/* ---------- Top bar (templates/admin/topbar.html) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(100deg, var(--c900), var(--c800));
  color: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08), 0 6px 20px rgba(16, 24, 40, 0.12);
}
.topbar-inner {
  width: min(1300px, calc(100% - 48px)); margin: 0 auto;
  display: flex; align-items: center; gap: 24px; min-height: 60px;
}
.topbar a { color: inherit; text-decoration: none; }
.topbar a:hover { text-decoration: none; }
.topbar-brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; font-weight: 650; font-size: 0.98rem; letter-spacing: -0.01em; }
.topbar-logo {
  width: 32px; height: 32px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.14); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.topbar-nav { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.topbar-nav::-webkit-scrollbar { display: none; }
.topbar-link {
  /* Reset browser/page button defaults - a page (e.g. templates/student/view.html) may put
     .topbar-link on a <button> rather than an <a>, and its own generic `button { ... }` rule
     would otherwise show through as a solid pill instead of a plain nav link. */
  display: inline-flex; align-items: center; gap: 7px;
  background: none; border: none; margin: 0; font-family: inherit; cursor: pointer;
  padding: 7px 12px; border-radius: 8px; font-size: 0.9rem; font-weight: 500; white-space: nowrap;
  color: rgba(255, 255, 255, 0.72) !important; transition: background 0.15s, color 0.15s;
}
.topbar-icon { flex-shrink: 0; opacity: 0.8; }
.topbar-link.active .topbar-icon, .topbar-link:hover .topbar-icon { opacity: 1; }
.topbar-link:hover { color: #fff !important; background: rgba(255, 255, 255, 0.08); }
.topbar-link.active { color: #fff !important; background: rgba(255, 255, 255, 0.16); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12); }
.topbar-user { display: flex; align-items: center; gap: 10px; flex-shrink: 0; margin-left: auto; }
.topbar-avatar {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}
.topbar-user-text { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-user-name { font-size: 0.86rem; font-weight: 600; color: #fff; }
.topbar-user-tz { font-size: 0.74rem; color: rgba(255, 255, 255, 0.65); }
.topbar-logout { margin: 0; display: block !important; }
.topbar-logout button {
  width: 34px; height: 34px; padding: 0; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: rgba(255, 255, 255, 0.75); border: 1px solid rgba(255, 255, 255, 0.2);
}
.topbar-logout button:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.topbar-alert { position: relative; }
.topbar-alert[hidden] { display: none; }
.topbar-alert-btn {
  width: 34px; height: 34px; padding: 0; margin: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer;
}
.topbar-alert-btn:hover, .topbar-alert-btn[aria-expanded="true"] { background: rgba(255, 255, 255, 0.12); }
.topbar-alert-panel {
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 60;
  width: min(300px, calc(100vw - 24px)); box-sizing: border-box; padding: 14px 16px;
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.18);
}
.topbar-alert-title { margin: 0 0 4px; font-size: 0.9rem; font-weight: 650; color: var(--ink); }
.topbar-alert-body { margin: 0 0 10px; font-size: 0.83rem; line-height: 1.45; color: var(--muted); }
.topbar-alert-days { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-soft); }
.topbar .topbar-alert-days a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 2px; border-bottom: 1px solid var(--line-soft);
  font-size: 0.86rem; font-weight: 550; color: var(--accent);
}
.topbar .topbar-alert-days li:last-child a { border-bottom: none; padding-bottom: 0; }
.topbar .topbar-alert-days a::after { content: "→"; color: var(--muted); }
.topbar .topbar-alert-days a:hover { color: var(--accent-dark); }

/* ---------- Components ---------- */
a { color: var(--accent); }
table { border-collapse: separate; border-spacing: 0; }
th {
  background: #f9fafb; color: var(--muted);
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--line);
}
th:first-child { border-top-left-radius: 8px; }
th:last-child { border-top-right-radius: 8px; }
td { border-bottom: 1px solid var(--line-soft); }
tbody tr:hover > td { background: #fafafb; }

button { border-radius: 8px; font-weight: 500; transition: background 0.15s, border-color 0.15s, box-shadow 0.15s; }
button.secondary { background: #fff; color: var(--ink-2); border: 1px solid #d1d5db; }
button.secondary:hover { background: #f9fafb; border-color: #c4c8cf; }
input, select, textarea { border-radius: 8px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent-border-mid);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
dialog { border-radius: 14px; box-shadow: 0 24px 60px rgba(16, 24, 40, 0.22); }
dialog::backdrop { background: rgba(17, 24, 39, 0.45); }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  body { padding: 0 0 32px; }
  .page { width: calc(100% - 20px); margin-top: 12px; padding: 18px 14px; border-radius: 10px; }
  h1 { font-size: 1.25rem; }

  .topbar-inner { width: 100%; box-sizing: border-box; padding: 0 12px; flex-wrap: wrap; gap: 0 10px; min-height: 0; }
  .topbar-brand { order: 1; padding: 10px 0; }
  .topbar-user { order: 2; }
  .topbar-user-text { display: none; }
  .topbar-nav { order: 3; flex-basis: 100%; margin: 0 -12px; padding: 0 8px 8px; -webkit-mask-image: linear-gradient(to right, #000 88%, transparent); mask-image: linear-gradient(to right, #000 88%, transparent); }
  .topbar-link { padding: 6px 10px; font-size: 0.85rem; gap: 6px; }
  .topbar-icon { width: 15px; height: 15px; }

  /* Tables collapse into stacked cards on mobile (see each page's inline styles). */
  th:first-child, th:last-child { border-radius: 0; }
  tbody tr:hover > td { background: transparent; }
}
