@import url('https://fonts.googleapis.com/css2?family=Syne:wght@600;700;800&family=DM+Sans:wght@400;500;700&display=swap');

/*
 |--------------------------------------------------------------------------
 | Theming
 |--------------------------------------------------------------------------
 | header.php toggles theme via `document.body.classList.toggle('dark-mode')`
 | — it never sets a `data-theme` attribute. This file previously keyed its
 | light palette off `[data-theme="light"]`, which never matched anything,
 | so it was permanently stuck on the dark :root palette regardless of the
 | toggle. Fixed: :root is now the LIGHT palette (the real default, matching
 | header.php's own default), and `body.dark-mode` overrides it — the same
 | mechanism header.php already uses, so both files now agree.
 |--------------------------------------------------------------------------
 */
:root {
  --bg: #f4f5f8;
  --bg-soft: #ffffff;
  --panel: #ffffff;
  --panel-2: #f0f1f6;
  --border: #e3e5ee;
  --text: #191b22;
  --text-dim: #676d7e;
  --orange: #ff6b1a;
  --orange-dim: #ff6b1a33;
  --green: #23c98b;
  --green-dim: #23c98b26;
  --red: #ff5470;
  --red-dim: #ff547026;
  --amber: #ffb020;
  --amber-dim: #ffb02026;
  --blue: #4ea1ff;
  --blue-dim: #4ea1ff26;

  /* Shared with header.php's inline theme — used for the gradient topbar/brand
     accents so every page (old and newly redesigned) draws from the same
     two colors instead of drifting into separate palettes. */
  --accent: #4f7cff;
  --accent-2: #7c5cff;

  --radius: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.12);
  --font-head: 'Syne', sans-serif;
  --font-body: 'DM Sans', sans-serif;
}

body.dark-mode {
  --bg: #0f1115;
  --bg-soft: #161922;
  --panel: #1b1f2a;
  --panel-2: #20242f;
  --border: #2a2f3d;
  --text: #eef0f5;
  --text-dim: #9aa0b0;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

/* Back-compat: keep responding to [data-theme="dark"] too, in case any
   other surface in the app still sets that attribute instead of the class. */
[data-theme="dark"] {
  --bg: #0f1115;
  --bg-soft: #161922;
  --panel: #1b1f2a;
  --panel-2: #20242f;
  --border: #2a2f3d;
  --text: #eef0f5;
  --text-dim: #9aa0b0;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  transition: background .2s, color .2s;
}
h1, h2, h3, h4, .brand { font-family: var(--font-head); letter-spacing: .2px; }
a { color: inherit; text-decoration: none; }

/* ---------- Auth page ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #ff6b1a22, transparent 40%),
              radial-gradient(circle at 80% 80%, #23c98b1f, transparent 40%), var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 36px 32px;
}

.auth-logo { display:flex; align-items:center; gap:10px; margin-bottom: 6px; }
.auth-logo .ball { font-size: 28px; }
.auth-logo span { font-size: 22px; font-weight: 800; }
.auth-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 26px; }
.tabs { display:flex; gap: 4px; background: var(--panel-2); border-radius: 10px; padding: 4px; margin-bottom: 22px; }
.tabs a { flex:1; text-align:center; padding: 8px 0; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--text-dim); }
.tabs a.active { background: var(--orange); color: #fff; }

.field { margin-bottom: 16px; }
.field label { display:block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-soft); color: var(--text); font-family: var(--font-body); font-size: 14px;
}
.field input::placeholder, .field textarea::placeholder {
  color: var(--text-dim);
  opacity: 1;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--orange); border-color: var(--orange); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 10px; border: none; cursor: pointer;
  font-family: var(--font-body); font-weight: 700; font-size: 14px; transition: transform .12s, opacity .12s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { opacity: .92; }

/*
 |------------------------------------------------------------------
 | BUG FIX: .btn-ghost previously had no explicit `color`, so on
 | pages/themes where it inherited a dark `color` while also getting
 | a dark `background` (e.g. via body.dark-mode cascading oddly, or a
 | page overriding background alone), it rendered as a solid dark box
 | with invisible text. Explicit color + hover state fixes it for good
 | in both themes.
 |------------------------------------------------------------------
 */
.btn-ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); color: var(--text); }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: .92; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---------- App shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  transition: width .2s;
}
.sidebar.collapsed { width: 74px; }
.sidebar.collapsed .label, .sidebar.collapsed .brand span, .sidebar.collapsed .user-block .who { display: none; }
.brand { display:flex; align-items:center; gap:10px; padding: 6px 8px 22px; font-size: 20px; font-weight: 800; }
.nav-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); margin: 14px 8px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-dim); font-weight: 600; font-size: 14px; margin-bottom: 2px;
}
.nav-link:hover { background: var(--panel-2); color: var(--text); }
.nav-link.active { background: var(--orange-dim); color: var(--orange); }
.nav-link .icon { width: 20px; text-align: center; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 14px; }
.user-block { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--orange); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.who .name { font-size: 13px; font-weight: 700; }
.who .role { font-size: 11px; color: var(--text-dim); text-transform: capitalize; }

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

/*
 |------------------------------------------------------------------
 | BUG FIX: .topbar used to be `background: var(--bg-soft)` — since
 | --bg-soft only ever changed via a `data-theme` attribute that
 | nothing in the app actually sets, this rendered as a plain dark bar
 | in light mode and only "looked right" in dark mode by coincidence.
 | Now it's the same blue/purple gradient in both themes (matching
 | kids.php / sessions.php / progress.php / settings.php), scoped to
 | `.main` so it doesn't clash with anything inside the sidebar.
 |------------------------------------------------------------------
 */
.main .topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-bottom: none;
  border-radius: var(--radius);
  margin: 20px 24px 0;
  box-shadow: 0 8px 24px rgba(79,124,255,0.25);
  position: sticky; top: 0; z-index: 5;
}
.main .topbar h1 { font-size: 20px; margin: 0; color: #fff; }

.content { padding: 26px 28px 60px; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } .sidebar { display: none; } }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.stat-card .stat-label { color: var(--text-dim); font-size: 13px; font-weight: 500; }
.stat-card .stat-value { font-size: 30px; font-weight: 800; font-family: var(--font-head); margin-top: 6px; }
.stat-card .stat-icon { float: right; font-size: 22px; opacity: .8; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 30px 0 14px; }
.section-title h2 { font-size: 17px; margin: 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--text-dim); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td { padding: 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-ok { background: var(--green-dim); color: var(--green); }
.badge-warn { background: var(--amber-dim); color: var(--amber); }
.badge-bad { background: var(--red-dim); color: var(--red); }
.badge-info { background: var(--blue-dim); color: var(--blue); }

.kid-card { display: flex; gap: 14px; align-items: center; }
.kid-photo { width: 52px; height: 52px; border-radius: 50%; background: var(--panel-2); display:flex; align-items:center; justify-content:center; font-weight: 800; font-size: 18px; color: var(--orange); flex-shrink: 0; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-bg.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal h3 { margin-top: 0; }
.modal-close { float: right; cursor: pointer; color: var(--text-dim); font-size: 20px; background: none; border: none; }

.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--orange);
  padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; min-width: 240px;
  animation: slideIn .25s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.search-box { display: flex; align-items: center; gap: 8px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; min-width: 220px; }
.search-box input { border: none; background: transparent; color: var(--text); outline: none; width: 100%; font-family: var(--font-body); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty-state .big { font-size: 40px; margin-bottom: 10px; }

.progress-bar { width: 100%; height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress-bar .fill { height: 100%; background: linear-gradient(90deg, var(--orange), var(--green)); border-radius: 999px; }

.icon-btn { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; width: 32px; height: 32px; display:flex; align-items:center; justify-content:center; cursor: pointer; color: var(--text-dim); }
.icon-btn:hover { color: var(--text); }

.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.text-dim { color: var(--text-dim); }
.mt-0 { margin-top: 0; }

/* ===================================================
   Auth page enhancements
=================================================== */
.auth-wrap { min-height: 100dvh; }

.auth-card {
  animation: cardIn .35s ease;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.auth-logo .ball {
  display: inline-flex;
  filter: drop-shadow(0 2px 6px var(--orange-dim));
}

.tabs a { transition: background .15s, color .15s; }
.tabs a:hover:not(.active) { color: var(--text); }

.field input, .field select, .field textarea {
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  box-shadow: 0 0 0 3px var(--orange-dim);
}

.auth-error {
  background: var(--red-dim);
  color: var(--red);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
  border: 1px solid var(--red-dim);
}

/* password show/hide */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 12px;
  color: var(--text-dim); padding: 5px 8px; font-weight: 700;
  border-radius: 6px; transition: background .15s, color .15s;
}
.pw-toggle:hover { color: var(--text); background: var(--panel-2); }

/* inline field validation */
.field-error {
  font-size: 11px; color: var(--red); margin-top: 5px; display: none;
}
.field.has-error input { border-color: var(--red); }
.field.has-error input:focus { box-shadow: 0 0 0 3px var(--red-dim); }
.field.has-error .field-error { display: block; }

.btn { position: relative; }
.btn[disabled] { opacity: .65; cursor: not-allowed; transform: none; }

/* prevent iOS zoom-on-focus for all form inputs, not just auth */
@media (max-width: 640px) {
  .field input, .field select, .field textarea { font-size: 16px; }
}

/* ===================================================
   Auth page — breakpoints
=================================================== */
@media (max-width: 480px) {
  .auth-wrap { padding: 16px; }
  .auth-card { padding: 26px 20px; }
  .auth-logo span { font-size: 19px; }
  .auth-logo .ball { font-size: 24px; }
  .auth-sub { font-size: 13px; margin-bottom: 20px; }
  .tabs a { font-size: 13px; padding: 8px 4px; }
}

@media (min-width: 640px) {
  .auth-card { padding: 40px 36px; }
}

/* ===================================================
   App shell — responsive sidebar (bonus: mobile drawer
   instead of just hiding the sidebar outright)
=================================================== */
.mobile-menu-btn { display: none; }
@media (max-width: 700px) {
  .shell { flex-direction: column; }
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    font-size: 20px;
    color: #fff;
    background: linear-gradient(135deg, var(--accent, #4f46e5), var(--accent-2, #7c3aed));
    border: none;
    border-radius: 12px;
    cursor: pointer;
    margin: 14px 14px 0;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }
  .mobile-menu-btn:hover {
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.45);
  }
  .mobile-menu-btn:active {
    transform: scale(0.94);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
  }
  .sidebar {
    display: flex;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 240px;
    transform: translateX(-100%);
    z-index: 40;
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39;
  }
  .sidebar-backdrop.open { display: block; }
  .main { width: 100%; }
  .main .topbar { margin: 12px; padding: 16px; }
  .content { padding: 18px 16px 40px; }
}

@media (max-width: 480px) {
  .stat-card .stat-value { font-size: 24px; }
  .card { padding: 16px; }
  .modal { padding: 20px; }
}