/* MektepOS design refresh — centralized, reversible visual layer. */
.auth-page { width: 100%; max-width: 480px; margin-inline: auto; }
.auth-page .topbar { gap: 12px; flex-wrap: wrap; }
.auth-page input.form-control { min-height: 44px; }

:root {
  --ds-ink: #202733;
  --ds-muted: #68778b;
  --ds-line: #e4eaf2;
  --ds-canvas: #f4f7fb;
  --ds-surface: #fff;
  --ds-brand: #5146e5;
  --ds-brand-soft: #f0efff;
  --ds-radius: 18px;
  --ds-shadow: 0 8px 24px rgba(26, 39, 61, .055);
}
html:not(.legacy-design), html:not(.legacy-design) body { background: var(--ds-canvas); color: var(--ds-ink); }
html:not(.legacy-design) body { font-family: 'Outfit', 'Montserrat', system-ui, sans-serif; }
html:not(.legacy-design) .app-layout { background: var(--ds-canvas); }
html:not(.legacy-design) .app-main { min-width: 0; }
html:not(.legacy-design) .container-app { max-width: 1680px; }
html:not(.legacy-design) .gemini-sidebar { background: #fff; border-right: 1px solid var(--ds-line); box-shadow: 4px 0 20px rgba(30,41,59,.025); }
html:not(.legacy-design) .sidebar-header { border-bottom: 1px solid #eef1f6; }
html:not(.legacy-design) .sidebar-link { border-radius: 12px; color: #596a82; transition: background .18s ease, color .18s ease, transform .18s ease; }
html:not(.legacy-design) .sidebar-link:hover { background: #f5f6fc; color: var(--ds-brand); transform: translateX(2px); }
html:not(.legacy-design) .sidebar-link.active { background: var(--ds-brand); color: white; box-shadow: 0 6px 14px rgba(81,70,229,.19); }
html:not(.legacy-design) .sidebar-link i { color: inherit; }
html:not(.legacy-design) :is(.card, .glass-card, .premium-card, .stitch-card, .hist-card, .stat-card, .student-card, .teacher-card, .busy-room-card, .rooms-dashboard-card, .curator-progress-card) { border-radius: var(--ds-radius); border-color: var(--ds-line); box-shadow: var(--ds-shadow); }
html:not(.legacy-design) :is(.card, .glass-card, .premium-card, .stitch-card, .hist-card, .stat-card, .student-card, .teacher-card, .busy-room-card, .rooms-dashboard-card, .curator-progress-card):hover { border-color: #d9def7; }
html:not(.legacy-design) :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea, .form-control, .form-select) { border-color: #dce3ed; border-radius: 12px; color: var(--ds-ink); }
html:not(.legacy-design) :is(input, select, textarea, .form-control, .form-select):focus { border-color: #8e88f3; box-shadow: 0 0 0 .2rem rgba(81,70,229,.12); }
html:not(.legacy-design) :is(.btn-primary, .stitch-btn) { background-color: var(--ds-brand); border-color: var(--ds-brand); border-radius: 11px; }
html:not(.legacy-design) :is(.btn-outline-primary, .btn-light) { border-radius: 11px; }
html:not(.legacy-design) .table { --bs-table-border-color: #edf0f5; color: var(--ds-ink); }
html:not(.legacy-design) .table thead th { color: #65748a; font-size: .78rem; font-weight: 700; letter-spacing: .025em; text-transform: uppercase; }
html:not(.legacy-design) .alert { border: 0; border-radius: 14px; }
html:not(.legacy-design) :is(.badge, .class-badge-v2, .lesson-badge-v2) { border-radius: 999px; }
.design-rollback { position: fixed; z-index: 1040; right: 14px; bottom: 14px; padding: 8px 13px; border: 1px solid #d9deea; border-radius: 999px; background: rgba(255,255,255,.94); color: #65748a; box-shadow: 0 3px 12px rgba(30,41,59,.08); font: 500 12px/1.2 'Outfit', sans-serif; cursor: pointer; opacity: .76; transition: opacity .18s, background .18s; }
.design-rollback:hover { opacity: 1; background: white; }
.design-rollback[aria-pressed="true"] { color: var(--ds-brand); border-color: #c9c5ff; background: #f5f4ff; }
html.legacy-design .design-rollback { opacity: 1; }
@media (max-width: 767.98px) { .design-rollback { right: 10px; bottom: calc(68px + env(safe-area-inset-bottom)); } }
@media (prefers-reduced-motion: reduce) { html:not(.legacy-design) *, html:not(.legacy-design) *::before, html:not(.legacy-design) *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; } }

/* Responsive layout fixes for the current platform pages. */
html:not(.legacy-design),
html:not(.legacy-design) body { width: 100%; max-width: 100%; overflow-x: clip; }
html:not(.legacy-design) *,
html:not(.legacy-design) *::before,
html:not(.legacy-design) *::after { box-sizing: border-box; }
html:not(.legacy-design) .app-layout { width: 100%; min-width: 0; max-width: 100%; }
html:not(.legacy-design) .app-main {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
}
html:not(.legacy-design) .app-main > .container-app,
html:not(.legacy-design) .app-main > .wide-container,
html:not(.legacy-design) main > .container-app,
html:not(.legacy-design) main > .wide-container {
  width: 100% !important; min-width: 0 !important; max-width: 100% !important; margin-inline: 0 !important;
}
html:not(.legacy-design) .container-app,
html:not(.legacy-design) .wide-container,
html:not(.legacy-design) .dashboard-canvas,
html:not(.legacy-design) .profile-hub-container { min-width: 0 !important; max-width: 100% !important; }
html:not(.legacy-design) .row,
html:not(.legacy-design) [class*="col-"] { min-width: 0; }
html:not(.legacy-design) :is(.d-flex, .d-inline-flex) > :is(div, section, article, form, nav) { min-width: 0; }
html:not(.legacy-design) :is(.table-responsive, .overflow-x-auto, [class*="overflow-x-auto"], .lesson-ribbon, .filter-ribbon-grades) {
  max-width: 100%; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch;
}
html:not(.legacy-design) :is(img, video, canvas, svg) { max-width: 100%; }
html:not(.legacy-design) :is(h1, h2, h3, h4, h5, h6, p, label, .form-text) { overflow-wrap: anywhere; }
@media (min-width: 768px) and (max-width: 991.98px) {
  html:not(.legacy-design) .gemini-sidebar { width: 76px; }
  html:not(.legacy-design) .gemini-sidebar:not(.collapsed) { width: 260px; }
}
html:not(.legacy-design) .key-submit-layout > [class*="col-"] { min-width: 0; }
html:not(.legacy-design) .key-submit-layout .card,
html:not(.legacy-design) .key-submit-layout .premium-card { min-width: 0; max-width: 100%; }
html:not(.legacy-design) #qrPlaceholder h5,
html:not(.legacy-design) #qrPlaceholder p { overflow-wrap: anywhere; }
html:not(.legacy-design) .free-rooms-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 112px), 1fr)); }
html:not(.legacy-design) .free-room-badge { min-width: 0; min-height: 72px; padding: 10px 6px; }
html:not(.legacy-design) .free-room-number { max-width: 100%; overflow-wrap: anywhere; font-size: clamp(.95rem, 2vw, 1.15rem); }
html:not(.legacy-design) .free-room-sub { justify-content: center; flex-wrap: wrap; text-align: center; }
html:not(.legacy-design) .busy-rooms-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
html:not(.legacy-design) .busy-card-header { min-width: 0; gap: 8px; }
html:not(.legacy-design) .busy-room-title,
html:not(.legacy-design) .busy-subject-title,
html:not(.legacy-design) .busy-teacher-name { min-width: 0; overflow-wrap: anywhere; }
html:not(.legacy-design) .analytics-grid-2col > * { min-width: 0; }
html:not(.legacy-design) canvas { max-width: 100%; }
@media (max-width: 1199.98px) {
  html:not(.legacy-design) .key-submit-layout > [class*="col-"] { flex: 0 0 100%; max-width: 100%; }
}
@media (max-width: 575.98px) {
  html:not(.legacy-design) .dashboard-canvas { padding-left: .25rem !important; padding-right: .25rem !important; }
  html:not(.legacy-design) .key-submit-layout .card { padding: 1rem !important; }
  html:not(.legacy-design) .rooms-dashboard-card { padding: 14px; }
  html:not(.legacy-design) .free-rooms-grid { grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 8px; }
  html:not(.legacy-design) .busy-rooms-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 991.98px) {
  html:not(.legacy-design) main.app-main { padding-bottom: 80px !important; }
  html:not(.legacy-design) :is(.btn-group, .input-group, .d-flex.flex-column.flex-sm-row) { min-width: 0; max-width: 100%; }
  html:not(.legacy-design) .app-main { width: 100%; }
}

/* ==========================================================================
   Design tokens v2 — единая шкала радиусов, высот, семантических цветов.
   Старые переменные app.css (--primary, --radius и т.д.) переведены в алиасы.
   ========================================================================== */
:root {
  --ds-radius: 16px;           /* карточки, панели */
  --ds-radius-md: 12px;        /* кнопки, поля, чипы */
  --ds-radius-sm: 8px;         /* мелкие элементы */
  --ds-radius-pill: 999px;     /* бейджи, капсулы */
  --ds-control-h: 44px;        /* основные кнопки и поля */
  --ds-control-h-sm: 36px;     /* кнопки в таблицах и плотных блоках */
  --ds-text-min: .75rem;       /* минимальный размер текста: 12px */

  --ds-success: #0f8a5f;  --ds-success-soft: #e7f6ef;
  --ds-warning: #b45309;  --ds-warning-soft: #fff4dc;
  --ds-danger:  #d92d4a;  --ds-danger-soft:  #fdeaee;
  --ds-info:    #0369a1;  --ds-info-soft:    #e6f3fb;
}

/* Алиасы старой системы → новые токены. Только в новом виде: в «старом виде»
   (html.legacy-design) действуют прежние значения из app.css. */
html:not(.legacy-design) {
  --primary: var(--ds-brand);
  --primary-soft: var(--ds-brand-soft);
  --text: var(--ds-ink);
  --muted: var(--ds-muted);
  --secondary: var(--ds-muted);
  --secondary-text: var(--ds-muted);
  --border: var(--ds-line);
  --bg: var(--ds-canvas);
  --card: var(--ds-surface);
  --success: var(--ds-success);
  --warning: var(--ds-warning);
  --danger: var(--ds-danger);
  --radius: var(--ds-radius);
}

/* Доступность: skip-link и фокус */
.skip-link {
  position: fixed; z-index: 2000; top: 8px; left: 8px;
  padding: 10px 16px; border-radius: var(--ds-radius-md);
  background: var(--ds-brand); color: #fff; font-weight: 600; text-decoration: none;
  transform: translateY(-160%); transition: transform .18s ease;
}
.skip-link:focus { transform: translateY(0); color: #fff; outline: 3px solid rgba(81,70,229,.35); outline-offset: 2px; }
html:not(.legacy-design) :is(a, button, [role="button"], summary, .btn, .sidebar-link):focus-visible {
  outline: 3px solid rgba(81,70,229,.45); outline-offset: 2px;
}

/* Кнопки: две высоты вместо восьми */
html:not(.legacy-design) .btn { min-height: var(--ds-control-h); border-radius: var(--ds-radius-md); display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
html:not(.legacy-design) .btn.btn-sm { min-height: var(--ds-control-h-sm); padding-inline: .75rem; }
html:not(.legacy-design) .btn.rounded-circle { min-height: 0; }   /* круглые иконочные кнопки задают размер сами */
html:not(.legacy-design) :is(.btn-primary, .stitch-btn, .btn-outline-primary, .btn-light, .btn-outline-success, .btn-outline-secondary) { border-radius: var(--ds-radius-md); }
html:not(.legacy-design) :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=range]), select, .form-control, .form-select) { min-height: var(--ds-control-h-sm); border-radius: var(--ds-radius-md); }
html:not(.legacy-design) :is(.auth-page, form) :is(input.form-control, select.form-select) { min-height: var(--ds-control-h); }

/* Радиусы карточек и панелей — одна величина */
html:not(.legacy-design) :is(.analytics-header-card, .page-header-card, .generator-hero, .analytics-card, .stat-card, .kpi-card) { border-radius: var(--ds-radius); }

/* Единая шапка страницы: общий вид для трёх прежних вариантов */
html:not(.legacy-design) :is(.analytics-header-card, .page-header-card, .generator-hero) {
  background: var(--ds-surface); border: 1px solid var(--ds-line); box-shadow: var(--ds-shadow); color: var(--ds-ink);
}
html:not(.legacy-design) :is(.analytics-header-card, .page-header-card, .generator-hero) :is(h1, h2, h4) {
  font-size: clamp(1.25rem, 1rem + 1vw, 1.6rem); font-weight: 700; letter-spacing: -.01em; line-height: 1.2; margin: 0;
}
html:not(.legacy-design) :is(.analytics-header-card, .page-header-card) :is(.avatar-circle, .rounded-4.text-white) {
  width: 48px !important; height: 48px !important; border-radius: var(--ds-radius-md) !important;
  background: var(--ds-brand) !important; box-shadow: none !important;
}

/* Мелкий текст не меньше 12px */
html:not(.legacy-design) .badge { font-size: max(var(--ds-text-min), .75em); }
html:not(.legacy-design) :is(.small, small, .form-text) { font-size: max(var(--ds-text-min), .875em); }

/* Подписи навигации в раскрытой боковой панели читаемее, группы разделены */
html:not(.legacy-design) .gemini-sidebar:not(.collapsed) .sidebar-link { min-height: 44px; }

/* ==========================================================================
   Переключатель оформления (работает во всех темах)
   ========================================================================== */
.theme-switcher { position: relative; width: 100%; }
.theme-switcher .theme-toggle { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; font: inherit; }
.theme-menu { position: fixed; z-index: 1100; min-width: 200px; padding: 6px; border: 1px solid #d9deea; border-radius: 16px; background: rgba(255,255,255,.97); box-shadow: 0 10px 30px rgba(15,23,42,.14); color: #202733; }
.theme-menu[hidden] { display: none; }
.theme-option { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 8px 12px; border: 0; border-radius: 10px; background: transparent; color: inherit; font: 500 14px/1.2 'Outfit', system-ui, sans-serif; text-align: left; cursor: pointer; }
.theme-option:hover { background: rgba(15,23,42,.06); }
.theme-option[aria-pressed="true"] { background: rgba(81,70,229,.12); font-weight: 700; }
.theme-option[aria-pressed="true"]::after { content: "✓"; margin-left: auto; }
/* Сенсорные экраны и телефоны: цели нажатия не меньше 44px (Apple HIG, WCAG 2.5.5) */
@media (pointer: coarse), (max-width: 767.98px) {
  html:not(.legacy-design) .btn,
  html:not(.legacy-design) .btn.btn-sm { min-height: 44px; }
  html:not(.legacy-design) .btn.btn-sm.rounded-circle,
  html:not(.legacy-design) .btn.rounded-circle.p-0 { min-width: 44px; min-height: 44px; }
  html:not(.legacy-design) :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=range]), select, .form-control, .form-select) { min-height: 44px; }
  .design-rollback, .theme-option { min-height: 44px; }
}
.theme-swatch { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 1px solid rgba(15,23,42,.15); }
.theme-swatch[data-swatch="classic"] { background: linear-gradient(135deg, #4f46e5 50%, #f1f5f9 50%); }
.theme-swatch[data-swatch="modern"] { background: linear-gradient(135deg, #5146e5 50%, #f4f7fb 50%); }
.theme-swatch[data-swatch="apple"] { background: linear-gradient(135deg, #0071e3 50%, #f5f5f7 50%); }
.theme-options-inline { display: grid; gap: 4px; padding: 8px; }

/* Шапка бокового меню: в развёрнутой панели логотип и название, в узкой — только знак логотипа */
.gemini-sidebar .sidebar-header { padding-left: 20px; }
.gemini-sidebar.collapsed .sidebar-header { justify-content: center; padding: 0; }
.gemini-sidebar.collapsed .sidebar-header .brand-logo { display: flex !important; justify-content: center; }
.gemini-sidebar.collapsed .sidebar-header .brand-logo img { width: 38px; height: 38px; }

/* Круглая кнопка сворачивания на краю панели (наполовину выступает за край, как в примере) */
.sidebar-edge-toggle { display: none; }
@media (min-width: 992px) {
  .sidebar-edge-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 16px; left: 244px; z-index: 1045;
    width: 32px; height: 32px; padding: 0;
    border: 1px solid #e2e8f0; border-radius: 50%;
    background: #fff; color: #475569;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .14);
    cursor: pointer;
    transition: left .3s cubic-bezier(.2, 0, 0, 1), color .2s ease;
  }
  .gemini-sidebar.collapsed ~ .sidebar-edge-toggle { left: 56px; }
  .sidebar-edge-toggle:hover { color: var(--ds-brand, #4f46e5); }
  .sidebar-edge-toggle i { transition: transform .3s ease; }
  .gemini-sidebar.collapsed ~ .sidebar-edge-toggle i { transform: rotate(180deg); }
}
@media (prefers-reduced-motion: reduce) { .sidebar-edge-toggle, .sidebar-edge-toggle i { transition: none; } }

/* Группы бокового меню (раскрываются по клику; в узкой панели с иконками заголовков нет) */
.sidebar-group + .sidebar-group { margin-top: 4px; }
.sidebar-group:not(:has(.sidebar-link)) { display: none; }
.sidebar-group-head { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 8px 14px; border: 0; border-radius: 12px; background: transparent; color: #64748b; font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.sidebar-group-head:hover { background: rgba(15, 23, 42, .05); }
.sidebar-group-head > i:first-child { font-size: 1.15rem; }
.sidebar-group-chevron { margin-left: auto; transition: transform .2s ease; }
.sidebar-group-head[aria-expanded="false"] .sidebar-group-chevron { transform: rotate(-90deg); }
.sidebar-group-body { padding-left: 6px; }
.gemini-sidebar.collapsed .sidebar-group-head { display: none; }
.gemini-sidebar.collapsed .sidebar-group-body { display: block !important; padding-left: 0; }
.gemini-sidebar.collapsed .sidebar-group + .sidebar-group { margin-top: 8px; padding-top: 8px; border-top: 1px solid #e5e7eb; }
@media (prefers-reduced-motion: reduce) { .sidebar-group-chevron { transition: none; } }
