/* Палитры: data-palette на <html> (indigo по умолчанию), тёмная тема — класс .dark.
   Выбор хранится в CloudStorage Telegram, светлая/тёмная по умолчанию — как в Telegram. */
:root {
  --bg: #F4F6FA; --surface: #FFFFFF; --line: #E2E6EF; --text: #0F172A; --muted: #5B6475;
  --track: #E2E6EF; --check: #C3C9D6; --ok: #16A34A; --danger: #C62828;
  --accent: #4F46E5; --on-accent: #FFFFFF;
  --hero: #1E1B4B; --hero-border: transparent; --hero-muted: #C7D2FE; --hero-line: #4C4A8A;
  --hero-btn: #FFFFFF; --hero-btn-text: #1E1B4B; --hero-warn: #FFD8A8;
  --late-bg: #FFF4EC; --late-line: #FBD3B8; --late-icon: #C2410C; --late-icon-fg: #FFFFFF; --late-text: #9A3412;
  --pts: #DDF5E6; --on-pts: #17663A;
  --st-bg: #FFF1E0; --st-text: #9A4A06; --info-bg: #E3EDFB; --info: #1F4F8A;
  --scrim: rgba(15, 23, 42, .45);
  color-scheme: light;
}
:root.dark {
  --bg: #0E1116; --surface: #171B22; --line: #232935; --text: #F2F4F7; --muted: #9AA3B2;
  --track: #262C36; --check: #4A5363; --ok: #4ADE80; --danger: #F87171;
  --accent: #C6F36B; --on-accent: #0E1116;
  --hero: #1C2230; --hero-border: #2E3646; --hero-muted: #A9B4C6; --hero-line: #3A4354;
  --hero-btn: #C6F36B; --hero-btn-text: #0E1116;
  --late-bg: #2A1A10; --late-line: #5A3216; --late-icon: #FF9F5A; --late-icon-fg: #2A1A10; --late-text: #FFC69C;
  --pts: #1E3A2A; --on-pts: #9BE3B4;
  --st-bg: #3A2A14; --st-text: #FFC69C; --info-bg: #1B2C42; --info: #A9CBF2;
  --scrim: rgba(0, 0, 0, .6);
  color-scheme: dark;
}
:root[data-palette="mint"] {
  --bg: #F1F7F5; --line: #DCE8E4; --accent: #0F766E;
  --hero: #0B3B36; --hero-muted: #A7E3D6; --hero-line: #2A5F58; --hero-btn-text: #0B3B36;
}
:root.dark[data-palette="mint"] {
  --bg: #0B1312; --surface: #121C1A; --line: #1E2B28; --accent: #5EEAD4; --on-accent: #062B27;
  --hero: #10231F; --hero-border: #1F3D37; --hero-muted: #9CCFC3; --hero-line: #2B4A44;
  --hero-btn: #5EEAD4; --hero-btn-text: #062B27;
}
:root[data-palette="sunset"] {
  --bg: #FBF5F2; --line: #F0E2DB; --accent: #C2410C;
  --hero: #3B1426; --hero-muted: #F5C2D3; --hero-line: #6A3550; --hero-btn-text: #3B1426;
  --late-bg: #FDECEC; --late-line: #F7C6C6; --late-icon: #B91C1C; --late-text: #991B1B;
}
:root.dark[data-palette="sunset"] {
  --bg: #140E10; --surface: #1D1518; --line: #2C2125; --accent: #FB923C; --on-accent: #2A0F05;
  --hero: #2A1420; --hero-border: #46233A; --hero-muted: #E9B7C9; --hero-line: #5A3049;
  --hero-btn: #FB923C; --hero-btn-text: #2A0F05;
  --late-bg: #2B1214; --late-line: #5C2328; --late-icon: #F87171; --late-icon-fg: #2B1214; --late-text: #FCA5A5;
}
:root[data-palette="ocean"] {
  --bg: #F1F6FA; --line: #DCE6EE; --accent: #0369A1;
  --hero: #082F49; --hero-muted: #A5D8F3; --hero-line: #24506E; --hero-btn-text: #082F49;
}
:root.dark[data-palette="ocean"] {
  --bg: #0A1219; --surface: #111B24; --line: #1C2A36; --accent: #38BDF8; --on-accent: #04202F;
  --hero: #0C2233; --hero-border: #17384F; --hero-muted: #9CC9E4; --hero-line: #24506E;
  --hero-btn: #38BDF8; --hero-btn-text: #04202F;
}
:root[data-palette="graphite"] {
  --bg: #F5F5F4; --line: #E4E4E1; --accent: #18181B;
  --hero: #18181B; --hero-muted: #D4D4D8; --hero-line: #3F3F46; --hero-btn: #FACC15; --hero-btn-text: #18181B;
}
:root.dark[data-palette="graphite"] {
  --bg: #0F0F11; --surface: #18181B; --line: #27272A; --accent: #FACC15; --on-accent: #1A1A1A;
  --hero: #1F1F23; --hero-border: #2E2E33; --hero-muted: #B4B4BC; --hero-line: #3F3F46;
  --hero-btn: #FACC15; --hero-btn-text: #1A1A1A;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
/* Листается только вверх-вниз: что бы ни вылезло по ширине, вбок страница не едет */
html, body { overflow-x: hidden; max-width: 100%; overscroll-behavior-x: none; }
/* Длинные слова и ссылки без пробелов переносим (word-wrap — для Edge 18, overflow-wrap — для остальных) */
body { word-wrap: break-word; overflow-wrap: break-word; }
body { font: 15px/1.4 "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; color: inherit; }
[hidden] { display: none !important; }
.display { font-family: "Unbounded", "Onest", sans-serif; }
.screen { min-height: 100vh; padding: 16px 16px 96px; padding: 16px 16px calc(96px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 16px; }
/* Telegram Desktop открывает приложение в широком окне — держим колонку шириной с телефон */
.screen, .sheet-body { max-width: 560px; margin: 0 auto; width: 100%; }
html { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
#edit-screen { padding-bottom: 24px; padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); gap: 0; }

/* шапка */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hello { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.muted { color: var(--muted); font-size: 13px; }
.hello h1 { margin: 0; font-size: 22px; line-height: 1.15; font-weight: 700; letter-spacing: -.01em; }
.hello .pts { align-self: flex-start; white-space: normal; }
.top-right { display: flex; align-items: center; gap: 8px; flex: none; }
.ring { display: block; }
.ring .bg { stroke: var(--track); } .ring .fg { stroke: var(--accent); }
.ring text { fill: var(--text); font: 700 13px "Onest", sans-serif; }
/* Кнопки — без display:flex: Edge 18 (AyuGram, старый Telegram Desktop) не умеет flex внутри <button>, и они разъезжаются */
.icon-btn { width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); display: inline-block; text-align: center; line-height: 42px; font-size: 20px; cursor: pointer; padding: 0; }

/* неделя */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day { height: 64px; min-width: 0; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); display: block; text-align: center; padding: 6px 0 0; cursor: pointer; }
.day span { display: block; }
.day .wd { font-size: 11px; line-height: 14px; color: var(--muted); }
.day .n { font-size: 17px; line-height: 22px; font-weight: 600; margin-top: 1px; }
.day .dots { font-size: 11px; font-weight: 700; height: 13px; line-height: 13px; margin-top: 1px; color: var(--accent); letter-spacing: 1px; }
.day.today { border-color: var(--accent); }
.day.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.day.on .wd, .day.on .dots { color: var(--on-accent); }

/* ближайший дедлайн */
.hero { background: var(--hero); border: 1px solid var(--hero-border); color: #FFFFFF; border-radius: 22px; padding: 18px; display: flex; flex-direction: column; gap: 12px; cursor: pointer; }
.hero-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kicker { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--hero-muted); }
.hero-title { font-size: 20px; font-weight: 600; line-height: 1.25; word-break: break-word; }
.hero-sub { font-size: 14px; color: var(--hero-muted); }
.count { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.count b { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.count span { font-size: 14px; color: var(--hero-muted); }
.hero-warn { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--hero-warn); }
.hero-actions { display: flex; gap: 8px; }
.hero-actions button { flex: 1 1 0; min-width: 0; height: 46px; border-radius: 14px; font-weight: 600; font-size: 15px; cursor: pointer; }
.hero-actions .primary { border: 0; background: var(--hero-btn); color: var(--hero-btn-text); }
.hero-actions .ghost { border: 1px solid var(--hero-line); background: transparent; color: #FFFFFF; }
.hero .pts { background: #DDF5E6; color: #17663A; }

/* просрочено */
.late { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 18px; background: var(--late-bg); border: 1px solid var(--late-line); cursor: pointer; }
.late-icon { flex: none; width: 38px; height: 38px; border-radius: 12px; background: var(--late-icon); color: var(--late-icon-fg); display: flex; align-items: center; justify-content: center; font-size: 20px; }
.late-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.late-body b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.late-body span { font-size: 13px; color: var(--late-text); }
.late .chk { border-color: var(--late-icon); }
.late-wrap { display: flex; flex-direction: column; gap: 8px; }

/* фильтр по предмету */
.chips { display: block; white-space: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -ms-overflow-style: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-block; vertical-align: top; height: 36px; line-height: 34px; margin-right: 8px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 500; white-space: nowrap; cursor: pointer; }
.chip:last-child { margin-right: 0; }
.chip .dot { display: inline-block; vertical-align: middle; margin: -2px 6px 0 0; }
.chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }

/* дни */
.group { display: grid; grid-template-columns: 54px minmax(0, 1fr); column-gap: 12px; }
.glabel { display: flex; flex-direction: column; gap: 2px; padding-top: 6px; min-width: 0; }
.glabel b { font-size: 14px; font-weight: 700; }
.glabel.now b { color: var(--accent); }
.glabel span { font-size: 12px; color: var(--muted); }
.gitems { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.card:active { filter: brightness(.97); }
.cbody { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.crow { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.subj { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); min-width: 0; }
.subj span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.time { flex: none; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ctitle { font-size: 15px; font-weight: 500; line-height: 1.3; word-break: break-word; overflow-wrap: anywhere; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tags:empty { display: none; }
.done .ctitle { text-decoration: line-through; color: var(--muted); }
.done .pts { opacity: .5; }

.chk { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--check); background: transparent; display: block; text-align: center; line-height: 22px; font-size: 15px; color: transparent; padding: 0; cursor: pointer; position: relative; }
.chk::after { content: ""; position: absolute; inset: -9px; } /* палец попадает легче */
.chk.on { background: var(--ok); border-color: var(--ok); color: #FFFFFF; }

.pts { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 8px; background: var(--pts); color: var(--on-pts); white-space: nowrap; font-variant-numeric: tabular-nums; }
.st { font-size: 12px; padding: 3px 9px; border-radius: 8px; white-space: nowrap; }
.st-warn { background: var(--st-bg); color: var(--st-text); } .st-info { background: var(--info-bg); color: var(--info); } .st-ok { background: var(--pts); color: var(--on-pts); }

.empty, .error { margin: 32px 8px; text-align: center; display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
.empty i { font-size: 34px; color: var(--accent); } .empty b { color: var(--text); font-weight: 600; }
.error { color: var(--danger); }
.fab-wrap { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px; padding: 12px max(16px, env(safe-area-inset-left, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--bg); border-top: 1px solid var(--line); z-index: 5; }
.main { width: 100%; height: 50px; border: 0; border-radius: 16px; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 16px; cursor: pointer; display: block; text-align: center; line-height: 50px; padding: 0 12px; }
.main .ti { margin-right: 6px; }
.main:disabled { opacity: .6; }
.fab-wrap .main { max-width: 528px; margin: 0 auto; }

/* выбор оформления */
.sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; background: var(--scrim); }
.sheet-body { width: 100%; background: var(--bg); border-radius: 24px 24px 0 0; padding: 20px 16px; padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 16px; max-height: 90vh; overflow-y: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet h3 { margin: 0; font-size: 13px; font-weight: 500; color: var(--muted); }
.palettes { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.pal { border: 2px solid var(--line); background: var(--surface); border-radius: 16px; padding: 10px 6px; display: block; text-align: center; font-size: 13px; cursor: pointer; }
.pal.on { border-color: var(--accent); }
.sw { display: block; width: 40px; height: 40px; margin: 0 auto 8px; border-radius: 50%; position: relative; overflow: hidden; }
.sw i { position: absolute; inset: 0 0 0 50%; }
.modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.modes button { height: 40px; border: 0; border-radius: 10px; background: transparent; font-size: 14px; font-weight: 500; cursor: pointer; }
.modes button.on { background: var(--accent); color: var(--on-accent); }

/* карточка задания */
h1.edit-h { font-size: 20px; font-weight: 700; margin: 4px 0 16px; }
.fld { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.fld label { font-size: 13px; color: var(--muted); }
input { height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 0 12px; font: 16px "Onest", sans-serif; width: 100%; min-width: 0; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
/* iOS рисует дату и время своим элементом с собственной минимальной шириной — он вылезает из колонки */
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; display: block; line-height: 44px; text-align: left; }
input::-webkit-date-and-time-value { text-align: left; margin: 0; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.row2 .fld { min-width: 0; }
.inline { display: flex; gap: 10px; align-items: center; } .inline input { width: 130px; flex: none; }
.hint { font-size: 12px; color: var(--muted); }
.form-error { color: var(--danger); font-size: 14px; min-height: 1px; margin-bottom: 8px; }
.stbox { border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 12px 14px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.sthead { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.strow { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); }
.strow b { font-weight: 500; color: var(--text); text-align: right; min-width: 0; word-break: break-word; }
.note { font-size: 13px; display: flex; gap: 7px; }
.note.ok { color: var(--on-pts); } .note.warn { color: var(--st-text); } .note.muted { color: var(--muted); }
.openlink { display: flex; align-items: center; gap: 8px; padding: 14px; border-radius: 16px; background: var(--hero); color: #FFFFFF; text-decoration: none; font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.openlink .ti-external-link { margin-left: auto; color: var(--hero-muted); }
.actions { display: flex; flex-direction: column; gap: 12px; }
.danger-link, .link { background: none; border: 0; color: var(--danger); font-size: 15px; padding: 10px; cursor: pointer; }
.link { color: var(--accent); padding: 4px 0; }
.dark .link { color: var(--accent); }
.dev-bar { margin-bottom: 4px; }
/* Никаких анимаций: при зуме окна в Telegram Desktop они «пружинят» */
*, *::before, *::after { transition: none !important; animation: none !important; }

/* ---------- Старые встроенные браузеры ----------
   AyuGram и старый Telegram Desktop на Windows без WebView2 открывают приложение в Edge 18 (EdgeHTML).
   Там нет inset, env(), max(), gap во flex и gap в grid (только grid-gap). Ниже — те же значения
   старыми свойствами: современные браузеры считают их синонимами, ничего не меняется. */
.sheet { top: 0; right: 0; bottom: 0; left: 0; }
.sw i { top: 0; right: 0; bottom: 0; left: 50%; }
.chk::after { top: -9px; right: -9px; bottom: -9px; left: -9px; }
.week { grid-gap: 6px; } .row2 { grid-gap: 10px; }
.palettes { grid-gap: 8px; } .modes { grid-gap: 4px; } .group { grid-column-gap: 12px; }

/* Нет gap во flex (класс ставит проверка в index.html) — отступы полями */
.no-gap .screen > * + *, .no-gap #list > * + *, .no-gap .sheet-body > * + * { margin-top: 16px; }
.no-gap .hero > * + *, .no-gap .actions > * + * { margin-top: 12px; }
.no-gap .hero-actions > * + * { margin-left: 8px; margin-top: 0; }
.no-gap .hello > * + *, .no-gap .gitems > * + *, .no-gap .late-wrap > * + *, .no-gap .cbody > * + *,
.no-gap .fld > * + *, .no-gap .stbox > * + *, .no-gap .empty > * + *, .no-gap .error > * + * { margin-top: 6px; }
.no-gap .glabel > * + *, .no-gap .late-body > * + * { margin-top: 2px; }
.no-gap .late > * + *, .no-gap .card > * + *, .no-gap .top > * + * { margin-left: 12px; }
.no-gap .top-right > * + *, .no-gap .hero-head > * + *, .no-gap .count > * + *, .no-gap .hero-warn > * + *,
.no-gap .crow > * + *, .no-gap .inline > * + *, .no-gap .note > * + *, .no-gap .openlink > * + * { margin-left: 8px; }
.no-gap .subj > * + * { margin-left: 6px; }
.no-gap .tags > * { margin: 0 6px 6px 0; }
.no-gap #edit-screen > * + * { margin-top: 0; }
