:root {
    --color-primary: #78674b;
    --color-primary-dark: #5a4d38;
    --color-text: #222;
    --color-muted: #666;
    --color-border: #e0e0e0;
    --color-bg: #f5f4f2;
    --color-sidebar: #362e21;
    --color-error-bg: #fdecea;
    --color-error-text: #7a1f1f;
    --color-success-bg: #e9f7ec;
    --color-success-text: #1e6b34;
    --radius: 8px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--color-text); background: var(--color-bg); }
a { color: var(--color-primary); }

/* ---- App shell (admin/parent portal) ---- */
.app-mobile-bar { display: none; }
.app-sidebar-backdrop { display: none; }
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--color-sidebar);
    color: #f2e9ea;
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    transition: width 0.2s ease;
}

.app-brand {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    font-weight: 700; font-size: 1.1rem; padding: 0 20px 20px; border-bottom: 1px solid rgba(255,255,255,0.15);
}
.app-brand-label { overflow-wrap: break-word; line-height: 1.25; }

.app-sidebar-toggle {
    background: none; border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; color: #f2e9ea;
    width: 26px; height: 26px; flex-shrink: 0; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.app-sidebar-toggle:hover { background: rgba(255,255,255,0.12); }
.app-mobile-toggle { display: none; }

.app-nav { display: flex; flex-direction: column; flex: 1; padding-top: 10px; }
.app-nav a { display: flex; align-items: center; gap: 12px; color: #f2e9ea; text-decoration: none; padding: 12px 20px; font-size: 0.95rem; white-space: nowrap; }
.app-nav a:hover { background: rgba(255,255,255,0.08); }
.app-nav a i { flex-shrink: 0; width: 18px; text-align: center; font-size: 1.05rem; }

.app-logout { padding: 16px 20px 0; border-top: 1px solid rgba(255,255,255,0.15); }
.app-user { font-size: 0.85rem; opacity: 0.8; margin-bottom: 8px; }
.app-logout .btn-link { display: flex; align-items: center; gap: 10px; color: #f2e9ea; }

/* ---- Collapsed sidebar ---- */
.app-sidebar.collapsed { width: 64px; }
.app-sidebar.collapsed .app-brand { justify-content: center; padding: 0 0 20px; }
.app-sidebar.collapsed .app-nav-label,
.app-sidebar.collapsed .app-brand-label { display: none; }
.app-sidebar.collapsed .app-nav a { justify-content: center; padding: 12px 0; }
.app-sidebar.collapsed .app-logout { display: flex; flex-direction: column; align-items: center; }
.app-sidebar.collapsed .app-logout .btn-link { justify-content: center; }

.app-content { flex: 1; padding: 28px 32px; min-width: 0; }

/* ---- Auth pages ---- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-body-wide { align-items: flex-start; padding: 40px 20px; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: var(--radius); padding: 32px; box-shadow: 0 2px 10px rgba(0,0,0,0.08); }
.auth-card-wide { max-width: 900px; }
.auth-card-wide .card { text-align: left; }
.auth-card-wide .card h2 { color: var(--color-primary); border-bottom: 2px solid var(--color-border); padding-bottom: 8px; margin-top: 0; }
.auth-logo { display: block; width: 88px; height: auto; margin: 0 auto 12px; }
.auth-brand { text-align: center; color: var(--color-primary); font-size: 1.3rem; margin-bottom: 20px; }
.auth-links { text-align: center; margin-top: 16px; font-size: 0.9rem; }

/* ---- Typography / layout helpers ---- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 1.4rem; }
h2 { font-size: 1.1rem; }

.card { background: #fff; border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }

.stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-tile {
    flex: 1; min-width: 140px; background: #fff; border-radius: var(--radius); padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06); display: block; text-decoration: none;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.stat-tile:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); transform: translateY(-2px); }
.stat-tile .stat-value { font-size: 1.6rem; font-weight: 700; color: var(--color-primary); }
.stat-tile .stat-label { font-size: 0.85rem; color: var(--color-muted); }

/* ---- Forms ---- */
.field { display: block; font-size: 0.85rem; font-weight: 600; color: var(--color-muted); margin-bottom: 14px; }
.field input, .field select, .field textarea {
    display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font-size: 0.95rem; font-weight: 400;
    color: var(--color-text); border: 1px solid var(--color-border); border-radius: 6px;
}
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 200px; }
.field-row > .btn, .field-row > button, .field-row > a.btn { margin-bottom: 14px; }
.checkbox-field { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; margin-bottom: 14px; }

.rte-toolbar { display: flex; gap: 6px; margin-top: 6px; }
.rte-toolbar button {
    border: 1px solid var(--color-border); background: #fff; border-radius: 6px; padding: 5px 12px;
    cursor: pointer; font-size: 0.85rem; color: var(--color-text);
}
.rte-toolbar button:hover { background: var(--color-bg); }
.rte-editor {
    min-height: 180px; margin-top: 6px; padding: 12px 14px; border: 1px solid var(--color-border);
    border-radius: 8px; font-size: 0.95rem; font-weight: 400; color: var(--color-text); background: #fff;
}
.rte-editor:focus { outline: 2px solid var(--color-primary); outline-offset: 1px; }
.rte-editor ul, .rte-editor ol { margin: 8px 0; padding-left: 22px; }
.rte-editor p { margin: 0 0 8px; }

.btn, button, input[type="submit"] {
    display: inline-block; font-size: 0.95rem; font-weight: 600; border: none; border-radius: 6px;
    padding: 10px 18px; cursor: pointer; text-decoration: none; background: var(--color-primary); color: #fff;
}
.btn:hover, button:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-primary); border: 1px solid var(--color-primary); }
.btn-danger { background: #a83232; }
.btn-link { background: none; color: var(--color-primary); padding: 0; font-weight: 400; text-decoration: underline; }
.btn-block { width: 100%; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.signature-pad {
    width: 100%; height: 220px; border: 2px dashed var(--color-border); border-radius: 8px;
    touch-action: none; background: #fff; margin-bottom: 12px;
}

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); font-size: 0.9rem; }
th { background: #faf8f7; font-weight: 700; color: var(--color-muted); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }

/* ---- Alerts ---- */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-error { background: var(--color-error-bg); color: var(--color-error-text); border: 1px solid #f3c1bd; }
.alert-success { background: var(--color-success-bg); color: var(--color-success-text); border: 1px solid #b9e2c2; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 0.78rem; font-weight: 600; }
.badge-success { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-warn { background: #fff4e0; color: #8a5a00; }
.badge-muted { background: #eee; color: #555; }

.empty-state { color: var(--color-muted); padding: 20px 0; text-align: center; }

@media (max-width: 800px) {
    /* Persistent top bar - stays put (not inside .app-sidebar) so its hamburger
       button is always reachable even while the drawer itself is off-canvas. */
    .app-mobile-bar {
        display: flex; align-items: center; justify-content: space-between; gap: 12px;
        position: sticky; top: 0; z-index: 20;
        background: var(--color-sidebar); color: #f2e9ea;
        padding: 12px 16px; font-weight: 700; font-size: 1rem;
    }
    .app-mobile-bar .app-brand-label { overflow-wrap: break-word; line-height: 1.25; }

    .app-mobile-toggle {
        display: flex; align-items: center; justify-content: center; flex-shrink: 0;
        width: 34px; height: 34px; background: none; color: #f2e9ea;
        border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; cursor: pointer;
    }
    .app-mobile-toggle:hover { background: rgba(255,255,255,0.12); }

    /* Off-canvas side drawer: fixed panel sliding in from the left over a dimmed
       backdrop, instead of the desktop's inline flex column. The desktop
       collapse/expand toggle + its persisted width state don't apply here. */
    .app-shell { flex-direction: column; }
    .app-sidebar, .app-sidebar.collapsed {
        position: fixed; top: 0; left: 0; z-index: 30;
        width: min(80vw, 280px); height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 2px 0 16px rgba(0,0,0,0.25);
    }
    .app-sidebar.mobile-open { transform: translateX(0); }
    .app-sidebar .app-brand { display: none; }
    .app-sidebar .app-nav { padding-top: 16px; overflow-y: auto; }

    .app-sidebar-backdrop {
        display: block; position: fixed; inset: 0; z-index: 25;
        background: rgba(0,0,0,0.4);
        opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
    }
    .app-sidebar-backdrop.visible { opacity: 1; pointer-events: auto; }

    .app-sidebar.collapsed .app-nav-label, .app-sidebar.collapsed .app-brand-label { display: inline; }
    .app-sidebar.collapsed .app-nav a { justify-content: flex-start; padding: 12px 20px; }
    .app-content { padding: 16px; }
    .card { padding: 16px; }

    /* Smaller, non-wrapping buttons so action rows (Filter/Export, View/Edit/
       Delete, pagination, ...) stay compact and legible on a phone. */
    .btn, button, input[type="submit"] { padding: 8px 14px; font-size: 0.88rem; white-space: nowrap; }
    .app-sidebar-toggle:not(.app-mobile-toggle) { display: none; }

    /* Wide multi-column tables (registrations, invoices, submissions, ...) would
       otherwise force the whole page to scroll sideways on a phone. Keeping the
       table itself as the scroll container (rows/cells keep their table layout,
       only the outer <table> box becomes block + scrollable) contains that to
       just the table. */
    table { display: block; overflow-x: auto; }
}
