/* KidsTutor — mobile-first stylesheet
   - Default styles target ≤640px (phones)
   - min-width media queries scale up for tablet/desktop
   - System font stack
   - 16px base font (prevents iOS auto-zoom on inputs)
   - 44×44pt minimum touch target
*/

:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1e40af;
    --color-bg: #f9fafb;
    --color-surface: #ffffff;
    --color-text: #111827;
    --color-text-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-error: #dc2626;
    --color-success: #16a34a;
    --color-warning: #d97706;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-12: 48px;
    --header-h: 56px;
    --bottom-nav-h: 64px;
    --content-max: 720px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Microsoft YaHei", "Helvetica Neue", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 var(--space-3) 0; line-height: 1.3; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 600; }
h3 { font-size: 17px; font-weight: 600; }

/* ─── Layout shell ───────────────────────────────────────────────────── */

.app-shell {
    min-height: 100vh;
    padding-bottom: var(--bottom-nav-h);  /* leave room for bottom nav on mobile */
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 var(--space-4);
    box-shadow: var(--shadow-sm);
}

.top-bar .title {
    font-size: 17px;
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-bar .actions { display: flex; gap: var(--space-2); }

.container {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-4);
}

/* ─── Bottom nav (mobile) ────────────────────────────────────────────── */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    display: flex;
    height: var(--bottom-nav-h);
    z-index: 10;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--color-text-muted);
    font-size: 11px;
    font-weight: 500;
    min-height: 44px;
}

.bottom-nav a.active,
.bottom-nav a:hover {
    color: var(--color-primary);
    text-decoration: none;
}

.bottom-nav .icon {
    font-size: 20px;
    line-height: 1;
}

/* Hide bottom nav on ≥1025px (use sidebar instead) */
@media (min-width: 1025px) {
    .bottom-nav { display: none; }
    .app-shell { padding-bottom: 0; }
}

/* ─── Cards ──────────────────────────────────────────────────────────── */

.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    border: 1px solid var(--color-border);
}

.card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
}

.card-row .meta { color: var(--color-text-muted); font-size: 14px; }

.child-card { display: block; }
.child-card .name { font-size: 17px; font-weight: 600; }
.child-card .meta { color: var(--color-text-muted); font-size: 14px; margin-top: 4px; }

/* ─── Buttons ────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: var(--space-3) var(--space-5);
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    background: var(--color-surface);
    color: var(--color-text);
    transition: background 0.1s ease;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary {
    background: var(--color-surface);
    border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); }

.btn-danger {
    background: var(--color-error);
    color: white;
    border-color: var(--color-error);
}

.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: var(--space-2) var(--space-3); font-size: 14px; }

/* ─── Forms ──────────────────────────────────────────────────────────── */

.form-group { margin-bottom: var(--space-4); }

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: var(--space-2);
    color: var(--color-text);
}

.form-label .required { color: var(--color-error); }

.form-input, .form-select {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: var(--space-3);
    font-size: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.form-hint {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.form-row {
    display: flex;
    gap: var(--space-3);
}

@media (max-width: 640px) {
    .form-row { flex-direction: column; gap: 0; }
    .form-row .form-group { margin-bottom: var(--space-4); }
}

/* ─── Flash messages ─────────────────────────────────────────────────── */

.flash {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    margin-bottom: var(--space-3);
    font-size: 14px;
}
.flash-error { background: #fef2f2; color: var(--color-error); border: 1px solid #fecaca; }
.flash-success { background: #f0fdf4; color: var(--color-success); border: 1px solid #bbf7d0; }
.flash-warning { background: #fffbeb; color: var(--color-warning); border: 1px solid #fde68a; }

/* ─── Auth pages (login / register) ──────────────────────────────────── */

.auth-page {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-4);
}

.auth-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: var(--space-6);
    max-width: 400px;
    width: 100%;
    margin: 0 auto;
}

.auth-card h1 {
    text-align: center;
    margin-bottom: var(--space-6);
}

.auth-card .auth-footer {
    text-align: center;
    margin-top: var(--space-4);
    font-size: 14px;
    color: var(--color-text-muted);
}

/* ─── Tables → cards on mobile ───────────────────────────────────────── */

.data-list { display: flex; flex-direction: column; gap: var(--space-3); }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border-radius: var(--radius);
    overflow: hidden;
}
table.data-table th, table.data-table td {
    padding: var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}
table.data-table th {
    background: var(--color-bg);
    font-weight: 600;
    font-size: 14px;
}

/* Tables: card view on mobile, table view on ≥641px */
@media (max-width: 640px) {
    table.data-table, table.data-table thead, table.data-table tbody,
    table.data-table tr, table.data-table th, table.data-table td {
        display: block;
    }
    table.data-table thead { display: none; }
    table.data-table tr {
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        margin-bottom: var(--space-3);
        padding: var(--space-3);
    }
    table.data-table td {
        border: none;
        padding: var(--space-1) 0;
    }
    table.data-table td:before {
        content: attr(data-label) ": ";
        font-weight: 600;
        color: var(--color-text-muted);
    }
}

/* ─── Admin invite codes table ───────────────────────────────────────── */

.code-cell {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 14px;
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: 4px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}
.badge-success { background: #dcfce7; color: var(--color-success); }
.badge-warning { background: #fef3c7; color: var(--color-warning); }
.badge-muted { background: #f3f4f6; color: var(--color-text-muted); }

/* ─── Empty state ────────────────────────────────────────────────────── */

.empty {
    text-align: center;
    padding: var(--space-12) var(--space-4);
    color: var(--color-text-muted);
}

.empty .icon { font-size: 48px; opacity: 0.4; }
.empty h3 { margin-top: var(--space-3); color: var(--color-text); }

/* ─── Hide on mobile / desktop ──────────────────────────────────────── */

@media (max-width: 640px) {
    .hide-mobile { display: none !important; }
}
@media (min-width: 641px) {
    .hide-desktop { display: none !important; }
}

/* ─── Desktop ≥1025px: sidebar + wider content ──────────────────────── */

@media (min-width: 1025px) {
    :root { --content-max: 1024px; }
    .desktop-layout {
        display: grid;
        grid-template-columns: 220px 1fr;
        gap: var(--space-6);
        max-width: 1280px;
        margin: 0 auto;
        padding: var(--space-6);
    }
    .sidebar {
        background: var(--color-surface);
        border-radius: var(--radius);
        padding: var(--space-4);
        box-shadow: var(--shadow-sm);
        border: 1px solid var(--color-border);
        align-self: start;
        position: sticky;
        top: var(--space-4);
    }
    .sidebar a {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-3);
        border-radius: var(--radius);
        color: var(--color-text);
        font-weight: 500;
    }
    .sidebar a:hover, .sidebar a.active {
        background: var(--color-bg);
        text-decoration: none;
        color: var(--color-primary);
    }
    .top-bar { position: static; border: none; box-shadow: none; padding: 0; }
}