:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --sidebar: #f5f6f8;
  --surface: #f7f8fa;
  --surface-2: #eef1f4;
  --text: #121a2c;
  --muted: #727a89;
  --line: #e2e5e9;
  --accent: #009f78;
  --accent-strong: #008965;
  --accent-soft: #e2f7f0;
  --amber: #c88a14;
  --danger: #bd3d47;
  --danger-soft: #fff0f1;
  --shadow: 0 12px 35px rgba(20, 28, 45, .08);
  --radius: 10px;
  --sidebar-width: 294px;
}

html[data-theme="dark"] {
  --bg: #0c1017;
  --panel: #111720;
  --sidebar: #0f141c;
  --surface: #161d28;
  --surface-2: #1b2431;
  --text: #edf2f7;
  --muted: #98a3b4;
  --line: #263040;
  --accent: #20c997;
  --accent-strong: #12b886;
  --accent-soft: #133a30;
  --amber: #e0a83c;
  --danger: #ef6b75;
  --danger-soft: #3a1c22;
  --shadow: 0 16px 45px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.app-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; overflow-x: hidden; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); background: var(--sidebar); border-right: 1px solid var(--line); overflow-y: auto; z-index: 30; }
.main-panel { grid-column: 2; min-width: 0; }
.sidebar-brand, .topbar, .admin-topbar { height: 58px; display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.sidebar-brand { padding: 0 18px; justify-content: space-between; background: var(--panel); position: sticky; top: 0; z-index: 3; }
.brand-link { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .01em; }
.brand-mark { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--text); color: var(--bg); font-weight: 800; letter-spacing: -.04em; }
.brand-mark-small { width: 31px; height: 31px; font-size: 12px; }

.programme-summary { padding: 20px 18px 16px; border-bottom: 1px solid var(--line); }
.programme-summary h2 { font-size: 18px; line-height: 1.2; margin: 0 0 18px; }
.progress-track { height: 3px; border-radius: 10px; background: var(--line); overflow: hidden; }
.progress-track span { display: block; height: 100%; background: var(--accent); }
.progress-copy { display: flex; justify-content: space-between; color: var(--muted); margin-top: 10px; font-size: 11px; }
.progress-copy strong { font-weight: 600; color: var(--muted); }

.sidebar-nav { padding: 12px 0 30px; }
.nav-label { padding: 10px 18px 7px; color: var(--text); font-weight: 750; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.nav-row { min-height: 43px; padding: 8px 18px 8px 28px; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--text); border-left: 3px solid transparent; }
.nav-row:hover, .nav-row.is-active { background: var(--surface-2); }
.nav-row.is-active { border-left-color: var(--accent); font-weight: 650; }
.nav-row-sub { padding-left: 37px; font-size: 13px; }
.nav-count { color: var(--muted); font-size: 11px; white-space: nowrap; }
.status-ring { width: 17px; height: 17px; border: 1px solid #c9ced6; border-radius: 50%; flex: 0 0 auto; }
.status-ring.is-complete, .status-dot.is-complete { background: var(--accent); border-color: var(--accent); }
.status-dot { width: 13px; height: 13px; border: 1px solid #c9ced6; border-radius: 50%; flex: 0 0 auto; }
.sidebar-search { padding: 9px 17px 6px; }
.sidebar-search input { width: 100%; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 9px 11px; outline: none; }
.sidebar-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
.week-group { border: 0; }
.week-group summary { min-height: 43px; padding: 8px 13px 8px 16px; display: grid; grid-template-columns: 14px minmax(0, 1fr) auto auto; align-items: center; gap: 8px; cursor: pointer; list-style: none; }
.week-group summary::-webkit-details-marker { display: none; }
.week-group summary:hover { background: var(--surface-2); }
.week-summary-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.chevron { font-size: 18px; color: var(--muted); transform-origin: center; transition: transform .15s ease; }
.week-group[open] .chevron { transform: rotate(90deg); }

.topbar { padding: 0 22px; background: var(--panel); position: sticky; top: 0; z-index: 20; gap: 10px; }
.topbar-spacer { flex: 1; }
.theme-toggle, .icon-button { border: 0; background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.theme-toggle { gap: 7px; min-height: 36px; padding: 0 10px; border-radius: 8px; color: var(--muted); }
.theme-toggle:hover, .icon-button:hover { background: var(--surface); color: var(--text); }
.icon-button { width: 36px; height: 36px; border-radius: 8px; font-size: 18px; }
.user-chip { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: #d7aa70; color: #fff; font-weight: 700; }
.logout-link { font-size: 12px; color: var(--muted); }
.mobile-menu, .sidebar-close { display: none; }

.content-area { max-width: 1120px; margin: 0 auto; padding: 26px 42px 70px; }
.breadcrumbs { color: var(--amber); font-size: 11px; margin-bottom: 38px; display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumbs a:hover { text-decoration: underline; }
.content-heading { margin: 0 0 42px; }
.content-heading h1 { margin: 6px 0 10px; font-size: clamp(28px, 3vw, 42px); letter-spacing: -.035em; line-height: 1.08; }
.content-heading p { color: var(--muted); margin: 0; }
.content-heading-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.centre-heading { text-align: center; max-width: 760px; margin-left: auto; margin-right: auto; }
.eyebrow { color: var(--amber); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }

.lesson-list { max-width: 900px; margin: 0 auto; }
.list-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.list-header h2 { font-size: 14px; margin: 0; }
.list-header span { color: var(--muted); font-size: 11px; }
.lesson-row { min-height: 68px; background: var(--surface); border: 1px solid transparent; border-radius: 6px; margin-bottom: 7px; padding: 12px 15px; display: flex; align-items: center; gap: 14px; }
.lesson-row:hover { border-color: var(--line); background: var(--surface-2); transform: translateY(-1px); }
.drag-icon { color: var(--muted); font-size: 18px; }
.lesson-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.lesson-copy strong { font-weight: 650; }
.lesson-copy small { color: var(--muted); }
.completion-check { width: 22px; height: 22px; display: grid; place-items: center; border: 1px solid #cbd1d8; border-radius: 50%; color: white; font-size: 12px; }
.completion-check.is-complete { background: var(--accent); border-color: var(--accent); }
.type-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 92px; max-width: 125px; padding: 5px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 10px; font-weight: 700; }

.calendar-board { display: grid; gap: 18px; }
.calendar-week { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--panel); }
.calendar-week-title { display: block; background: color-mix(in srgb, var(--amber) 18%, var(--panel)); padding: 12px 16px; font-weight: 750; }
.calendar-days { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.calendar-day { padding: 18px 14px; min-height: 118px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 7px; }
.calendar-day:last-child { border-right: 0; }
.calendar-day:hover { background: var(--surface); }
.calendar-day span, .calendar-day small { color: var(--muted); font-size: 11px; }
.calendar-day small { margin-top: auto; }
.calendar-actions { text-align: center; margin-top: 32px; }

.video-frame { background: #000; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.video-frame video { display: block; width: 100%; max-height: 68vh; background: #000; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.detail-card, .description-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.detail-card { display: flex; flex-direction: column; gap: 6px; }
.detail-card span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.description-card h3 { margin: 0 0 8px; }
.description-card p { margin: 0; color: var(--muted); line-height: 1.6; }
.empty-state { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 42px 24px; text-align: center; }
.empty-state h3 { margin: 0 0 8px; }
.empty-state p { color: var(--muted); margin: 0 auto 18px; max-width: 570px; line-height: 1.55; }

.button { border: 1px solid transparent; border-radius: 7px; min-height: 38px; padding: 8px 15px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer; font-weight: 650; }
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover { background: var(--accent-strong); }
.button-complete { background: var(--accent-soft); color: var(--accent-strong); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.button-secondary { background: var(--panel); border-color: var(--line); color: var(--text); }
.button-secondary:hover { background: var(--surface); }
.button-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); color: var(--danger); }
.button-small { min-height: 31px; padding: 5px 9px; font-size: 11px; }
.inline-form { margin: 0; }

.auth-page { display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top, var(--surface-2), var(--bg) 45%); }
.auth-card { width: min(440px, 100%); background: var(--panel); padding: 34px; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.auth-card .brand-mark { margin-bottom: 20px; }
.auth-card h1 { margin: 0 0 8px; font-size: 28px; }
.muted { color: var(--muted); }
.stack-form { display: grid; gap: 14px; margin-top: 24px; }
.stack-form label, .field { display: grid; gap: 7px; font-weight: 600; font-size: 12px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--text); padding: 10px 11px; outline: none; }
textarea { resize: vertical; min-height: 92px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent); }
.alert { padding: 12px 14px; border-radius: 8px; margin: 16px 0; }
.alert-success { background: var(--accent-soft); color: var(--accent-strong); }
.alert-error { background: var(--danger-soft); color: var(--danger); }

.admin-page { min-height: 100vh; }
.admin-topbar { padding: 0 28px; justify-content: space-between; background: var(--panel); position: sticky; top: 0; z-index: 20; }
.admin-topbar-actions { display: flex; align-items: center; gap: 8px; }
.admin-container { width: min(1240px, calc(100% - 36px)); margin: 0 auto; padding: 34px 0 80px; }
.admin-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 24px; }
.admin-heading h1 { font-size: 36px; margin: 5px 0 0; }
.server-limit { color: var(--muted); font-size: 12px; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.admin-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 22px; }
.admin-card-wide { grid-column: 1 / -1; }
.card-heading { margin-bottom: 18px; }
.card-heading h2 { margin: 0 0 6px; }
.card-heading p { margin: 0; color: var(--muted); line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-span-2 { grid-column: 1 / -1; }
.source-panel { background: var(--surface); border: 1px solid var(--line); padding: 16px; border-radius: 9px; }
.source-panel h3 { margin: 0 0 14px; font-size: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; }
.compact-form { margin-top: 0; }
.structure-card { margin-top: 18px; }
.structure-list { display: grid; gap: 12px; }
.structure-week { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.structure-week > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; padding: 14px 16px; background: var(--surface); }
.structure-week > summary::-webkit-details-marker { display: none; }
.structure-week > summary span { color: var(--muted); font-size: 12px; }
.structure-week-body { padding: 16px; }
.inline-edit-form { display: grid; grid-template-columns: minmax(180px, 1fr) 110px auto; gap: 8px; align-items: center; }
.structure-day { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.day-admin-head { display: flex; gap: 9px; align-items: center; }
.day-admin-head .inline-edit-form { grid-template-columns: minmax(140px, 1fr) 155px 85px auto; flex: 1; }
.admin-item-row { display: flex; gap: 9px; align-items: center; padding: 10px 0 0 18px; }
.admin-item-title { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.admin-item-title small { color: var(--muted); }
.danger-actions { display: flex; justify-content: flex-end; padding-top: 10px; }
.text-danger { border: 0; background: transparent; color: var(--danger); cursor: pointer; font-size: 11px; padding: 4px; }
.mini-copy { margin: 9px 0 0 18px; font-size: 12px; }

.sidebar-overlay { display: none; }

@media (max-width: 980px) {
  :root { --sidebar-width: 270px; }
  .content-area { padding-left: 28px; padding-right: 28px; }
  .calendar-days { grid-template-columns: repeat(2, 1fr); }
  .calendar-day { border-bottom: 1px solid var(--line); }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-card-wide { grid-column: auto; }
  .day-admin-head { align-items: stretch; flex-direction: column; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 25; }
  .sidebar-open .sidebar-overlay { display: block; }
  .main-panel { grid-column: auto; }
  .mobile-menu, .sidebar-close { display: inline-flex; }
  .content-area { padding: 24px 18px 55px; }
  .breadcrumbs { margin-bottom: 25px; }
  .content-heading-row { align-items: flex-start; flex-direction: column; }
  .calendar-days { grid-template-columns: 1fr; }
  .calendar-day { border-right: 0; }
  .detail-grid { grid-template-columns: 1fr; }
  .logout-link { display: none; }
  .theme-label { display: none; }
  .admin-topbar { padding: 0 14px; }
  .admin-container { width: min(100% - 22px, 1240px); padding-top: 20px; }
  .admin-heading { align-items: flex-start; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .field-span-2 { grid-column: auto; }
  .inline-edit-form, .day-admin-head .inline-edit-form { grid-template-columns: 1fr; }
  .admin-item-row { align-items: flex-start; flex-wrap: wrap; padding-left: 0; }
  .admin-item-title { min-width: calc(100% - 130px); }
  .server-limit { align-self: flex-start; }
}
