/* Baseline styles. No framework: system fonts, a handful of custom properties, light and dark. */
:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5b6676;
  --border: #d9dee6;
  --accent: #1f5fbf;
  --ok: #1a7f4b;
  --bad: #b3261e;
  --radius: 8px;

  /* School branding. These defaults are the built-in look. A school that has chosen colors gets
     a second stylesheet, /branding/theme.css, which sets these same names (and --accent) to
     values worked out from its three colors. The page colors above are repeated in
     Branding/BrandColor.swift (PagePalette), which checks contrast against them: change both. */
  --bar: var(--surface);
  --on-bar: var(--text);
  --bar-link: var(--accent);
  --bar-muted: var(--muted);
  --bar-stripe: 1px solid var(--border);
  --button-fill: var(--accent);
  --button-text: var(--surface);
  --button-edge: var(--accent);
  --highlight: var(--accent);
  --on-highlight: var(--surface);
  --highlight-edge: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181f;
    --surface: #1d232d;
    --text: #e6e9ef;
    --muted: #9aa5b5;
    --border: #2f3846;
    --accent: #7fb0f5;
    --ok: #5fd08f;
    --bad: #ff8a80;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  color: var(--on-bar);
  background: var(--bar);
  border-bottom: var(--bar-stripe);
}

.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; text-decoration: none; color: var(--on-bar); }
.brand-icon { width: 2rem; height: 2rem; object-fit: contain; }
.muted { color: var(--muted); }
.site-header .product, .site-header .muted { color: var(--bar-muted); }
.site-header .product { font-size: 0.875rem; opacity: 0.85; }

main { max-width: 60rem; margin: 0 auto; padding: 1.5rem 1rem; }

h1 { margin: 0 0 0.25rem; font-size: 1.75rem; }
h2 { margin: 0 0 0.75rem; font-size: 1.125rem; }

.card {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0 0 1rem; }
dt { color: var(--muted); }
dd { margin: 0; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

button {
  padding: 0.4rem 0.9rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

/* A link that starts something (sign in with Google) rather than going somewhere. */
a.button, .button-look {
  display: inline-block;
  padding: 0.5rem 1rem;
  color: var(--button-text);
  background: var(--button-fill);
  /* An outline drawn inside the button, so it takes no room. Same color as the button unless
     the school's color is too close to the page's. */
  box-shadow: inset 0 0 0 1px var(--button-edge);
  border-radius: var(--radius);
  font-weight: 600;
  text-decoration: none;
}
a.button:hover { filter: brightness(1.1); }

.notice {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  color: var(--bad);
}

/* htmx's own indicator styles are switched off (they are injected inline, which the CSP blocks). */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

.site-header { align-items: center; }
.site-nav { display: flex; gap: 1rem; }
.site-nav a { color: var(--bar-link); }
.signout { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
/* Narrow screens first: the name beside "Sign out" and the product name are the first to go. */
.signout .muted, .site-header .product { display: none; }
@media (min-width: 40rem) {
  .signout .muted, .site-header .product { display: inline; }
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.4rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
td form { margin: 0; }
ul { margin: 0; padding-left: 1.25rem; }

/* ---- Slice 2D: admin screens, viewers, error pages ---- */

.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.hint { display: block; color: var(--muted); font-size: 0.875rem; font-weight: 400; }

.flash {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--ok);
  border-radius: var(--radius);
  color: var(--ok);
}
/* Stays in view while the page scrolls: the failed click may be well below the top. */
#flash { position: sticky; top: 0.5rem; z-index: 1; }
#flash:empty { display: none; }
#flash .notice { margin-top: 0; background: var(--surface); box-shadow: 0 2px 8px rgb(0 0 0 / 0.15); }

/* The second row of links, under the header, on admin screens. */
.subnav { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; margin: 0.75rem 0 0; }
.subnav a { padding: 0.3rem 0.7rem; border-radius: var(--radius); text-decoration: none; }
.subnav a:hover { background: var(--surface); }
.subnav a[aria-current="page"] { background: var(--button-fill); color: var(--button-text); box-shadow: inset 0 0 0 1px var(--button-edge); font-weight: 600; }
.subnav.tabs { margin-top: 1rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.tile { margin-top: 0; text-decoration: none; color: var(--text); }
.tile:hover { border-color: var(--accent); }
.tile h2 { color: var(--accent); }
.tile p { margin: 0; }

/* Forms: one field per line, label above. */
.stack > * + * { margin-top: 1rem; }
.stack p { margin-bottom: 0; }
.field { display: block; max-width: 32rem; }
.field-label { display: block; margin-bottom: 0.25rem; font-weight: 600; }
input[type="text"], input[type="email"], input[type="date"], select, textarea {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.4rem 0.6rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.875rem; }
.field:has(textarea) { max-width: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input:disabled, select:disabled { color: var(--muted); background: var(--bg); }

.checklist { margin: 1rem 0 0; padding: 0; border: none; }
.checklist legend { padding: 0; margin-bottom: 0.25rem; font-weight: 600; }
.checklist label { display: flex; gap: 0.6rem; align-items: baseline; padding: 0.3rem 0; }
.checklist input { flex: none; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; }
button.primary { color: var(--button-text); background: var(--button-fill); border-color: var(--button-edge); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.primary:hover, button.danger:hover { filter: brightness(1.1); }

details { margin-top: 1rem; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details[open] > summary { margin-bottom: 1rem; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; }
.filters .field { flex: 1 1 12rem; max-width: 20rem; }
.inline-fields { display: flex; flex-wrap: wrap; gap: 1rem; }
.inline-fields .field { flex: 1 1 7rem; max-width: 9rem; }

/* The permissions matrix: one row per rule, a select per action. */
.card:has(> table) { overflow-x: auto; }
main:has(.matrix) { max-width: 84rem; }
.matrix select { min-width: 5.5rem; }
.matrix select[name="scope"] { min-width: 11rem; }
.matrix input[name="notes"] { min-width: 9rem; }
.matrix td { vertical-align: middle; }
.matrix select.state-full { border-color: var(--ok); }
.matrix select.state-none { color: var(--muted); }
.matrix tr.unsaved td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.matrix tr.unsaved button { color: var(--button-text); background: var(--button-fill); border-color: var(--button-edge); }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline; }
.saved { margin-left: 0.5rem; color: var(--ok); font-weight: 600; animation: fade-away 4s forwards; }
@keyframes fade-away { 0%, 60% { opacity: 1; } 100% { opacity: 0; } }

.old { color: var(--muted); text-decoration: line-through; }
.pager { display: flex; gap: 1.5rem; margin: 1rem 0 0; }
.pager:empty { display: none; }

.error-page { max-width: 36rem; margin: 3rem auto; }
.error-page h1 { margin-bottom: 0.75rem; }
.error-page .actions { margin: 1.5rem 0; }
pre { overflow-x: auto; padding: 0.75rem; background: var(--bg); border-radius: var(--radius); font-size: 0.8125rem; white-space: pre-wrap; }

/* ---- Phase 2.5: school branding ---- */

.badge {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  color: var(--on-highlight);
  background: var(--highlight);
  box-shadow: inset 0 0 0 1px var(--highlight-edge);
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
}

.after-form { margin-top: 1rem; }
.advice { margin: 1rem 0 0; padding: 0.6rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted); }

.color-field { display: flex; gap: 0.5rem; align-items: center; }
.color-field input[type="color"] { flex: none; width: 3rem; height: 2.75rem; padding: 0.15rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.color-field input[type="text"] { max-width: 9rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
input[type="file"] { max-width: 100%; font: inherit; }

.icon-current { display: flex; align-items: center; gap: 1rem; }
.icon-current img { flex: none; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius); }

/* The two mock pages on the branding screen. Each box is given a whole set of page and brand
   colors by /admin/branding/preview.css, so one shows light mode and the other dark whatever
   the device itself is set to. */
.preview-pair { margin-top: 1rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem; }
.brand-preview { margin: 0; }
.preview-page { overflow: hidden; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.preview-body { margin: 0.75rem; padding: 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.preview-body p { margin: 0; }
.preview-body p + p { margin-top: 0.75rem; }
.preview-link { text-decoration: underline; }
table.contrast { margin-top: 1rem; font-size: 0.875rem; }


/* Sign-in and the account page are phone screens: buttons a thumb can hit (44px and up). */
button.tall { min-height: 2.75rem; padding: 0.5rem 1.1rem; }
button:disabled { opacity: 0.55; cursor: default; }
.passkey .notice { margin-bottom: 0; }
[hidden] { display: none !important; }
.passkey-list { list-style: none; margin: 0; padding: 0; }
.passkey-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; padding: 0.75rem 0; border-top: 1px solid var(--border); }
.passkey-list li > div { flex: 1 1 14rem; }
.passkey-list form { margin: 0; }


/* ---- Sign in as another user ---- */

/* The bar across every page while an administrator is signed in as someone else. Its colors are
   fixed, not the school's: it has to look like a warning under any branding, light or dark.
   Black on this amber is 11:1. A phone screen (it rides on parents' pages), so it stacks. */
.acting-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin: 0;
  padding: 0.6rem 1rem;
  color: #1c1300;
  background: #ffc940;
  border-bottom: 2px solid #1c1300;
}
.acting-bar p { flex: 1 1 16rem; margin: 0; }
.acting-bar button { flex: none; color: #1c1300; background: #fff8e1; border-color: #1c1300; font-weight: 600; }
