/* Shared touch-friendly layout for the browser and Telegram WebView. */
[hidden] { display: none !important; }
:root { --tg-top: 0px; --tg-bottom: 0px; }
html { scroll-padding-top: 90px; }
.mobile-nav { display: none; }
.kind-lesson .timeline-content { grid-column: 3 / -1; }
.timeline-content, .task-main, .form-grid > *, .summary-card { min-width: 0; overflow-wrap: anywhere; }
.timeline-content, .task-main { word-break: normal; }
.modal { max-height: min(90dvh, calc(var(--visual-height, 100vh) - 24px)); overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; background: var(--surface); }
/* Native fieldsets and date/time controls must be allowed to shrink on phones. */
.modal :is(form, fieldset, label, .modal-body, .telegram-settings, .telegram-heading > div) { min-width: 0; min-inline-size: 0; max-width: 100%; }
.modal :is(legend, p, small, strong, h2, .button, .text-button) { overflow-wrap: anywhere; }
.modal legend { max-width: 100%; white-space: normal; }
.modal :is(input, select, textarea) { min-width: 0; max-width: 100%; box-sizing: border-box; }
.modal .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
/* Avoid an implicit min-content grid track and iOS native control sizing.
   The inputs keep their native date/time pickers and form validation. */
.settings-modal .native-picker-field { display: flex; flex-direction: column; align-items: stretch; width: 100%; }
.settings-modal .native-picker-field input {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  inline-size: 100%;
  min-width: 0;
  min-inline-size: 0;
  max-width: 100%;
  max-inline-size: 100%;
  box-sizing: border-box;
  margin: 0;
  min-height: 46px;
  padding: 12px;
  font-size: 16px;
}
.telegram-heading { grid-template-columns: 38px minmax(0, 1fr); }
.telegram-connected strong { min-width: 0; overflow-wrap: anywhere; }
.modal-head > div { min-width: 0; }
body:has(dialog[open]) { overflow: hidden; }
.task-class-picker input:focus-visible + span, .schedule-mode input:focus-visible + span { outline: 3px solid var(--purple); outline-offset: 2px; }
.modal-close { flex: 0 0 auto; }
.summary-primary .summary-label, .summary-primary small { color: #eeeaff; }
.in-telegram body { padding-top: var(--tg-top); }
.in-telegram .topbar { top: var(--tg-top); }
.miniapp-entry { display: grid; place-items: center; padding: 24px; min-height: 100dvh; }
.entry-card { width: min(100%, 430px); padding: 32px; }
.entry-card .brand-mark { margin-bottom: 30px; }
.entry-card h1 { line-height: 1.12; }
.entry-card p:not(.eyebrow) { color: var(--ink-soft); line-height: 1.6; }
.entry-link { display: block; text-align: center; text-decoration: none; }

@media (max-width: 680px) {
  html { scroll-padding-top: 80px; overflow-x: clip; }
  body { background: var(--paper); overflow-x: clip; }
  .topbar { height: 60px; padding: 0 16px; backdrop-filter: none; background: var(--paper); }
  .topbar-actions > .button { display: none; }
  .topbar-actions .group-button { display: inline-flex; padding: 8px 11px; min-height: 40px; font-size: 12px; }
  .shell { width: calc(100% - 24px); padding: 22px 0 calc(100px + max(env(safe-area-inset-bottom), var(--tg-bottom))); }
  .day-header { gap: 16px; margin-bottom: 18px; }
  .week-picker { margin-top: 0; padding: 10px; border-radius: 20px; box-shadow: none; }
  .week-picker-head { margin-bottom: 9px; }
  .week-days { gap: 4px; }
  .week-days a { min-height: 56px; border-radius: 13px; }
  .week-days a strong { font-size: 16px; }
  .week-days a span { font-size: 9px; }
  .headman-columns { grid-template-columns: minmax(0, 1fr); }
  .member-request { align-items: flex-start; }
  .important-item, .group-material, .headman-lesson { padding: 13px; }
  h1 { font-size: 32px; line-height: 1.08; }
  h2 { font-size: 23px; }
  .day-subtitle { font-size: 13px; line-height: 1.5; }
  .date-nav { align-self: stretch; justify-content: space-between; box-shadow: none; }
  .date-nav a { min-width: 48px; height: 44px; }
  .date-nav .date-today { flex: 1; max-width: 200px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .summary-card { border-radius: 20px; padding: 15px; min-height: 120px; gap: 8px; box-shadow: none; backdrop-filter: none; }
  .summary-primary { grid-column: 1 / -1; min-height: 140px; }
  .summary-card strong { font-size: 25px; }
  .summary-card p { font-size: 12px; }
  .summary-label { font-size: 9px; letter-spacing: .09em; }
  .summary-card small { font-size: 11px; }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); }
  .panel, .panel-actions, .panel-actions form { min-width: 0; }
  .panel { border-radius: 22px; box-shadow: none; backdrop-filter: none; }
  .timeline-panel, .focus-panel, .tasks-panel { padding: 18px 12px; }
  .panel-head { padding: 0 4px; gap: 16px; margin-bottom: 20px; }
  .panel-actions { flex-wrap: wrap; gap: 6px; }
  .button, .text-button, .mini-button, .session-check, .icon-button, .modal-close, .note-delete { min-height: 44px; }
  .icon-button, .modal-close, .note-delete { min-width: 44px; }
  .timeline-item { grid-template-columns: 43px 8px minmax(0, 1fr); gap: 8px; }
  .timeline::before { left: 54px; }
  .timeline-dot { width: 9px; height: 9px; border-width: 2px; }
  .timeline-time { font-size: 11px; align-self: start; padding-top: 22px; }
  .timeline-content { padding: 13px 12px; margin: 5px 0; border-radius: 14px; }
  .timeline-content h3 { font-size: 15px; line-height: 1.3; }
  .timeline-content p { font-size: 12px; line-height: 1.45; }
  .timeline-controls { grid-column: 3; padding-bottom: 7px; }
  .timeline-controls .session-check { width: 100%; }
  .lesson-notes summary { min-height: 44px; width: 100%; font-size: 12px; flex-wrap: wrap; }
  .note-form textarea, .note-options select { font-size: 16px; max-width: 100%; }
  .note-options select { min-width: 0; width: 100%; min-height: 44px; }
  .note-form-actions { flex-wrap: wrap; }
  .attach-control { min-height: 44px; display: grid; align-content: center; }
  .note-labels { flex-wrap: wrap; }
  .note-card { padding: 9px; }
  .focus-meta { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .focus-meta dd { overflow-wrap: anywhere; }
  .task-row { grid-template-columns: 44px 4px minmax(0, 1fr) 44px; gap: 7px; }
  .task-check { width: 44px; height: 44px; }
  .task-due { display: block; grid-column: 3; grid-row: 2; }
  .task-row > form:last-child { grid-column: 4; grid-row: 1; }
  .task-due span { font-size: 10px; }
  .task-due strong { font-size: 12px; }
  .task-main h3 { line-height: 1.35; }
  .modal { inset-inline: 0; width: 100%; max-width: 100%; margin: auto 0 0; max-height: calc(var(--visual-height, 100dvh) - 12px - var(--tg-top)); border-radius: 24px 24px 0 0; padding-bottom: max(16px, env(safe-area-inset-bottom), var(--tg-bottom)); touch-action: pan-y pinch-zoom; overscroll-behavior-x: none; }
  .modal::backdrop { backdrop-filter: none; }
  .modal form, .modal-body { padding: 22px 18px; }
  .modal-body > form, .modal-body details form, .telegram-settings form { padding: 0; }
  .modal-head { gap: 12px; margin-bottom: 22px; }
  .modal input, .modal select, .modal textarea { font-size: 16px; min-width: 0; }
  .modal input[type="radio"], .modal input[type="checkbox"] { min-height: auto; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
  .form-grid [data-study-field] { grid-column: 1 / -1; }
  .task-class-picker { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .task-class-picker span { min-height: 68px; }
  .task-class-picker b { font-size: 11px; }
  .schedule-mode span { min-height: 44px; display: flex; align-items: center; line-height: 1.4; }
  .telegram-settings { margin: 0 12px 12px; padding: 14px; }
  .modal .notification-toggle { min-height: 56px; gap: 12px; }
  .notification-toggle strong { font-size: 13px; line-height: 1.4; }
  .notification-toggle small { font-size: 12px; line-height: 1.5; }
  .modal .notification-master { padding: 12px; }
  .group-input-row { grid-template-columns: minmax(0, 1fr); }
  .toasts { top: 72px; left: 12px; right: 12px; }
  .toast { font-size: 13px; }
  .mobile-nav { position: fixed; z-index: 15; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 8px 6px calc(8px + max(env(safe-area-inset-bottom), var(--tg-bottom))); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 30px #24213508; }
  .mobile-nav a, .mobile-nav button { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; min-height: 48px; padding: 0; border: 0; background: transparent; text-decoration: none; color: var(--ink-soft); font-size: 10px; font-weight: 700; cursor: pointer; }
  .mobile-nav span { font-size: 22px; line-height: 1; }
  .mobile-nav .mobile-add { color: var(--purple); }
  .mobile-add span { width: 36px; height: 30px; display: grid; place-items: center; border-radius: 11px; background: var(--purple); color: white; }
  .keyboard-open .mobile-nav { display: none; }
  .entry-card { padding: 25px; }
}

@media (max-width: 420px) {
  .settings-modal .form-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-modal input[type="time"], .settings-modal input[type="date"] { min-height: 46px; }
}

[data-tg-theme="dark"] {
  color-scheme: dark;
  --ink: #f0edf8; --ink-soft: #b6b0c7; --paper: #141c28; --surface: #192332;
  --line: #ffffff1c; --purple: #b5a6ff; --shadow: none;
}
[data-tg-theme="dark"] body { background: var(--paper); }
[data-tg-theme="dark"] :is(.topbar, .date-nav, .panel, .modal, .note-card, .kind-task .timeline-content, .session-check, .telegram-connected, .telegram-test-form, .notification-master) { background: var(--surface); border-color: var(--line); }
[data-tg-theme="dark"] :is(.timeline-content, .modal input, .modal textarea, .modal select, .note-form textarea, .note-options select, .task-class-picker span, .schedule-mode span, .telegram-settings, .sync-intro, .sync-status, .notes-empty, .telegram-next, .file-drop) { background: #222e40; border-color: var(--line); }
[data-tg-theme="dark"] .type-lecture .timeline-content { background: #2c2846; }
[data-tg-theme="dark"] .type-practice .timeline-content { background: #382c2b; }
[data-tg-theme="dark"] .type-lab .timeline-content { background: #1b3432; }
[data-tg-theme="dark"] .teacher-line { color: var(--ink-soft); }
[data-tg-theme="dark"] .note-card.is-important { background: #3e3522; border-color: #90783b; }
[data-tg-theme="dark"] .button-dark { background: #7661d9; }
[data-tg-theme="dark"] .task-check { background: var(--surface); border-color: var(--line); }
[data-tg-theme="dark"] .switch-track { background: #526179; border-color: #8794a8; }
[data-tg-theme="dark"] .notification-switch input:checked + .switch-track { background: #8966e0; border-color: #bfa7ff; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
