/* Design tokens: the five core colors. Everything else derives from these or neutral opacity. */
:root {
  --white: #FFFFFF;
  --violet: #6D28D9;
  --red: #DC2626;
  --blue: #2563EB;
  --green: #16A34A;

  --ink: rgb(0 0 0 / 0.87);
  --ink-muted: rgb(0 0 0 / 0.6);
  --line: rgb(0 0 0 / 0.12);
  --tint: rgb(0 0 0 / 0.03);
  --violet-tint: color-mix(in srgb, var(--violet) 8%, var(--white));
  --blue-tint: color-mix(in srgb, var(--blue) 8%, var(--white));
  --red-tint: color-mix(in srgb, var(--red) 8%, var(--white));
  --green-tint: color-mix(in srgb, var(--green) 10%, var(--white));

  --radius: 6px;
  --sidebar: 232px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--white); color: var(--ink); font: 14.5px/1.5 var(--font); }
h1 { font-size: 1.35rem; line-height: 1.25; margin: 0; overflow-wrap: anywhere; }
h2 { font-size: 1.02rem; margin: 0 0 .7rem; }
h3 { font-size: .95rem; margin: 0 0 .4rem; }
p { margin: 0 0 1rem; }
a { color: var(--blue); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--white); color: var(--violet); padding: .5rem 1rem; z-index: 20; }
.skip-link:focus { left: 1rem; top: .5rem; }
.muted { color: var(--ink-muted); }
.nowrap { white-space: nowrap; }

/* ---- Portal shell: sidebar + main ---- */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--violet); color: var(--white); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar :focus-visible { outline-color: var(--white); }
.identity { display: flex; align-items: center; gap: .6rem; color: var(--white); text-decoration: none; padding: .25rem .5rem 1rem; border-bottom: 1px solid rgb(255 255 255 / 0.2); margin-bottom: .75rem; }
.crest { width: 34px; height: 34px; border-radius: 8px; background: var(--white); color: var(--violet); display: grid; place-items: center; font-weight: 800; font-size: 1rem; flex: none; }
.identity strong { display: block; font-size: .95rem; line-height: 1.2; }
.identity span { font-size: .75rem; opacity: .85; }
.nav-group { margin-bottom: .9rem; }
.nav-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; opacity: .75; padding: 0 .6rem .3rem; }
.nav a { display: block; color: var(--white); text-decoration: none; padding: .42rem .6rem; border-radius: var(--radius); font-size: .92rem; }
.nav a:hover { background: rgb(255 255 255 / 0.12); }
.nav a[aria-current="page"] { background: var(--white); color: var(--violet); font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--white); position: sticky; top: 0; z-index: 5; }
.crumb { font-size: .82rem; color: var(--ink-muted); }
.crumb strong { color: var(--ink); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.bell { display: inline-flex; align-items: center; gap: .35rem; padding: .35rem .6rem; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; font-size: .85rem; }
.bell:hover { background: var(--tint); }
.bell .count { background: var(--violet); color: var(--white); border-radius: 999px; font-size: .72rem; font-weight: 700; padding: 0 .4rem; min-width: 1.3rem; text-align: center; }
.account { position: relative; }
.account summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem; padding: .25rem .5rem; border-radius: var(--radius); border: 1px solid transparent; }
.account summary::-webkit-details-marker { display: none; }
.account summary:hover, .account[open] summary { border-color: var(--line); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--violet-tint); color: var(--violet); display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.account .who { font-size: .85rem; line-height: 1.2; text-align: left; }
.account .who small { display: block; color: var(--ink-muted); text-transform: capitalize; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); min-width: 220px; padding: .4rem; box-shadow: 0 6px 20px rgb(0 0 0 / 0.08); }
.menu .email { font-size: .8rem; color: var(--ink-muted); padding: .3rem .5rem .5rem; border-bottom: 1px solid var(--line); margin-bottom: .3rem; overflow-wrap: anywhere; }
.menu a, .menu button { display: block; width: 100%; text-align: left; padding: .4rem .5rem; border-radius: 4px; color: var(--ink); text-decoration: none; font: inherit; font-size: .9rem; background: none; border: 0; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--tint); }
.menu form { margin: 0; }
.menu .signout { color: var(--red); }

.content { padding: 1.25rem 1.5rem 2.5rem; max-width: 1180px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.page-head p { margin: .2rem 0 0; color: var(--ink-muted); }
.page-head > div { min-width: 0; }
.section { margin-bottom: 1.6rem; min-width: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .6rem; }
.section-head h2 { margin: 0; }
.grid-2 { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid-even { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-2 > *, .grid-even > * { min-width: 0; }

/* Key facts strip */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 1.5rem; padding: 0; list-style: none; }
.facts li { padding: .7rem 1rem; border-right: 1px solid var(--line); }
.facts li:last-child { border-right: 0; }
.facts span { display: block; font-size: .72rem; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .04em; }
.facts strong { display: block; font-size: 1.12rem; color: var(--violet); margin-top: .1rem; }
.facts strong.na { color: var(--ink-muted); font-size: .92rem; font-weight: 600; }
.facts .warn strong { color: var(--red); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 600; font-size: .8rem; color: var(--ink-muted); background: var(--tint); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--tint); }
tfoot td { font-weight: 600; background: var(--tint); border-top: 1px solid var(--line); border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.details { max-width: 26rem; overflow-wrap: anywhere; }
td code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .82rem; }
.empty { padding: 1.25rem; text-align: center; color: var(--ink-muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); }
.list li { padding: .65rem .85rem; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .meta { font-size: .8rem; color: var(--ink-muted); }
.announcement h3 { margin-bottom: .15rem; }
.announcement p { margin: .35rem 0 0; white-space: pre-line; }

/* Timetable */
.timetable { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.day { border: 1px solid var(--line); border-radius: var(--radius); min-height: 6rem; }
.day h3 { margin: 0; padding: .45rem .7rem; background: var(--violet-tint); color: var(--violet); border-bottom: 1px solid var(--line); font-size: .85rem; }
.slot { padding: .5rem .7rem; border-bottom: 1px solid var(--line); font-size: .85rem; }
.slot:last-child { border-bottom: 0; }
.slot .time { font-weight: 700; font-variant-numeric: tabular-nums; }
.slot .where { color: var(--ink-muted); font-size: .8rem; }
.day .none { padding: .6rem .7rem; color: var(--ink-muted); font-size: .82rem; }

/* Forms */
.form { max-width: 560px; }
.form-wide { max-width: 820px; }
.field { margin-bottom: .9rem; }
.field-row { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
label { display: block; font-weight: 600; margin-bottom: .25rem; font-size: .88rem; }
.hint { font-size: .8rem; color: var(--ink-muted); margin-top: .2rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem .2rem; margin: 0 0 1rem; min-width: 0; }
legend { font-size: .82rem; font-weight: 600; padding: 0 .3rem; color: var(--ink-muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="tel"], input[type="date"],
input[type="datetime-local"], input[type="time"], input[type="search"], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--white);
  border: 1px solid rgb(0 0 0 / 0.3); border-radius: var(--radius); padding: .45rem .6rem;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
input[readonly] { background: var(--tint); }
textarea { min-height: 6rem; resize: vertical; }
.checkbox { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.checkbox input { width: 1.05rem; height: 1.05rem; }
[aria-invalid="true"] { border-color: var(--red) !important; }
.field-error { color: var(--red); font-size: .82rem; margin-top: .2rem; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form input[type="number"] { width: 6.5rem; }
.inline-form select, .inline-form input[type="text"], .inline-form input[type="search"] { width: auto; min-width: 11rem; }
.inline-form input[type="date"], .inline-form input[type="time"] { width: auto; }
.inline-form label { margin: 0; }
.filters { padding: .75rem; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; gap: .75rem; }
.table-wrap + .inline-form, .list + .inline-form, .table-wrap + form { margin-top: .75rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .88rem; line-height: 1.2;
  padding: .45rem .85rem; border-radius: var(--radius); border: 1px solid var(--blue);
  background: var(--white); color: var(--blue); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--blue-tint); }
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: color-mix(in srgb, var(--blue) 88%, black); }
.btn-danger { color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red-tint); }
.btn-success { background: var(--green); border-color: var(--green); color: var(--white); }
.btn-success:hover { background: color-mix(in srgb, var(--green) 85%, black); }
.btn-sm { padding: .25rem .55rem; font-size: .8rem; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Alerts */
.alert { border: 1px solid var(--line); border-left-width: 4px; border-radius: var(--radius); padding: .6rem .9rem; margin: 0 0 1rem; }
.alert-success { border-color: var(--green); background: var(--green-tint); }
.alert-error { border-color: var(--red); background: var(--red-tint); }
.alert-info { border-color: var(--blue); background: var(--blue-tint); }
.alert > strong:first-child { margin-right: .3rem; }
.alert-success strong { color: var(--green); }
.alert-error strong { color: var(--red); }

/* Badges */
.badge { display: inline-block; font-size: .74rem; font-weight: 600; padding: .05rem .5rem; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.badge-role { color: var(--violet); background: var(--violet-tint); text-transform: capitalize; }
.badge-success, .badge-open { color: var(--ink); border-color: var(--green); background: var(--green-tint); }
.badge-failure, .badge-denied, .badge-inactive, .badge-closed { color: var(--red); background: var(--red-tint); }
.badge-pending, .badge-dropped { color: var(--ink-muted); border-color: var(--line); }
.badge-info { color: var(--blue); background: var(--blue-tint); }

dl.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.5rem; margin: 0; }
dl.details dt { color: var(--ink-muted); }
dl.details dd { margin: 0; }

.danger-zone { border: 1px solid var(--red); border-radius: var(--radius); padding: 1rem; }
.danger-zone h2 { color: var(--red); }
.pagination { display: flex; justify-content: space-between; margin-top: 1rem; }

/* ---- Sign-in pages ---- */
.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.auth-brand { background: var(--violet); color: var(--white); padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; }
.auth-brand .crest { width: 44px; height: 44px; font-size: 1.25rem; }
.auth-brand h1 { font-size: 1.6rem; margin: 1.25rem 0 .5rem; }
.auth-brand p { opacity: .9; max-width: 28rem; }
.auth-brand small { opacity: .8; }
.auth-main { display: flex; flex-direction: column; justify-content: center; }
.auth { width: 100%; max-width: 400px; margin: 0 auto; padding: 2rem 16px; }
.auth h2 { font-size: 1.3rem; margin-bottom: 1rem; }
.auth .btn-primary { width: 100%; padding: .6rem; }
.auth .switch { margin-top: 1.25rem; text-align: center; }

@media (max-width: 960px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: .6rem 16px; }
  .identity { border: 0; margin: 0; padding: .25rem 0 .5rem; }
  .nav { display: flex; flex-wrap: wrap; gap: .25rem; }
  .nav-group { display: contents; }
  .nav-label { display: none; }
  .topbar { padding: .5rem 16px; position: static; }
  .account .who { display: none; }
  .content { padding: 1rem 16px 2rem; }
  .facts li { border-right: 0; border-bottom: 1px solid var(--line); }
  dl.details { grid-template-columns: 1fr; gap: 0; }
  dl.details dd { margin-bottom: .5rem; }
  .inline-form select, .inline-form input[type="text"], .inline-form input[type="search"] { min-width: 0; flex: 1 1 10rem; }
  .auth-page { grid-template-columns: 1fr; }
  .auth-brand { padding: 1.25rem 16px; }
  .auth-brand p, .auth-brand small { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
