/* ============================================================================
   SMS — application stylesheet (no build step; plain CSS in public/)
   Design tokens → layout → components
   ========================================================================== */

:root {
    --ink: #1e293b;
    --ink-soft: #475569;
    --muted: #64748b;
    --line: #e2e8f0;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --brand-soft: #eff6ff;
    --ok: #059669;
    --warn: #d97706;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --sidebar-bg: #0f172a;
    --sidebar-ink: #cbd5e1;
    --sidebar-muted: #64748b;
    --radius: 10px;
    --shadow: 0 1px 3px rgb(15 23 42 / 0.08);
    --shadow-lg: 0 10px 30px rgb(15 23 42 / 0.12);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.35rem; margin: 0 0 .25rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 650; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: .9em; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mt { margin-top: 1rem; }

/* --- App shell (sidebar + main) ------------------------------------------ */

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

.sidebar {
    width: 232px;
    flex: 0 0 232px;
    background: var(--sidebar-bg);
    color: var(--sidebar-ink);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid rgb(148 163 184 / 0.15);
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    background: var(--brand);
    color: #fff;
    font-weight: 800;
    font-size: .8rem;
    letter-spacing: .05em;
}

.brand-name { font-weight: 700; color: #f1f5f9; font-size: .95rem; }

.nav { flex: 1; padding: 10px 8px; overflow-y: auto; }

.nav-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--sidebar-ink);
    font-size: .92rem;
    margin-bottom: 2px;
}
.nav-link:hover { background: rgb(148 163 184 / 0.12); text-decoration: none; }
.nav-link.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav-link.disabled { color: var(--sidebar-muted); cursor: default; }
.nav-link.disabled:hover { background: none; }

.nav-group {
    text-transform: uppercase;
    font-size: .68rem;
    letter-spacing: .08em;
    color: var(--sidebar-muted);
    margin: 16px 12px 6px;
}

.soon {
    font-size: .62rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgb(148 163 184 / 0.18);
    color: var(--sidebar-muted);
}

.sidebar-footer {
    padding: 14px 16px;
    font-size: .75rem;
    color: var(--sidebar-muted);
    border-top: 1px solid rgb(148 163 184 / 0.15);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-title { font-weight: 650; color: var(--ink); font-size: .98rem; }

.topbar-user { display: flex; align-items: center; gap: 10px; }

.user-name { font-weight: 600; font-size: .9rem; }

.content { padding: 28px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* --- Cards ---------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 18px;
}

.card-title { margin-bottom: 8px; }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.card-tile { position: relative; margin: 0; }

/* --- Forms ---------------------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; }

.field label { font-size: .85rem; font-weight: 600; color: var(--ink-soft); }

.field input {
    font: inherit;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    width: 100%;
}
.field input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.15);
}

.check { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--ink-soft); }

/* --- Buttons -------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font: inherit;
    font-weight: 600;
    font-size: .9rem;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background .12s, border-color .12s;
}
.btn:hover { text-decoration: none; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--bg); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }

/* --- Alerts --------------------------------------------------------------- */

.alert {
    padding: 11px 14px;
    border-radius: 8px;
    font-size: .9rem;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }

/* --- Role badges ---------------------------------------------------------- */

.role-badge {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-dark);
}
.role-superadmin { background: #fef3c7; color: #92400e; }
.role-admin { background: var(--brand-soft); color: var(--brand-dark); }
.role-ops { background: #ecfdf5; color: #065f46; }
.role-parent { background: #f8fafc; color: var(--ink-soft); }

/* --- Guest pages ---------------------------------------------------------- */

.guest-body {
    background: linear-gradient(160deg, #1e3a8a 0%, #0f172a 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.guest-wrap { width: 100%; max-width: 400px; }

.guest-card {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 30px;
}

.guest-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 22px;
}
.guest-brand .brand-name { color: var(--ink); font-weight: 800; font-size: 1.05rem; }

.guest-title { font-size: 1.25rem; margin-bottom: 4px; }

.guest-hint { color: var(--muted); font-size: .85rem; margin-top: 16px; }
.guest-foot { color: rgb(203 213 225 / 0.8); font-size: .8rem; margin-top: 16px; text-align: center; }

/* --- 2FA pages ------------------------------------------------------------ */

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 18px;
    align-items: start;
}

.qr-box {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 220px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
}
.qr-box img { max-width: 200px; height: auto; }

.secret-box {
    font-family: var(--mono);
    font-size: 1rem;
    letter-spacing: .08em;
    background: var(--bg);
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 12px;
    margin: 10px 0 18px;
    text-align: center;
    word-break: break-all;
}

.recovery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.recovery-code {
    font-family: var(--mono);
    font-size: 1rem;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
    letter-spacing: .12em;
}

/* --- Page heads ----------------------------------------------------------- */

.page-head { margin-bottom: 18px; }
.page-head h1 { display: flex; align-items: center; gap: 10px; }

/* --- Responsive ----------------------------------------------------------- */

@media (max-width: 860px) {
    .sidebar { width: 64px; flex-basis: 64px; }
    .brand-name, .nav-group, .nav-link span:not(.soon), .sidebar-footer { display: none; }
    .nav-link { justify-content: center; }
    .nav-link .soon { display: none; }
    .content { padding: 18px; }
    .topbar { padding: 10px 16px; }
    .user-name { display: none; }
}

/* --- Phase 2 admin: tables, pills, toolbars, grids ------------------------- */

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .925rem;
}
.table th {
    text-align: left;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
}
.table td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
.table tbody tr:last-child td { border-bottom: none; }
.td-right { text-align: right; white-space: nowrap; }

.pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .04em;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink);
    text-transform: uppercase;
}
.pill-ok { color: #0f7b3d; border-color: #9fd9b4; background: #e6f6ec; }
.pill-muted { color: var(--muted); }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar-top { margin-top: 16px; align-items: end; }
.search {
    flex: 1;
    min-width: 180px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: .9rem;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-term { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 10px; align-items: end; }
.grid-cards { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) {
    .grid-2, .grid-3, .grid-term, .grid-cards { grid-template-columns: 1fr; }
}

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn-group { display: flex; gap: 10px; flex-wrap: wrap; }
.field-error { display: block; color: #b3261e; font-size: .8rem; margin-top: 4px; }
textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: .9rem;
    font-family: inherit;
}
select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font-size: .9rem;
}
.danger-zone { border-color: #e5b4b0 !important; }
.alert-ok { background: #e6f6ec; border-color: #9fd9b4; color: #0f7b3d; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.tab {
    padding: 6px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: .82rem;
    color: var(--muted);
    text-decoration: none;
}
.tab.active { background: var(--brand); color: var(--surface); border-color: var(--brand); }

/* --- Phase 7: tags, portal cards, avatars, searchable pickers --------------- */
.tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    background: var(--bg);
    border: 1px solid var(--line);
    color: var(--ink-soft);
}
.tag-ok { background: #e6f6ec; border-color: #9fd9b4; color: #0f7b3d; }
.tag-error { background: #fdeeee; border-color: #f3b8b4; color: #b91c1c; }

.avatar {
    width: 56px;
    height: 56px;
    border-radius: 999px;
    object-fit: cover;
    border: 2px solid var(--line);
    background: var(--bg);
    flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; vertical-align: -6px; margin-right: 6px; border-width: 1px; }
.avatar-initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--brand-dark);
    background: var(--brand-soft);
}
.child-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.child-stats { display: flex; gap: 24px; margin: 0 0 12px; }
.child-stats dt { font-size: .75rem; color: var(--muted); }
.child-stats dd { margin: 0; font-weight: 600; }
.announcement-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.announcement-row:last-child { border-bottom: none; }
.announcement-row p { margin: 4px 0 0; }
.invoice-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.invoice-row:last-child { border-bottom: none; }
.invoice-row-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.code-display { font-size: 1.15rem; letter-spacing: .08em; }
.search-results {
    border: 1px solid var(--line);
    border-radius: 8px;
    max-height: 220px;
    overflow-y: auto;
    background: var(--surface);
}
.search-result {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    font-size: .88rem;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--bg); }
