/* ============ Jurnal Kelas - gaya mobile-first ============ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-soft: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --st-h: #16a34a; --st-s: #f59e0b; --st-i: #3b82f6; --st-a: #dc2626; --st-t: #8b5cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #131c2e; --surface-2: #0f1826;
    --text: #e5edf7; --text-soft: #93a4bd; --border: #23304a;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 16px; line-height: 1.45;
  overscroll-behavior-y: none;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }

/* ---------- Tombol ---------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 10px;
  padding: 12px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
  background: var(--surface-2); color: var(--text); transition: background .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-soft); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.btn:disabled { opacity: .6; }

.icon-btn {
  appearance: none; background: transparent; border: none; cursor: pointer;
  font-size: 18px; color: var(--text-soft); padding: 8px; border-radius: 8px; line-height: 1;
}
.icon-btn:active { background: var(--border); }
.icon-btn.danger { color: var(--danger); }

/* ---------- Kartu & layout ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.content { padding: 16px 16px calc(96px + var(--safe-bottom)); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); margin: 18px 2px 8px; }
.muted { color: var(--text-soft); font-size: 14px; }
.small { font-size: 12px; }
.center-note { text-align: center; color: var(--text-soft); padding: 48px 16px; }
.center-text { text-align: center; }
.grow { flex: 1; min-width: 0; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.hello { font-size: 13px; color: var(--text-soft); }
.hello-name { font-size: 20px; font-weight: 700; }
.topbar-class .topbar-title { flex: 1; min-width: 0; }
.topbar-title .class-name { font-size: 17px; font-weight: 700; }
.topbar-title .class-sub { font-size: 12px; color: var(--text-soft); }

/* ---------- Auth ---------- */
.auth-wrap { padding: 32px 20px calc(40px + var(--safe-bottom)); }
.brand { text-align: center; margin: 24px 0 20px; }
.brand-logo {
  width: 66px; height: 66px; border-radius: 18px; margin: 0 auto 12px;
  background: var(--primary); color: #fff; font-weight: 800; font-size: 26px;
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(37,99,235,.35);
}
.brand h1 { margin: 0; font-size: 24px; }
.brand-sub { color: var(--text-soft); font-size: 14px; margin: 4px 0 0; }
.auth-card h2 { margin: 0 0 14px; font-size: 18px; }
.auth-switch { text-align: center; margin: 14px 0 0; color: var(--text-soft); font-size: 14px; }

/* ---------- Field / form ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.field-hint { font-size: 12px; color: var(--text-soft); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea { resize: vertical; }
.invalid { border-color: var(--danger) !important; }

/* ---------- Kartu kelas (dashboard) ---------- */
.class-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; }
.class-card-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.class-avatar {
  width: 46px; height: 46px; border-radius: 12px; flex: none;
  background: linear-gradient(135deg, var(--primary), #60a5fa); color: #fff;
  display: grid; place-items: center; font-weight: 700; text-transform: uppercase; font-size: 15px;
}
.class-name { font-weight: 700; font-size: 16px; }
.class-sub { color: var(--text-soft); font-size: 14px; }
.class-meta { color: var(--text-soft); font-size: 12px; margin-top: 2px; }

/* ---------- Empty state ---------- */
.empty { text-align: center; color: var(--text-soft); padding: 40px 16px; }
.empty-emoji { font-size: 40px; margin-bottom: 8px; }
.empty p { margin: 0 0 14px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: max(16px, calc(50% - 320px + 16px)); bottom: calc(20px + var(--safe-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--primary); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 18px rgba(37,99,235,.45); z-index: 30;
}
.fab:active { background: var(--primary-dark); }

/* ---------- Tabs ---------- */
.tabs {
  position: sticky; top: 57px; z-index: 15; display: flex; gap: 4px; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 6px 10px;
}
.tab { flex: none; padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--text-soft); white-space: nowrap; }
.tab.active { background: var(--primary); color: #fff; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.date-input { width: auto; flex: 1; }

/* ---------- List rows ---------- */
.list-row { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.list-row .num { width: 26px; text-align: center; color: var(--text-soft); font-size: 13px; flex: none; }
.row-title { font-weight: 600; }
.row-sub { font-size: 12px; color: var(--text-soft); }

/* ---------- Absensi ---------- */
.att-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { font-size: 12px; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-soft); }
.chip-H { border-color: var(--st-h); } .chip-S { border-color: var(--st-s); }
.chip-I { border-color: var(--st-i); } .chip-A { border-color: var(--st-a); } .chip-T { border-color: var(--st-t); }
.att-row { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; box-shadow: var(--shadow); }
.att-name { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; }
.st-group { display: flex; gap: 4px; flex: none; }
.st-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-soft); font-weight: 700; font-size: 13px; cursor: pointer;
}
.st-btn.active { color: #fff; border-color: transparent; }
.st-btn.st-H.active { background: var(--st-h); } .st-btn.st-S.active { background: var(--st-s); }
.st-btn.st-I.active { background: var(--st-i); } .st-btn.st-A.active { background: var(--st-a); }
.st-btn.st-T.active { background: var(--st-t); }

/* ---------- Sticky save ---------- */
.sticky-save {
  position: sticky; bottom: 0; margin: 14px -16px calc(-96px - var(--safe-bottom));
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

/* ---------- Nilai ---------- */
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; flex: none; }
.badge-formatif { background: #dbeafe; color: #1e40af; }
.badge-sumatif { background: #ede9fe; color: #5b21b6; }
@media (prefers-color-scheme: dark) {
  .badge-formatif { background: #1e3a5f; color: #93c5fd; }
  .badge-sumatif { background: #3b2f63; color: #c4b5fd; }
}
.score-input { width: 76px; flex: none; text-align: center; font-weight: 700; }
.score-input.below-kktp { color: var(--danger); border-color: var(--danger); }

/* ---------- Jurnal ---------- */
.journal-card { padding: 14px; }
.journal-head { display: flex; align-items: center; justify-content: space-between; }
.journal-date { font-weight: 700; font-size: 14px; }
.journal-topic { font-weight: 600; margin-top: 6px; }
.journal-text { color: var(--text); font-size: 14px; margin-top: 4px; white-space: pre-wrap; }
.journal-note { color: var(--text-soft); font-size: 13px; margin-top: 6px; white-space: pre-wrap; }

/* ---------- Rekap tabel ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.rtable { border-collapse: collapse; width: 100%; font-size: 13px; }
.rtable th, .rtable td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rtable thead th { background: var(--surface-2); color: var(--text-soft); font-weight: 700; position: sticky; top: 0; }
.rtable .ta-left { text-align: left; }
.rtable tbody tr:last-child td { border-bottom: none; }
.below-kktp-text { color: var(--danger); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: end center; z-index: 100; animation: fade .15s; }
@media (min-width: 480px) { .modal-backdrop { place-items: center; } }
.modal { background: var(--surface); width: 100%; max-width: 460px; border-radius: 18px 18px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.2); max-height: 90vh; overflow-y: auto; animation: slideup .2s; }
@media (min-width: 480px) { .modal { border-radius: 18px; } }
.modal-head { font-size: 17px; font-weight: 700; padding: 18px 18px 4px; }
.modal-body { padding: 14px 18px calc(18px + var(--safe-bottom)); }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(30px); } }

/* ---------- Toast ---------- */
#toast-host { position: fixed; left: 0; right: 0; bottom: calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast { background: #111827; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.25); opacity: 0; transform: translateY(10px); transition: .25s; max-width: 90%; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: #15803d; }
.toast-error { background: #b91c1c; }
