/* Sekolah portal: mobile-first styles for teachers and parents. */
:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --text: #1b2430;
    --muted: #677285;
    --border: #e3e7ee;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #e8efff;
    --danger: #c62828;
    --theme: #7c3aed;
    --theme-soft: #f1eafe;
    --schedule: #0f766e;
    --schedule-soft: #e2f5f2;
    --radius: 14px;
    --appbar-h: 60px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}
body.sheet-open { overflow: hidden; }

a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
[hidden] { display: none !important; }

/* ---------- App bar ---------- */
.appbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: var(--safe-top) 12px 0;
    min-height: calc(var(--appbar-h) + var(--safe-top));
    background: var(--primary);
    color: #fff;
}
.appbar-title { flex: 1; min-width: 0; }
.appbar-title h1 { font-size: 1.1rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-title p { font-size: 0.8rem; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: inherit;
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.3); }
.icon-btn svg { width: 22px; height: 22px; }
.logo { font-size: 1.2rem; }

/* ---------- Tabs ---------- */
.tabs {
    position: sticky;
    top: calc(var(--appbar-h) + var(--safe-top));
    z-index: 15;
    display: flex;
    background: var(--primary);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
    flex: 1 0 auto;
    padding: 10px 16px 12px;
    text-align: center;
    color: rgba(255, 255, 255, 0.75);
    font-weight: 600;
    font-size: 0.92rem;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}
.tabs a.active { color: #fff; border-bottom-color: #fff; }

/* ---------- Content ---------- */
.content {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 16px calc(32px + var(--safe-bottom));
}

.section-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin: 24px 4px 10px;
}
.section-title:first-child { margin-top: 4px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
a.card { display: block; color: inherit; }
a.card:active { background: #f8f9fc; }

.card h3 { font-size: 1.05rem; font-weight: 650; }
.card h4 { font-size: 1rem; font-weight: 650; }
.meta { color: var(--muted); font-size: 0.85rem; }
.prewrap { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; margin-top: 8px; }

.card-actions { display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }

.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }

.avatar {
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 700;
}

.chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--primary-soft);
    color: var(--primary-dark);
}
.chip-theme { background: var(--theme-soft); color: var(--theme); }
.chip-schedule { background: var(--schedule-soft); color: var(--schedule); }
.chip-now { background: #fff4d6; color: #92400e; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.class-link { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); color: inherit; }
.class-link:first-of-type { margin-top: 12px; }
.chevron { color: var(--muted); font-size: 1.3rem; }

.day-heading { font-size: 0.95rem; font-weight: 700; margin: 20px 4px 10px; color: var(--text); }
.day-heading:first-child { margin-top: 4px; }
.day-heading small { font-weight: 500; color: var(--muted); margin-left: 6px; }

.plan-card { border-left: 4px solid var(--schedule); }
.plan-card.theme { border-left-color: var(--theme); }
.plan-card.now { box-shadow: 0 0 0 2px #fcd34d inset; }
.plan-when { font-weight: 600; font-size: 0.9rem; margin: 6px 0 0; }

.contact { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); font-size: 0.9rem; }
.contact a { font-weight: 600; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar input[type="date"] { width: auto; flex: 0 1 180px; margin: 0; }

.segmented { display: inline-flex; background: #e6eaf1; border-radius: 10px; padding: 3px; }
.segmented button {
    border: 0;
    background: transparent;
    padding: 7px 14px;
    border-radius: 8px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}
.segmented button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* ---------- Buttons & forms ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 18px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { color: var(--danger); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 0.88rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 4px; font-weight: 600; font-size: 0.9rem; }
.field small { font-weight: 400; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input, textarea, select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #cdd3de;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    /* 16px avoids iOS zooming in on focus */
    font-family: inherit;
    font-size: 16px;
    line-height: 1.4;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; min-height: 120px; }

.kind-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kind-picker label {
    display: block;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}
.kind-picker label small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.kind-picker input { position: absolute; opacity: 0; pointer-events: none; width: auto; }
.kind-picker label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 0.92rem; }
.alert-error { background: #fdecec; color: #8f1d1d; }

/* ---------- States ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 2.4rem; margin-bottom: 8px; }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

.spinner {
    width: 32px;
    height: 32px;
    margin: 40px auto;
    border: 3px solid var(--primary-soft);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.splash { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

/* ---------- Login ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: linear-gradient(160deg, #2563eb 0%, #1e3a8a 100%);
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border-radius: 18px;
    padding: 28px 22px;
    display: grid;
    gap: 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.3);
}
.login-card .brand { text-align: center; }
.login-card .brand .mark { font-size: 2.6rem; }
.login-card h1 { font-size: 1.4rem; }
.login-card p { color: var(--muted); font-size: 0.92rem; }

/* ---------- Bottom sheet (dialog) ---------- */
.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fade 0.15s ease-out;
}
.sheet {
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    padding: 8px 18px calc(20px + var(--safe-bottom));
    animation: slide-up 0.2s ease-out;
}
.sheet-head {
    position: sticky;
    top: -8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    margin-bottom: 4px;
    background: var(--surface);
    z-index: 1;
}
.sheet-head h2 { font-size: 1.1rem; }
.sheet-head .icon-btn { background: #eef1f6; color: var(--text); }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }

@media (min-width: 640px) {
    .sheet-overlay { align-items: center; padding: 24px; }
    .sheet { border-radius: 18px; padding-bottom: 22px; }
    .content { padding-top: 24px; }
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + var(--safe-bottom));
    transform: translateX(-50%);
    z-index: 60;
    max-width: calc(100% - 32px);
    padding: 12px 18px;
    border-radius: 12px;
    background: #1f2937;
    color: #fff;
    font-size: 0.92rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.error { background: var(--danger); }

@media (max-width: 380px) {
    .field-row { grid-template-columns: 1fr; }
}
