:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --text: #16203a;
  --muted: #6b7794;
  --brand: #4f7cff;
  --brand-soft: #eaf0ff;
  --green: #17a673;
  --green-soft: #e5f7ef;
  --amber: #e5a00d;
  --amber-soft: #fdf3dd;
  --red: #e2544c;
  --red-soft: #fdecea;
  --purple: #8b5cf6;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20,32,58,.05), 0 8px 24px rgba(20,32,58,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --surface: #171d2c; --surface-2: #1d2434; --border: #2a3346;
    --text: #e8ecf5; --muted: #99a3ba;
    --green-soft: #10312a; --amber-soft: #33290f; --red-soft: #3a1e1e;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.22); --brand: #6b90ff; --brand-soft: #1e2a4a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
.app-loading { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, var(--brand-soft), transparent), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 30px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.role-switch { display: flex; gap: 8px; background: var(--surface-2); padding: 5px; border-radius: 12px; margin-bottom: 20px; }
.role-switch button { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px;
  cursor: pointer; font-weight: 600; color: var(--muted); }
.role-switch button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 16px; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 18px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.on { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; }
.nav-item .badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 20px;
  font-size: 11px; padding: 1px 7px; font-weight: 700; }
.nav-spacer { flex: 1; }
.side-user { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; display: flex; align-items: center; gap: 10px; }

.main { padding: 26px 30px 90px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.page-head .spacer { flex: 1; }

/* ---------- primitives ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 14px; font-size: 15px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.card h2 .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.03em; }
.stat .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat.red .n { color: var(--red); } .stat.amber .n { color: var(--amber); }
.stat.green .n { color: var(--green); } .stat.brand .n { color: var(--brand); }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 8px 14px; border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 7px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--red); border-color: var(--red-soft); background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label.field { display: block; margin-bottom: 13px; }
label.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 130px; }
.pillrow { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.cardhead { display: flex; gap: 11px; align-items: center; margin-bottom: 12px; }
.cardhead > .grow { flex: 1; min-width: 0; }
.btnrow { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 12px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.avatar { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px; flex: none; }
.avatar.lg { width: 46px; height: 46px; border-radius: 14px; font-size: 18px; }
.avatar.sm { width: 26px; height: 26px; border-radius: 8px; font-size: 11px; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 14px; }
.empty .big { font-size: 30px; display: block; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.strike { text-decoration: line-through; opacity: .55; }

/* ---------- task list ---------- */
.tasklist { display: flex; flex-direction: column; gap: 9px; }
.task {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; position: relative; overflow: hidden;
}
.task::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--border); }
.task.p-high::before { background: var(--red); }
.task.p-normal::before { background: var(--brand); }
.task.p-low::before { background: var(--border); }
.task.is-done { opacity: .62; }
.task .check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); background: transparent;
  cursor: pointer; flex: none; margin-top: 2px; display: grid; place-items: center; color: #fff; font-size: 12px; padding: 0;
}
.task .check.on { background: var(--green); border-color: var(--green); }
.task .check.half { border-color: var(--amber); color: var(--amber); background: var(--amber-soft); }
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 600; }
.task .meta { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; margin-top: 5px; }
.task .actions { display: flex; gap: 4px; align-items: center; }

.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 20px 0 9px; }
.section-label:first-child { margin-top: 0; }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row .spacer { flex: 1; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 0 10px 8px 0; font-weight: 700; }
table.data td { padding: 9px 10px 9px 0; border-top: 1px solid var(--border); }

.progress { height: 7px; background: var(--surface-2); border-radius: 20px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 20px; }

/* ---------- timetable ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 10px; }
.week .day { background: var(--surface-2); border-radius: var(--radius-sm); padding: 9px; min-height: 90px; }
.week .day h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.slot { background: var(--surface); border-radius: 8px; padding: 7px 8px; margin-bottom: 6px; font-size: 12.5px;
  border-left: 3px solid var(--brand); }
.slot .t { color: var(--muted); font-size: 11px; }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,20,32,.45); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 18px; z-index: 60; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 540px; max-height: 88vh;
  overflow: auto; box-shadow: 0 24px 60px rgba(15,20,32,.28); border: 1px solid var(--border); }
.modal header { padding: 18px 20px 4px; display: flex; align-items: center; gap: 10px; }
.modal header h3 { margin: 0; font-size: 17px; flex: 1; }
.modal .content { padding: 14px 20px 4px; }
.modal footer { padding: 14px 20px 20px; display: flex; gap: 9px; justify-content: flex-end; }
#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 90;
  display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 20px; font-size: 14px;
  font-weight: 600; box-shadow: var(--shadow); animation: pop .18s ease; }
.toast.err { background: var(--red); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- kid theme ---------- */
body.kid { --radius: 18px; --radius-sm: 12px; }
body.kid .main { padding-top: 22px; }
body.kid .page-head h1 { font-size: 27px; }
.hero { background: linear-gradient(135deg, var(--brand), var(--purple)); color: #fff; border-radius: 20px;
  padding: 22px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.hero h2 { margin: 0; font-size: 22px; }
.hero p { margin: 4px 0 0; opacity: .9; font-size: 14px; }
.hero .points { margin-left: auto; text-align: right; }
.hero .points b { font-size: 30px; display: block; line-height: 1.1; }
.chipbar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; }
.chipbar button { border: 1px solid var(--border); background: var(--surface); border-radius: 20px;
  padding: 6px 13px; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.chipbar button.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- mobile ---------- */
.mobile-nav { display: none; }
.topbar { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px 15px 92px; }
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .week { grid-template-columns: 1fr; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
    border-top: 1px solid var(--border); padding: 7px 6px calc(7px + env(safe-area-inset-bottom)); z-index: 40; overflow-x: auto;
  }
  .mobile-nav button { flex: 1; min-width: 54px; border: 0; background: none; padding: 6px 3px; border-radius: 10px;
    color: var(--muted); font-size: 10.5px; font-weight: 600; cursor: pointer; display: grid; gap: 2px; justify-items: center; }
  .mobile-nav button.on { color: var(--brand); background: var(--brand-soft); }
  .mobile-nav .ico { font-size: 18px; }
  .topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
}
@media (max-width: 560px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
