:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ebe6db;
  --ink: #1d1c19;
  --ink-2: #5e5a52;
  --line: #ddd6c8;
  --accent: #0d6b5f;
  --accent-ink: #ffffff;
  --accent-soft: #d6ebe6;
  --warn: #b4410c;
  --warn-soft: #fbe3d4;
  --danger: #b42318;
  --danger-soft: #fbe0dd;
  --ok: #1f7a3d;
  --ok-soft: #dcefe1;
  --grey-soft: #e6e2da;
  --shadow: 0 1px 2px rgba(40, 32, 20, .06), 0 4px 14px rgba(40, 32, 20, .05);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
  --tabbar: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141614;
    --surface: #1c1f1d;
    --surface-2: #262a27;
    --ink: #ecebe5;
    --ink-2: #a3a39b;
    --line: #2f3430;
    --accent: #5cc4b2;
    --accent-ink: #0d1f1b;
    --accent-soft: #1d3833;
    --warn: #f59a5c;
    --warn-soft: #3b2518;
    --danger: #f2766b;
    --danger-soft: #3d1d1a;
    --ok: #6fcf8d;
    --ok-soft: #183323;
    --grey-soft: #2a2d2b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--ink); }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.center { text-align: center; }
h2, h3 { margin: 0; letter-spacing: -.01em; }
h3 { font-size: 16px; margin-bottom: 10px; }

.screen {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- boot ---------- */
.boot { display: grid; place-items: center; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%; margin: 0 auto;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { display: grid; place-items: center; padding-inline: 16px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 26px 22px 22px; box-shadow: var(--shadow);
}
.login-card img { display: block; margin-bottom: 14px; }
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.login-card > .muted { margin: 4px 0 22px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select, textarea {
  width: 100%; font-size: 17px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px;
}
.field input:focus, textarea:focus, .inline-field input:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.error { color: var(--danger); font-size: 14px; margin: 0 0 12px; }
.hint { color: var(--ink-2); font-size: 13px; margin: 14px 0 0; }

.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
  width: 100%; border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 600;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-secondary { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid currentColor; margin-top: 8px; }
.btn-ghost { background: transparent; color: var(--ink-2); margin-top: 8px; }
.link-btn { border: 0; background: none; color: var(--ink-2); text-decoration: underline; padding: 4px 0; font-size: 14px; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
.offline-banner {
  position: sticky; top: 0; z-index: 10;
  margin-top: calc(-1 * env(safe-area-inset-top));
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--danger); color: #fff; font-size: 14px; font-weight: 600; text-align: center;
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  padding: 10px 8px 6px; padding-top: calc(10px + env(safe-area-inset-top));
  margin-top: calc(-1 * env(safe-area-inset-top));
  background: var(--bg);
}
.offline-banner:not([hidden]) ~ .tab .topbar { top: 38px; margin-top: 0; padding-top: 10px; }
.tab-head { padding: 18px 16px 12px; padding-top: calc(18px + env(safe-area-inset-top)); margin-top: calc(-1 * env(safe-area-inset-top)); }
.tab-head h2 { font-size: 22px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 50%;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.date-btn {
  border: 0; background: transparent; border-radius: 12px; padding: 4px 8px;
  display: flex; flex-direction: column; align-items: center; min-width: 0;
}
.date-btn:active { background: var(--surface-2); }
.date-weekday { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.date-main { font-size: 22px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.date-input { position: absolute; left: 50%; top: 56px; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }

.subbar { display: flex; justify-content: center; padding: 0 16px 6px; min-height: 8px; }
.chip {
  border: 0; border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}

.list { flex: 1; padding: 0 16px 28px; touch-action: pan-y; max-width: 640px; width: 100%; margin: 0 auto; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.lbl { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }

/* ---------- шапка дня ---------- */
.day-head {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.head-note { margin: 8px 0 0; }
.state { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.st-grey { background: var(--grey-soft); color: var(--ink-2); }
.st-orange { background: var(--warn-soft); color: var(--warn); }
.st-green { background: var(--ok-soft); color: var(--ok); }
.st-red { background: var(--danger-soft); color: var(--danger); }
.st-off, .st-future { background: var(--surface-2); color: var(--ink-2); }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.tot { display: flex; flex-direction: column; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.tot-l { font-size: 12px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.tot-v { font-size: 20px; }
.tot-v .sep { color: var(--ink-2); }

/* ---------- урок ---------- */
.lesson {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
  scroll-margin-top: 80px;
}
.lesson.incomplete { border-color: var(--danger); }
.lesson.complete { border-left: 4px solid var(--ok); }
.lesson-head { display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; align-items: center; }
.slot {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.lesson-title { display: flex; flex-direction: column; min-width: 0; }
.lesson-title b { overflow-wrap: anywhere; }
.lesson-status { min-width: 22px; text-align: center; font-weight: 700; }
.lesson-status.saved { color: var(--ok); }
.lesson-status.pending, .lesson-status.saving { color: var(--warn); }
.lesson-status.error { color: var(--danger); }
.lesson-fact { margin: 8px 0 0 42px; font-size: 14px; }
.lesson-body { margin-top: 10px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg-btn { border: 0; background: transparent; border-radius: 8px; padding: 6px 14px; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.seg-btn.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dur-inputs { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; border-radius: 12px; }
.inline-field { display: inline-flex; align-items: center; gap: 6px; }
.inline-field input {
  font-size: 18px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  font-family: var(--mono); font-variant-numeric: tabular-nums;
}
.inline-field input.num { width: 96px; }
.inline-field input[type=time] { width: 148px; }
.suffix, .prefix { color: var(--ink-2); font-weight: 600; }
.dur-preview { margin-top: 6px; min-height: 18px; font-family: var(--mono); }
.field-err { color: var(--danger); font-size: 14px; }
.field-err:empty { display: none; }
.chips-group { margin-top: 10px; border-radius: 12px; }
.chips-group .lbl { margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-opt {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 7px 12px; font-size: 14px;
}
.chip-opt.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.missing { outline: 2px solid var(--danger); outline-offset: 4px; }
.lesson-actions { display: flex; justify-content: flex-end; }

.comment-box textarea { font-size: 16px; resize: vertical; }
.comment-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.fix-btn { margin-top: 4px; }
.rejected { border-color: var(--danger); }
.rej-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.rej-row:first-of-type { border-top: 0; }

.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty-mark { font-size: 40px; line-height: 1; margin-bottom: 10px; opacity: .5; }

/* ---------- таблиці / звіт ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th { text-align: left; font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.tbl tr:last-child td { border-bottom: 0; }
.num-cell { font-weight: 700; color: var(--accent); width: 40px; }
.period { margin: 0 0 10px; }
.cards3 { display: grid; gap: 0; }
.stat .big { font-size: 28px; line-height: 1.2; margin: 2px 0; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--ink-2); font-size: 14px; }
.kv dd { margin: 0; text-align: right; font-size: 14px; }
.subj-head, .subj-row { display: grid; grid-template-columns: 1fr 52px 52px 48px; gap: 6px; align-items: baseline; }
.subj-head { padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.subj-row { padding: 8px 0 10px; border-bottom: 1px solid var(--line); position: relative; font-size: 15px; }
.subj-row .mono { text-align: right; }
.subj-row.unmapped .subj-name { color: var(--warn); }
.subj-row.total { font-weight: 700; border-bottom: 0; }
.subj-name { overflow-wrap: anywhere; }
.bar { grid-column: 1 / -1; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

/* ---------- нижня панель ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbtn {
  border: 0; background: transparent; height: var(--tabbar);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.tabbtn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbtn.on { color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  z-index: 30; max-width: calc(100% - 32px);
}

@media (min-width: 640px) {
  .tabbar { max-width: 640px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
