:root {
  --bg: #f4f6f9;
  --ink: #1a2332;
  --muted: #64748b;
  --panel: #fff;
  --line: #e2e8f0;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #16a34a;
  --ok-soft: #f0fdf4;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --radius: 12px;
  --sidebar: 260px;
  --font: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1,h2,h3,h4 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex-shrink: 0; background: #1e1b4b; color: #e0e7ff;
  padding: 1rem .85rem; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar__brand { display: flex; gap: .75rem; align-items: center; padding: .5rem; margin-bottom: .5rem; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); font-weight: 700; color: #fff;
}
.brand-mark--lg { width: 56px; height: 56px; font-size: 1.4rem; margin: 0 auto 1rem; }
.sidebar__brand strong, .sidebar__brand small { display: block; }
.sidebar__brand small { color: #a5b4fc; font-size: .75rem; }
.sidebar__nav { display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.sidebar__nav a {
  padding: .55rem .75rem; border-radius: 8px; color: #c7d2fe; font-size: .9rem; transition: background .15s;
}
.sidebar__nav a:hover, .sidebar__nav a.is-active { background: rgba(255,255,255,.1); color: #fff; }
.nav-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: #6366f1; padding: .75rem .75rem .25rem; }
.sidebar__user { display: flex; align-items: center; gap: .5rem; padding: .75rem .5rem 0; border-top: 1px solid rgba(255,255,255,.08); font-size: .85rem; }
.user-chip {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: .75rem; font-weight: 600; flex-shrink: 0;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .85rem 1.25rem;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.topbar__title { font-size: 1.15rem; flex: 1; }
.content { padding: 1.25rem; flex: 1; }
.content--portal { max-width: 960px; margin: 0 auto; width: 100%; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.panel--flush { overflow: auto; }
.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1rem; border-bottom: 1px solid var(--line);
}
.panel__body { padding: 1rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; margin-bottom: 1rem; }
.toolbar__filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .5rem 1rem; border-radius: 8px; border: 1px solid transparent; font: inherit; font-size: .875rem;
  font-weight: 500; cursor: pointer; transition: all .15s;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { background: var(--bg); }
.btn--sm { padding: .35rem .65rem; font-size: .8rem; }
.btn--block { width: 100%; }

.input, .field input, .field select, .field textarea {
  padding: .5rem .75rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: .875rem;
  background: #fff; min-width: 0;
}
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; }
.field span { font-size: .8rem; font-weight: 500; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; }
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem;
}
.stat-card__label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .25rem; }
.stat-card__value { font-size: 1.6rem; font-weight: 700; }
.stat-card--warn { border-color: #fcd34d; background: var(--warn-soft); }
.stat-card--danger { border-color: #fca5a5; background: var(--danger-soft); }
.stat-card--accent { border-color: #a5b4fc; background: var(--accent-soft); }
.stat-card--ok { border-color: #86efac; background: var(--ok-soft); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.list-compact { list-style: none; margin: 0; padding: 0; }
.list-compact li {
  display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem;
  padding: .65rem 1rem; border-bottom: 1px solid var(--line); font-size: .875rem;
}
.list-compact li:last-child { border-bottom: 0; }

.tag {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 600;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.tag--urgent, .tag--overdue { background: var(--danger-soft); color: var(--danger); }
.tag--paid, .tag--ok { background: var(--ok-soft); color: var(--ok); }
.tag--pending, .tag--warn { background: var(--warn-soft); color: var(--warn); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.family-card {
  display: flex; flex-direction: column; gap: .25rem; padding: 1rem; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel); color: inherit; transition: border-color .15s;
}
.family-card:hover { border-color: var(--accent); }

.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th, .data-table td { padding: .65rem 1rem; text-align: left; border-bottom: 1px solid var(--line); }
.data-table th { font-size: .75rem; text-transform: uppercase; color: var(--muted); background: var(--bg); }

/* Schedule grid */
.schedule-wrap { overflow: auto; max-height: calc(100vh - 180px); }
.sched-table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: .78rem; }
.sched-table th, .sched-table td { border: 1px solid var(--line); padding: 0; vertical-align: top; }
.sched-time-col, .sched-time { width: 52px; padding: .25rem .4rem !important; background: var(--bg); color: var(--muted); font-weight: 600; position: sticky; left: 0; z-index: 2; }
.sched-day-head { text-align: center; background: var(--accent-soft); color: var(--accent); font-size: .75rem; padding: .4rem !important; }
.sched-room-head { text-align: center; background: #f8fafc; font-size: .68rem; padding: .3rem .4rem !important; min-width: 90px; }
.sched-cell { min-width: 90px; height: 42px; background: #fafbfc; cursor: default; }
.sched-cell.has-lesson { background: #fff; }
.sched-lesson {
  padding: .2rem .3rem; margin: 1px; border-left: 3px solid var(--accent); background: #fff;
  border-radius: 4px; font-size: .68rem; line-height: 1.25;
}
.sched-lesson strong { display: block; font-size: .7rem; }
.sched-lesson small, .sched-lesson em { display: block; color: var(--muted); font-style: normal; font-size: .62rem; }

/* Funnel */
.funnel { display: flex; gap: .75rem; overflow-x: auto; padding-bottom: .5rem; }
.funnel-col { min-width: 200px; flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; }
.funnel-col h3 { font-size: .85rem; margin-bottom: .65rem; display: flex; align-items: center; gap: .4rem; }
.funnel-card {
  display: block; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 8px;
  margin-bottom: .4rem; background: #fff; color: inherit;
}
.funnel-card.is-urgent { border-color: var(--danger); background: var(--danger-soft); }
.funnel-card strong { display: block; font-size: .85rem; }
.funnel-card small, .funnel-card em { font-size: .75rem; color: var(--muted); font-style: normal; }

/* Progress chart */
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: .5rem 0; }
.bar-chart.inline { height: 80px; }
.bar {
  flex: 1; min-width: 28px; background: var(--accent); border-radius: 4px 4px 0 0;
  position: relative; min-height: 4px; transition: height .3s;
}
.bar span { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: .65rem; font-weight: 600; padding-bottom: 2px; }
.progress-chart { margin-bottom: 1rem; }
.progress-chart h4 { font-size: .85rem; margin-bottom: .35rem; }
.progress-meta { font-size: .8rem; color: var(--muted); margin-top: .35rem; }

.churn-card { padding: .75rem 1rem; border-left: 4px solid var(--warn); background: var(--warn-soft); border-radius: 0 8px 8px 0; margin-bottom: .5rem; }
.churn-card.severity-high { border-color: var(--danger); background: var(--danger-soft); }
.churn-card p { margin: .35rem 0 0; font-size: .85rem; }

.ktp-plan-item { padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 8px; margin-bottom: .4rem; cursor: pointer; }
.ktp-plan-item.is-active { border-color: var(--accent); background: var(--accent-soft); }
.ktp-list { padding-left: 1.2rem; }
.ktp-list li { margin-bottom: .75rem; font-size: .875rem; }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.quick-action {
  padding: .75rem; text-align: center; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font-weight: 500; font-size: .85rem;
}
.quick-action:hover { border-color: var(--accent); background: var(--accent-soft); }

.prep-plan { margin-top: 1rem; padding: .75rem; background: var(--accent-soft); border-radius: 8px; }

/* Auth */
.auth-page { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(135deg, #eef2ff, #f4f6f9); }
.auth-card { width: min(400px, 92vw); background: #fff; border-radius: var(--radius); padding: 2rem; box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.alert { padding: .65rem .85rem; border-radius: 8px; margin-bottom: 1rem; font-size: .875rem; }
.alert--danger { background: var(--danger-soft); color: var(--danger); }

/* Portal */
.app-shell--portal { flex-direction: column; }
.portal-header {
  display: flex; align-items: center; gap: 1.5rem; padding: .75rem 1.25rem;
  background: #1e1b4b; color: #e0e7ff;
}
.portal-header__brand { display: flex; align-items: center; gap: .65rem; }
.portal-nav { display: flex; gap: .5rem; flex: 1; }
.portal-nav a { color: #c7d2fe; padding: .4rem .75rem; border-radius: 6px; font-size: .875rem; }
.portal-nav a.is-active, .portal-nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.portal-header__user { display: flex; align-items: center; gap: .75rem; font-size: .875rem; }

.modal { border: 0; padding: 0; background: transparent; max-width: 96vw; }
.modal::backdrop { background: rgba(0,0,0,.4); }
.modal__card { background: #fff; border-radius: var(--radius); padding: 1.25rem; width: min(520px, 96vw); border: 0; }
.modal__actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

.toast {
  position: fixed; bottom: 1.25rem; right: 1.25rem; background: var(--ink); color: #fff;
  padding: .65rem 1rem; border-radius: 8px; font-size: .875rem; opacity: 0; transform: translateY(8px);
  transition: all .25s; z-index: 999;
}
.toast.is-show { opacity: 1; transform: none; }
.toast--err { background: var(--danger); }

.notif-bell { position: relative; cursor: default; font-size: 1.1rem; }
.notif-count {
  position: absolute; top: -6px; right: -8px; background: var(--danger); color: #fff;
  font-size: .65rem; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center;
}

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -280px; transition: left .25s; z-index: 50; }
  .sidebar.is-open { left: 0; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
