:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --ink: #1d2230;
  --ink-2: #4a5163;
  --muted: #7a8090;
  --line: #e3e1da;
  --accent: #4a5bd4;
  --accent-ink: #ffffff;
  --accent-soft: #e8ebfb;
  --ok: #2c9a6b;
  --ok-soft: #e1f3ea;
  --warn: #c98a12;
  --warn-soft: #fbf0d9;
  --danger: #c8443c;
  --danger-soft: #fbe5e3;
  --ext: #8c91a0;
  --ext-soft: #eceef2;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1c1f27;
    --surface-2: #242833;
    --ink: #eceef3;
    --ink-2: #c3c7d2;
    --muted: #8d93a3;
    --line: #2f3440;
    --accent: #8394ff;
    --accent-ink: #10132a;
    --accent-soft: #262c4d;
    --ok: #4cc392;
    --ok-soft: #173327;
    --warn: #e6b04a;
    --warn-soft: #3a2f17;
    --danger: #f0776f;
    --danger-soft: #3d2120;
    --ext: #9aa0ae;
    --ext-soft: #2a2e38;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 .75em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 550; cursor: pointer;
  text-decoration: none !important; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.lg { min-height: 48px; font-size: 16px; padding: 0 20px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); font-weight: 550; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 11px; min-height: 40px; width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
input, select, textarea { font-weight: 400; }
.row > select, .row > input:not([type=checkbox]) { width: auto; flex: 1 1 200px; max-width: 340px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
label.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--ink-2); cursor: pointer; }
label.check input { margin-top: 2px; flex: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card, .card + .grid2, .grid2 + .card, .grid2 + .grid2, .note + .grid2, .note + .card { margin-top: 16px; }
.grid2 > .card, .grid2 > div > .card:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.list { display: flex; flex-direction: column; }
.list > .item { display: flex; gap: 12px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); }
.list > .item:first-child { border-top: 0; padding-top: 0; }
.list > .item:last-child { padding-bottom: 0; }
.item.link { cursor: pointer; }
.item.link:hover .item-title { color: var(--accent); }
.item-title { font-weight: 600; }
.badge { display: inline-flex; align-items: center; min-width: 20px; height: 20px; padding: 0 7px; border-radius: 10px; font-size: 12px; font-weight: 650; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.grey { background: var(--surface-2); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; }
.note { background: var(--accent-soft); color: var(--ink-2); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; }
.note.warn { background: var(--warn-soft); }
.private { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; font-weight: 600; color: var(--warn); background: var(--warn-soft); padding: 2px 8px; border-radius: 8px; }
.copybox { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: 6px 6px 6px 12px; }
.copybox code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.time-big { font-variant-numeric: tabular-nums; font-weight: 650; }
.lesson-date { width: 64px; flex: none; text-align: center; border-radius: 10px; background: var(--surface-2); padding: 6px 0; line-height: 1.15; }
.lesson-date b { display: block; font-size: 20px; }
.lesson-date span { font-size: 12px; color: var(--muted); text-transform: uppercase; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 11px; width: fit-content; max-width: 100%; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font: inherit; font-size: 14px; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* ratings */
.rate-row { display: flex; flex-direction: column; gap: 6px; }
.rate-row .label { font-size: 14px; color: var(--ink-2); }
.rate { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; max-width: 420px; }
.rate button { height: 34px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; font: inherit; font-size: 14px; color: var(--ink-2); cursor: pointer; padding: 0; }
.rate button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.rate button.in { background: var(--accent-soft); border-color: var(--accent-soft); }
.score { display: inline-flex; gap: 4px; align-items: baseline; font-variant-numeric: tabular-nums; }
.score b { font-size: 17px; }
.scores { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink-2); }
.quote { border-left: 3px solid var(--line); padding: 2px 0 2px 12px; color: var(--ink-2); white-space: pre-wrap; }

/* toast & dialog */
#toasts { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: toast-in .2s ease; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
dialog { border: 0; border-radius: 18px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); width: min(94vw, 480px); max-height: 90vh; }
dialog::backdrop { background: rgba(15, 18, 30, .45); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- admin layout ---------- */
.app { padding-left: 232px; min-height: 100vh; }
.sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: 232px; overflow-y: auto; padding: 22px 14px; border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 10px 18px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 17px; font-weight: 700; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--ink-2); font-weight: 550; text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav a .badge { margin-left: auto; }
.nav .ico { width: 20px; text-align: center; }
.sidebar .spacer { flex: 1; }
.main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.back { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.bottom-nav { display: none; }

@media (max-width: 860px) {
  .app { padding-left: 0; }
  .sidebar { display: none; }
  .main { padding: 18px 16px calc(96px + env(safe-area-inset-bottom, 0px)); }
  h1 { font-size: 22px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; color: var(--muted); padding: 4px 0; position: relative; text-decoration: none; }
  .bottom-nav a .ico { font-size: 19px; line-height: 1.2; }
  .bottom-nav a.on { color: var(--accent); }
  .bottom-nav .badge { position: absolute; top: 0; left: 55%; height: 16px; min-width: 16px; font-size: 10px; padding: 0 4px; background: var(--warn); color: #fff; }
  .card { padding: 15px; }
}

/* ---------- calendar ---------- */
.cal-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.cal-toolbar .title { font-weight: 650; font-size: 16px; margin-right: auto; }
.cal-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }
.cal-legend span { display: inline-flex; gap: 6px; align-items: center; }
.cal-legend i { width: 14px; height: 10px; border-radius: 3px; display: inline-block; }
.cal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cal-head { display: grid; border-bottom: 1px solid var(--line); }
.cal-head div { padding: 8px 4px; text-align: center; font-size: 12px; color: var(--muted); border-left: 1px solid var(--line); }
.cal-head div:first-child { border-left: 0; }
.cal-head b { display: block; font-size: 18px; color: var(--ink); font-weight: 650; }
.cal-head .today b { color: var(--accent); }
.cal-scroll { overflow-y: auto; max-height: calc(100vh - 230px); min-height: 360px; }
.cal-body { display: grid; position: relative; }
.cal-hours { position: relative; }
.cal-hours div { position: absolute; right: 6px; font-size: 11px; color: var(--muted); transform: translateY(-7px); font-variant-numeric: tabular-nums; }
.cal-day { position: relative; border-left: 1px solid var(--line); touch-action: pan-y; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.cal-day .hline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); pointer-events: none; }
.cal-day .hline.half { border-top-style: dashed; opacity: .5; }
.cal-win { position: absolute; left: 0; right: 0; background: var(--ok-soft); border-left: 3px solid var(--ok); pointer-events: none; }
.cal-ev {
  position: absolute; border-radius: 7px; padding: 3px 6px; font-size: 12px; line-height: 1.25; overflow: hidden; cursor: pointer;
  color: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); border: 1px solid rgba(0, 0, 0, .06);
}
.cal-ev b { display: block; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev span { opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.cal-ev.ext { background: var(--ext-soft); color: var(--ink-2); border: 1px solid var(--line); }
.cal-ev.ext.free { opacity: .6; border-style: dashed; }
.cal-ev.req { background: repeating-linear-gradient(135deg, var(--warn-soft), var(--warn-soft) 6px, transparent 6px, transparent 12px), var(--surface); color: var(--warn); border: 1.5px dashed var(--warn); }
.cal-sel { position: absolute; left: 2px; right: 2px; background: var(--accent-soft); border: 2px solid var(--accent); border-radius: 7px; pointer-events: none; font-size: 12px; color: var(--accent); padding: 2px 6px; font-weight: 650; }
.cal-now { position: absolute; left: 0; right: 0; border-top: 2px solid var(--danger); pointer-events: none; z-index: 3; }
.cal-now::before { content: ""; position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.cal-allday { display: grid; border-bottom: 1px solid var(--line); font-size: 11px; }
.cal-allday > div { border-left: 1px solid var(--line); padding: 3px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-allday > div:first-child { border-left: 0; color: var(--muted); justify-content: center; text-align: right; padding-right: 6px; }
.cal-allday span { background: var(--ext-soft); border-radius: 4px; padding: 1px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }

/* availability editor */
.week-row { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.week-row:first-child { border-top: 0; }
.intervals { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.interval { display: inline-flex; align-items: center; gap: 2px; background: var(--ok-soft); color: var(--ok); border-radius: 8px; padding: 4px 4px 4px 10px; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
.interval.closed { background: var(--danger-soft); color: var(--danger); }
.interval button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 15px; padding: 0 6px; opacity: .7; }
.interval button:hover { opacity: 1; }
.time-pair { display: flex; gap: 6px; align-items: center; }
.time-pair input { width: 110px; }
@media (max-width: 560px) { .week-row { grid-template-columns: 1fr; gap: 6px; } }

/* ---------- public pages (student, book, login) ---------- */
.public { max-width: 720px; margin: 0 auto; padding: 28px 16px calc(40px + env(safe-area-inset-bottom, 0px)); }
.public-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.hero { padding: 6px 0 20px; }
.hero h1 { font-size: 28px; }
.center-card { max-width: 400px; margin: 10vh auto 0; }
.pin-input { font-size: 30px; letter-spacing: 14px; text-align: center; font-variant-numeric: tabular-nums; height: 62px; }
.days { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x proximity; }
.day-chip { flex: none; scroll-snap-align: start; width: 68px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 0; text-align: center; cursor: pointer; font: inherit; color: var(--ink); }
.day-chip small { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.day-chip b { display: block; font-size: 20px; }
.day-chip em { display: block; font-style: normal; font-size: 11px; color: var(--ok); }
.day-chip.on { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.day-chip.on small, .day-chip.on em { color: var(--accent-ink); opacity: .85; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.slot { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; height: 44px; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; font-variant-numeric: tabular-nums; }
.slot:hover { border-color: var(--accent); color: var(--accent); }
.slot.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.success { text-align: center; padding: 30px 10px; }
.success .big { font-size: 46px; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.feedback-box { margin-top: 10px; padding: 14px; border-radius: 12px; background: var(--surface-2); display: flex; flex-direction: column; gap: 14px; }
.soft-banner { display: flex; gap: 12px; align-items: center; background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }
.m0 { margin: 0; }
