:root {
  --paper: #F3F5F8; --paper-2: #FFFFFF; --ink: #0F1B2D; --ink-soft: #394960; --ink-faint: #5C6B80;
  --sky: #3FADE0; --sky-deep: #1672A8; --sky-tint: #E8F3FA; --coral: #D63D25; --leaf: #1F8F5F;
  --line: #D8E0E9; --line-strong: #B6C4D3;
  --nav-bg: #14233A; --nav-ink: #C9D5E3; --nav-hover: #20334F;
  --radius-sm: 11px;
  --shadow-sm: 0 2px 8px -4px rgba(34, 49, 74, .14);
  --shadow: 0 10px 24px -14px rgba(34, 49, 74, .28);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.45 'Nunito', system-ui, sans-serif; }
h1 { margin: 0; font-family: 'Unbounded', sans-serif; font-size: 1.35rem; line-height: 1.25; }
button, input, select { font: inherit; }
.icon { width: 16px; height: 16px; flex: 0 0 auto; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; color: var(--ink-soft); }

/* ---------- sign-in ---------- */
.login-card { width: 100%; max-width: 360px; background: var(--paper-2); border: 1.5px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 28px; color: var(--ink); }
.login-card h1 { margin-bottom: 18px; font-size: 1.2rem; }
.form-error { margin: 0 0 12px; color: var(--coral); font-size: 13.5px; }

.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 4px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.field input { width: 100%; padding: 8px 10px; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; color: var(--ink); }
.field input:focus, .table-toolbar input:focus, .table-toolbar select:focus { outline: none; border-color: var(--sky-deep); box-shadow: 0 0 0 3px rgba(63, 173, 224, .16); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border: 1.5px solid var(--line-strong); border-radius: 9px; background: var(--paper-2); color: var(--ink); font-weight: 700; cursor: pointer; }
.btn-primary { background: var(--sky-deep); border-color: var(--sky-deep); color: #fff; }
.btn-primary:hover { background: #105A86; border-color: #105A86; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-danger { background: var(--coral); border-color: var(--coral); color: #fff; }
.btn-danger:hover { background: #B8301B; border-color: #B8301B; }
.btn-wide { width: 100%; }

/* ---------- shell ---------- */
.app-shell { display: grid; grid-template-columns: 212px minmax(0, 1fr); min-height: 100vh; }
.main { min-width: 0; }
.side-nav { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 16px 12px; background: var(--nav-bg); color: var(--nav-ink); }
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 6px; font-family: 'Unbounded', sans-serif; font-weight: 700; font-size: 13px; color: #fff; }
.brand-mark { width: 28px; height: 28px; border-radius: 9px; background: var(--sky); display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.nav-tabs { display: flex; flex-direction: column; gap: 2px; }
.nav-tab { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: none; border-radius: 9px; background: none; color: var(--nav-ink); font-weight: 700; font-size: 13.5px; text-align: left; cursor: pointer; }
.nav-tab:hover { color: #fff; background: var(--nav-hover); }
.nav-tab.active, .nav-tab.active:hover { background: var(--sky-deep); color: #fff; }
.whoami { margin-top: auto; padding: 0 6px; font-size: 12.5px; color: var(--nav-ink); overflow-wrap: anywhere; }

.page { padding: 24px 28px 40px; max-width: 1100px; }
.page-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.count { color: var(--ink-faint); font-weight: 700; }
.page-action { margin-left: auto; align-self: center; }

.error-banner { margin: 16px 28px 0; padding: 10px 14px; border-radius: var(--radius-sm); background: #FDEEEB; border: 1.5px solid var(--coral); color: #8F2A19; font-weight: 600; }

/* ---------- family filter ---------- */
.chip { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 12px; padding: 4px 6px 4px 12px; border-radius: 100px; background: var(--sky-tint); border: 1.5px solid #BFDCEE; color: var(--sky-deep); font-weight: 700; }
.chip button { width: 22px; height: 22px; padding: 0; border: none; border-radius: 50%; background: none; color: inherit; font-size: 16px; line-height: 1; cursor: pointer; }
.chip button:hover { background: #D9ECF8; }
.link { color: var(--sky-deep); font-weight: 700; text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer; }
.link:hover { color: var(--ink); }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; border: none; border-radius: 10px; background: #B5D8EE; color: var(--sky-deep); cursor: pointer; transition: background .12s ease, color .12s ease, transform .12s ease; }
.icon-btn:hover { background: var(--sky-deep); color: #fff; }
.icon-btn:active { transform: scale(.95); }
.icon-btn:focus-visible { outline: 3px solid rgba(63, 173, 224, .45); outline-offset: 2px; }
.icon-btn .icon { width: 17px; height: 17px; stroke-width: 2.1; }
.data-table td.actions { width: 1%; text-align: right; }

/* ---------- edit dialog ---------- */
.dialog { width: min(420px, calc(100vw - 32px)); padding: 24px; border: 1.5px solid var(--line); border-radius: 18px; background: var(--paper-2); color: var(--ink); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(15, 27, 45, .45); }
.dialog h2 { margin: 0 0 14px; font-family: 'Unbounded', sans-serif; font-size: 1.05rem; }
.dialog select, .field select { width: 100%; padding: 8px 10px; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; color: var(--ink); }
.dialog input:focus, .dialog select:focus { outline: none; border-color: var(--sky-deep); box-shadow: 0 0 0 3px rgba(63, 173, 224, .16); }
.dialog-text { margin: 0 0 14px; color: var(--ink-soft); }
.hint { margin: 0 0 14px; font-size: 12.5px; color: var(--ink-faint); }
.dialog-wide { width: min(640px, calc(100vw - 32px)); }
.pay-status { margin: -6px 0 12px; font-weight: 700; }
.pay-add { display: flex; gap: 8px; margin-bottom: 8px; }
.pay-add select { flex: 1; min-width: 0; }
.pay-close { margin-top: 14px; }
.avatars { margin: 0 0 12px; padding: 0; border: 0; }
.avatars legend { margin-bottom: 4px; padding: 0; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.avatar-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatar-grid label { display: flex; align-items: center; justify-content: center; height: 44px; border: 1.5px solid var(--line-strong); border-radius: 10px; background: #fff; font-size: 24px; cursor: pointer; }
.avatar-grid input { position: absolute; opacity: 0; pointer-events: none; }
.avatar-grid label:has(input:checked) { border-color: var(--sky-deep); background: var(--sky-tint); box-shadow: 0 0 0 3px rgba(63, 173, 224, .2); }
.avatar-grid label:has(input:focus-visible) { outline: 3px solid rgba(63, 173, 224, .45); outline-offset: 1px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- table ---------- */
.table-toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.table-toolbar select, .table-toolbar input { padding: 7px 10px; border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm); background: #fff; color: var(--ink); }
.table-toolbar input { flex: 1 1 220px; min-width: 0; }
.table-card { background: var(--paper-2); border: 1.5px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm); overflow: hidden; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th { padding: 10px 12px; text-align: left; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); background: #F7F9FB; border-bottom: 1.5px solid var(--line); white-space: nowrap; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--sky-tint); }
.data-table .strong { font-weight: 700; }
.data-table .nowrap { white-space: nowrap; }
.data-table .row-muted td { color: var(--ink-faint); }
.empty { margin: 0; padding: 24px; text-align: center; color: var(--ink-faint); }
.badge { display: inline-block; padding: 3px 9px; border-radius: 100px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.badge-active { background: #DDF3E8; color: #146C47; }
.badge-inactive { background: #E6EAEF; color: var(--ink-soft); }

/* ---------- course and progress pages ---------- */
.back { display: inline-block; margin-bottom: 10px; font-size: 13.5px; }
.summary { margin: -6px 0 6px; font-weight: 700; color: var(--ink-soft); }
.blocks { display: grid; gap: 18px; }
.block-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; font-size: 15px; font-weight: 800; }
.block-head .ico { font-size: 18px; }
.data-table .num { width: 1%; color: var(--ink-faint); font-weight: 700; white-space: nowrap; }
.data-table .mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; }
.data-table .row-current td { background: #F2F9FD; }
.data-table .row-current td:first-child { box-shadow: inset 3px 0 0 var(--sky-deep); }
.data-table td.buttons { white-space: nowrap; text-align: right; }
.data-table td.buttons .btn + .btn { margin-left: 6px; }
/* Every block's table has the same columns: fixed widths keep them lined up from block to block */
.blocks .data-table { table-layout: fixed; }
.blocks .data-table th:nth-child(1) { width: 52px; }
#progress-blocks .data-table th:nth-child(3) { width: 190px; }
#progress-blocks .data-table th:nth-child(4) { width: 96px; }
#progress-blocks .data-table th:nth-child(5) { width: 290px; }
#course-blocks .data-table th:nth-child(3) { width: 270px; }
#course-blocks .data-table th:nth-child(4) { width: 80px; }
#course-blocks .data-table th:nth-child(5) { width: 104px; }
#course-blocks .data-table th:nth-child(6) { width: 136px; }
.badge-current { background: var(--sky-tint); color: var(--sky-deep); }
.badge-started { background: #FFF1D6; color: #8A5A00; }
.date { margin-left: 6px; color: var(--ink-faint); font-size: 12.5px; }
.stars-select { padding: 4px 6px; border: 1.5px solid var(--line-strong); border-radius: 8px; background: #fff; color: #B07A00; font-size: 13px; }
.stars-select:focus { outline: none; border-color: var(--sky-deep); box-shadow: 0 0 0 3px rgba(63, 173, 224, .16); }

@media (max-width: 700px) {
  .app-shell { grid-template-columns: 1fr; }
  .side-nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .nav-tabs { flex-direction: row; }
  .nav-tab { width: auto; }
  .whoami { margin: 0 0 0 auto; }
  .page { padding: 16px 16px 32px; }
  .error-banner { margin: 12px 16px 0; }
}
