:root {
    /* Brand colors, matching the iOS app's DuoColor.primary (#13bdec) and
       complementary (#ec4213). --good/--bad are darker shades of each so
       small text stays readable. */
    --accent: #13bdec;
    --accent-dark: #0f9bc2;
    --ink: #1f2328;
    --body: #4b5563;
    --muted: #6b7280;
    --hairline: #e5e7eb;
    --bg: #f6f7f9;
    --card: #ffffff;
    --sidebar: #1f2328;
    --sidebar-ink: #d1d5db;
    --good: #0a7fa0;
    --good-bg: #d9f4fb;
    --warn: #9a6700;
    --warn-bg: #fff4d6;
    --bad: #c1360f;
    --bad-bg: #fde4dc;
    --blue: #1565c0;
    --blue-bg: #e3f0fd;
    --neutral-bg: #f0f1f3;
    --banner-bg: #fff4d6;
    --banner-ink: #6b4a00;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --ink: #e6e8eb;
        --body: #c2c7ce;
        --muted: #9aa1ab;
        --hairline: #2d3239;
        --bg: #14171b;
        --card: #1b1f24;
        --sidebar: #0f1215;
        --good: #5fd3f2;
        --good-bg: #0f2f3a;
        --warn: #f0c14b;
        --warn-bg: #3a2f10;
        --bad: #ff8a66;
        --bad-bg: #3d1d12;
        --blue: #7fb6f5;
        --blue-bg: #16283d;
        --neutral-bg: #262b31;
        --banner-bg: #3a2f10;
        --banner-ink: #f0d58a;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--ink);
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--neutral-bg); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 16px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.text-bad { color: var(--bad); font-weight: 600; }

.demo-banner {
    background: var(--banner-bg);
    color: var(--banner-ink);
    padding: 9px 20px;
    font-size: 13px;
    border-bottom: 1px solid var(--hairline);
}

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-ink);
    padding: 22px 14px;
    display: flex;
    flex-direction: column;
}
.brand { font-weight: 800; font-size: 16px; color: #fff; margin: 0 8px 24px; }
.brand .brand-sub { color: var(--accent); margin-left: 2px; }
/* The wordmark's navy "Song" needs a light background: a white plate on the dark sidebar. */
.brand-plate { display: inline-block; background: #fff; border-radius: 12px; padding: 12px 12px 4px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-item { color: var(--sidebar-ink); padding: 9px 10px; border-radius: 8px; font-weight: 600; }
.nav-item:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; }
.nav-item.active { background: rgba(19, 189, 236, 0.18); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 0 8px; font-size: 12px; color: #9aa1ab; line-height: 1.5; }
.sidebar-foot strong { color: #fff; }

.content { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1200px; }
.subtitle { color: var(--body); margin: 0 0 20px; }
.loading { color: var(--muted); padding: 40px 0; }
.error-box { background: var(--bad-bg); color: var(--bad); padding: 14px 16px; border-radius: 10px; }
.empty { color: var(--muted); text-align: center; padding: 18px; margin: 0; }
.back-link { display: inline-block; margin-bottom: 12px; font-weight: 600; }

.card {
    background: var(--card);
    border: 1px solid var(--hairline);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card { margin-bottom: 16px; }

.page-head { display: flex; gap: 20px; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .subtitle { margin-bottom: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; max-width: 480px; justify-content: flex-end; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--card); border: 1px solid var(--hairline); border-radius: 12px; padding: 14px 16px; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 800; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--body); }

.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 17px; }
.count-bad, .count-warn { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; margin-left: 6px; }
.count-bad { background: var(--bad-bg); color: var(--bad); }
.count-warn { background: var(--warn-bg); color: var(--warn); }
.link-btn { font-weight: 600; font-size: 13px; }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; white-space: nowrap; background: var(--neutral-bg); color: var(--body); }
.pill-good { background: var(--good-bg); color: var(--good); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.pill-blue { background: var(--blue-bg); color: var(--blue); }

.issue { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--hairline); }
.card > .issue:first-of-type, .card > h2 + .issue { border-top: none; padding-top: 0; }
.issue-icon { flex-shrink: 0; width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.issue-error .issue-icon { background: var(--bad-bg); color: var(--bad); }
.issue-warning .issue-icon { background: var(--warn-bg); color: var(--warn); }
.issue-info .issue-icon { background: var(--blue-bg); color: var(--blue); }
.issue-body { flex: 1; min-width: 0; }
.issue-title { font-weight: 700; margin-bottom: 3px; }
.issue-code { font-weight: 500; color: var(--muted); margin-left: 4px; }
.issue-detail { color: var(--body); line-height: 1.5; }
.ok-line { color: var(--good); font-weight: 600; margin: 0; }

.table-wrap { overflow-x: auto; }
.card.table-wrap { padding: 4px 0; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
.card:not(.table-wrap) th:first-child, .card:not(.table-wrap) td:first-child { padding-left: 0; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--neutral-bg); }
table.mini td { padding: 5px 10px 5px 0; font-size: 13px; }

.list-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--hairline); }
.card > h2 + .list-row { border-top: none; padding-top: 0; }

.meter { margin-bottom: 12px; }
.meter-label { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 5px; gap: 8px; }
.bar-track { height: 8px; background: var(--neutral-bg); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; }
.bar-fill.good { background: var(--accent); }
.bar-fill.warn { background: #ffc800; }
.bar-fill.bad { background: #ec4213; }

.audit-row { padding: 10px 0; border-top: 1px solid var(--hairline); line-height: 1.45; }
.card > h2 + .audit-row { border-top: none; padding-top: 0; }
.audit-meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.audit-details { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted); word-break: break-word; }

.btn {
    font: inherit;
    font-weight: 600;
    font-size: 13px;
    padding: 7px 12px;
    border-radius: 8px;
    border: 1px solid var(--hairline);
    background: var(--card);
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-small { padding: 4px 9px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--bad); }
.modal .btn-danger { background: #c1360f; border-color: #a02d0c; color: #fff; }
.btn-ghost { background: transparent; }
.copy-btn { font: inherit; font-size: 11px; font-weight: 600; background: none; border: none; color: var(--blue); cursor: pointer; padding: 0 2px; }

.search-row { display: flex; gap: 8px; margin-bottom: 16px; max-width: 560px; }
input, select, textarea {
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--hairline);
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 8px; font-weight: 600; color: var(--body); text-transform: capitalize; }
.tab.active { background: var(--card); border: 1px solid var(--hairline); color: var(--ink); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { background: var(--card); border-radius: 14px; padding: 22px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.modal h2 { font-size: 18px; margin-bottom: 2px; }
.modal-note { color: var(--body); line-height: 1.5; margin: 0 0 8px; }
.modal label { font-size: 12px; font-weight: 700; color: var(--muted); margin-top: 8px; }
.modal-error { background: var(--bad-bg); color: var(--bad); padding: 8px 10px; border-radius: 8px; margin-top: 8px; font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--sidebar); }
.gate-card { background: var(--card); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; }
.gate-brand { margin: 0 0 20px; }
.gate-brand .brand-plate { padding-left: 0; }
.gate-form { display: flex; flex-direction: column; gap: 6px; }
.gate-form label { font-size: 12px; font-weight: 700; color: var(--muted); margin-top: 6px; }
.gate-form .btn { margin-top: 14px; padding: 10px; }
.gate-note { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 16px 0 0; }
.sign-out { background: none; border: none; padding: 0; margin-top: 6px; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 20; }

@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .kpis { grid-template-columns: repeat(2, 1fr); }
    .actions { justify-content: flex-start; max-width: none; }
}

@media (max-width: 700px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; padding: 12px 16px; }
    .brand { margin: 0 0 10px; }
    .nav-group { flex-direction: row; overflow-x: auto; }
    .nav-item { white-space: nowrap; }
    .sidebar-foot { display: none; }
    .content { padding: 20px 16px 48px; }
    .issue { flex-wrap: wrap; }
    .issue-body { flex-basis: calc(100% - 34px); }
    .issue .btn { margin-left: 34px; }
}

/* Songfish wordmark (logo 1d). Always on a light background. */
.wordmark { font-family: "Baloo 2", ui-rounded, system-ui, sans-serif; font-weight: 800; line-height: 1; letter-spacing: -0.01em; display: inline-flex; align-items: baseline; white-space: nowrap; }
.wm-song { color: #0a3342; }
.wm-fish { color: #13bdec; }
.wm-i { position: relative; }
.wm-i::after { content: ""; position: absolute; left: 50%; top: 0.045em; width: 0.26em; height: 0.2em; margin-left: -0.13em; border-radius: 50%; background: #ec4213; transform: rotate(-20deg); }
.brand-sub { display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; margin-top: 4px; }

/* School enquiries */
.enquiry-banner { display: block; background: var(--warn-bg); color: var(--warn); font-weight: 700; padding: 12px 16px; border-radius: 12px; margin: -8px 0 20px; }
.enquiry-message { background: var(--neutral-bg); border-radius: 10px; padding: 10px 12px; margin: 10px 0 0; white-space: pre-wrap; }
