/**
 * Admin interface styles.
 *
 * Adapted from the plugin's design system (sbst-base, sbst-themes, sbst-modals) — the spacing scale,
 * colour choices and modal behaviour carry over. What has gone is sbst-overlay.css, which existed only
 * to hide WordPress admin chrome, and the per-screen files, which fought each other through unscoped
 * selectors.
 *
 * Everything is expressed against custom properties, and dark mode redefines only those.
 */

:root {
    --ink: #1f2430;
    --ink-soft: #5a6272;
    --ink-faint: #8b93a3;
    --line: #dfe3ea;
    --line-soft: #edf0f5;
    --surface: #ffffff;
    --surface-alt: #f6f8fb;
    --surface-sunk: #eef1f6;
    --accent: #6b3fa0;
    --accent-ink: #ffffff;
    --accent-soft: #f2ecfa;
    --ok: #1d7a37;
    --ok-soft: #e8f5ec;
    --warn: #8a6100;
    --warn-soft: #fdf4e0;
    --bad: #b32d2e;
    --bad-soft: #fdf2f2;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
    --sidebar-width: 15rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --ink: #e8eaee;
        --ink-soft: #9aa3b2;
        --ink-faint: #6f7787;
        --line: #333a48;
        --line-soft: #262d39;
        --surface: #1a1f28;
        --surface-alt: #131720;
        --surface-sunk: #0f131a;
        --accent: #a583d4;
        --accent-ink: #16121d;
        --accent-soft: #241d33;
        --ok: #4ec26f;
        --ok-soft: #14251a;
        --warn: #e0b040;
        --warn-soft: #2a2213;
        --bad: #f08b8b;
        --bad-soft: #2b1717;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--surface-alt);
    -webkit-font-smoothing: antialiased;
}

body.modal-open { overflow: hidden; }

h1 { font-size: 1.5rem; margin: 0 0 1.25rem; }
h2 { font-size: 1.0625rem; margin: 0 0 .875rem; }

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

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .875em;
    background: var(--surface-sunk);
    border-radius: 4px;
    padding: .1rem .35rem;
}

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

.muted { color: var(--ink-soft); }
.muted-sm { display: block; color: var(--ink-soft); font-size: .8125rem; }
.lede { color: var(--ink-soft); margin: -.75rem 0 1.5rem; }
.align-right { text-align: right; }
.req { color: var(--bad); }

/* ------------------------------------------------------------------ loading */

.boot, .loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
    padding: 3rem 1rem;
    color: var(--ink-soft);
}

.spinner {
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 2.4s; }
    * { transition-duration: 0s !important; }
}

/* ------------------------------------------------- centered pages (auth) */

.centered-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem 1rem;
}

.centered-card {
    width: 100%;
    max-width: 24rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.75rem;
}

.centered-card.is-wide { max-width: 40rem; }

.brand { text-align: center; margin-bottom: 1.5rem; }
.brand h1 { font-size: 1.25rem; margin: 0 0 .25rem; }

/* -------------------------------------------------------------------- shell */

.shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 1.25rem .75rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    padding: 0 .5rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .1rem;
}

.sidebar-foot {
    margin-top: auto;
    padding-top: .75rem;
    border-top: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

.content {
    padding: 2rem;
    min-width: 0;
    max-width: 78rem;
}

/* Sidebar becomes a horizontal strip on narrow screens rather than disappearing behind a
   hamburger — there are few enough items that scrolling them is fine. */
@media (max-width: 52rem) {
    .shell { grid-template-columns: 1fr; }

    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .nav { flex-direction: row; overflow-x: auto; padding-bottom: .25rem; }
    .nav-link { white-space: nowrap; }
    .sidebar-foot { flex-direction: row; align-items: center; justify-content: space-between; }
    .content { padding: 1.25rem 1rem; }
}

/* ---------------------------------------------------------------------- nav */

.nav {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .1rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 100%;
    padding: .5rem .6rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    font: inherit;
    text-align: left;
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
}

.nav-link:hover { background: var(--surface-alt); }

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

.nav-link.is-quiet { color: var(--ink-soft); font-size: .9375rem; }

/* Not-yet-built screens are visible but plainly inert, so the shape of the system is legible. */
.nav-link.is-pending {
    color: var(--ink-faint);
    cursor: default;
    justify-content: space-between;
}

.nav-link.is-pending:hover { background: none; }

.nav-tag {
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    background: var(--surface-sunk);
    color: var(--ink-faint);
    padding: .1rem .35rem;
    border-radius: 3px;
}

.nav-name { display: block; font-weight: 600; color: var(--ink); }

.avatar {
    flex: 0 0 auto;
    width: 1.9rem;
    height: 1.9rem;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: .75rem;
    font-weight: 700;
}

/* -------------------------------------------------------------------- panel */

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.panel.is-attention { border-left: 3px solid var(--warn); }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.page-head h1 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.grid-2.is-wide-gap { gap: 1.25rem; }

@media (min-width: 44rem) {
    .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* -------------------------------------------------------------------- stats */

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

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

.stat-label { font-size: .8125rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 1.625rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-sub { font-size: .8125rem; color: var(--ink-soft); }

.inline-stats { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

.attention-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .75rem; }
.attention-list li { display: flex; flex-direction: column; gap: .1rem; }

/* ------------------------------------------------------------------- fields */

.field { display: block; margin-bottom: 1rem; }
.field-label { display: block; margin-bottom: .3rem; font-weight: 600; font-size: .9375rem; }
.field-hint { display: block; margin-top: .3rem; font-size: .8125rem; color: var(--ink-soft); }
.field-hint.is-error { color: var(--bad); }

.input {
    display: block;
    width: 100%;
    padding: .55rem .7rem;
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.field.has-error .input { border-color: var(--bad); }

.form-actions { display: flex; gap: .5rem; margin-top: 1.25rem; }

.detail-list { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 0 0 1rem; }
.detail-list dt { color: var(--ink-soft); font-size: .875rem; }
.detail-list dd { margin: 0; }

/* ------------------------------------------------------------------ buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* 40px minimum: this gets used on tablets at school events. */
    min-height: 40px;
    padding: .5rem 1rem;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
}

.btn:hover:not(:disabled) { background: var(--surface-alt); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .6; cursor: progress; }

.btn.is-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.is-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }

.btn.is-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.is-danger:hover:not(:disabled) { filter: brightness(1.08); background: var(--bad); }

/* Destructive but not the primary action — used in table rows, where a row of red buttons
   would read as an error state. */
.btn.is-danger-quiet { color: var(--bad); border-color: var(--line); }
.btn.is-danger-quiet:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad); }

.row-actions { display: inline-flex; gap: .35rem; justify-content: flex-end; }
.row-actions .btn { min-height: 32px; padding: .25rem .6rem; font-size: .8125rem; font-weight: 500; }

/* ------------------------------------------------------------------- alerts */

.alert {
    padding: .7rem .9rem;
    border-radius: var(--radius-sm);
    border-left: 3px solid;
    margin-bottom: 1rem;
    font-size: .9375rem;
}

.alert.is-error { color: var(--bad); background: var(--bad-soft); border-color: var(--bad); }
.alert.is-warning { color: var(--warn); background: var(--warn-soft); border-color: var(--warn); }
.alert.is-success { color: var(--ok); background: var(--ok-soft); border-color: var(--ok); }
.alert.is-info { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }

.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}

.badge.is-success { color: var(--ok); background: var(--ok-soft); }
.badge.is-warning { color: var(--warn); background: var(--warn-soft); }
.badge.is-danger { color: var(--bad); background: var(--bad-soft); }
.badge.is-neutral { color: var(--accent); background: var(--accent-soft); }
.badge.is-muted { color: var(--ink-soft); background: var(--surface-sunk); }

/* -------------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; margin: 0 -1.25rem -1.25rem; padding: 0 1.25rem 1.25rem; }

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

.table th {
    text-align: left;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ink-soft);
    padding: 0 .6rem .5rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.table td { padding: .6rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-alt); }

.empty { padding: 2rem 1rem; text-align: center; color: var(--ink-soft); }

/* ------------------------------------------------------------------- checks */

.checks { display: flex; flex-direction: column; gap: .6rem; }

.check { display: flex; gap: .7rem; align-items: flex-start; }
.check-dot { flex: 0 0 auto; width: 1rem; font-weight: 700; }
.check-dot.is-ok { color: var(--ok); }
.check-dot.is-bad { color: var(--bad); }
.check-name { font-weight: 600; font-size: .9375rem; }
.check-detail { color: var(--ink-soft); font-size: .8125rem; }

.role-list { display: flex; flex-direction: column; gap: .75rem; }
.role-name { font-weight: 600; }

/* -------------------------------------------------------------------- modal */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .45);
    display: grid;
    place-items: center;
    padding: 1rem;
    z-index: 100;
    overflow-y: auto;
}

.modal {
    width: 100%;
    max-width: 30rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 50px rgba(16, 24, 40, .25);
    /* Tall dialogs scroll internally rather than pushing their footer off screen. */
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line);
}

.modal-head h2 { margin: 0; }

.modal-close {
    border: 0;
    background: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--ink-soft);
    cursor: pointer;
    padding: 0 .25rem;
}

.modal-body { padding: 1.25rem; overflow-y: auto; }
.modal-body .field:last-child { margin-bottom: 0; }

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--line);
}

/* ------------------------------------------------------------------- toasts */

.toasts {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    z-index: 200;
    max-width: min(24rem, calc(100vw - 2rem));
}

.toast {
    padding: .7rem .9rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: .9375rem;
    background: var(--surface);
    border-left: 3px solid var(--ok);
    animation: toast-in .18s ease-out;
}

.toast.is-error { border-color: var(--bad); }
.toast.is-leaving { opacity: 0; transform: translateY(4px); transition: all .2s ease-in; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}
