/*
  Mobile / tablet adaptations ONLY.
  Edit THIS file for phone and tablet layouts (≤860px).
  Desktop visuals belong in styles.css — never mix breakpoints there.

  Linked with media="(max-width: 860px)" so desktop is unaffected.
*/

/* —— Tablet and below (≤860px) —— */
@media (max-width: 860px) {
  :root {
    /* Fixed chrome: scrollports stay between header and tap-bar */
    --mobile-header-h: calc(56px + env(safe-area-inset-top, 0px));
    --mobile-tabbar-h: calc(78px + env(safe-area-inset-bottom, 0px));
    --mobile-tabbar-clearance: calc(88px + env(safe-area-inset-bottom, 0px));
  }

  html,
  body {
    scroll-padding-top: var(--mobile-header-h);
    scroll-padding-bottom: var(--mobile-tabbar-clearance);
  }

  /* Lighter background for mobile/tablet — do not touch desktop styles.css */
  .bg {
    background: url("./assets/bg-library-mobile.jpg") center center / cover no-repeat;
  }

  /* Profile: scrollport sits strictly between fixed header and tap-bar */
  body.page-profile {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  body.page-profile .profile-stage {
    /* desktop .profile-stage { min-height: 100vh } must not win over max-height */
    min-height: 0 !important;
    margin-top: var(--mobile-header-h);
    height: calc(100dvh - var(--mobile-header-h) - var(--mobile-tabbar-h)) !important;
    max-height: calc(100dvh - var(--mobile-header-h) - var(--mobile-tabbar-h)) !important;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    box-sizing: border-box;
    padding-top: 12px !important;
    padding-bottom: 20px !important;
  }

  body.page-profile .profile-panel.is-active {
    padding-bottom: 12px;
  }

  body.page-profile .profile-panel .favorites-list,
  body.page-profile .profile-panel .points-ledger,
  body.page-profile .profile-panel[data-profile-panel="edits"] {
    padding-bottom: 8px;
    margin-bottom: 0;
  }

  /* Fixed header plaque: no extra fill, always above page content */
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 210;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 0;
    gap: 10px;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    background: transparent;
    pointer-events: none;
  }

  .topbar-left,
  .topbar .brand,
  .topbar .brand-logo,
  .topbar .brand-title {
    pointer-events: auto;
  }

  .topbar-left {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    min-width: 0;
    width: 100%;
    padding-right: 0;
  }

  .brand {
    font-size: 16px;
    gap: 8px;
    min-width: 0;
  }

  .brand-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }

  .theme-switch {
    position: fixed;
    /* Nudge down to optically center with 32px header logo */
    top: calc(14px + env(safe-area-inset-top, 0px));
    right: 16px;
    z-index: 50000;
    margin: 0;
    line-height: 0;
  }

  .theme-switch-track {
    width: 88px;
    height: 30px;
  }

  .theme-switch-thumb {
    width: 22px;
    height: 22px;
    top: 3px;
    left: 3px;
    transform: translateX(60px);
  }

  .theme-switch.is-light .theme-switch-thumb,
  html[data-theme="light"] .theme-switch .theme-switch-thumb {
    transform: translateX(0);
  }

  .theme-switch-text {
    font-size: 10px;
  }

  .theme-switch-text-dark {
    left: 7px;
  }

  .theme-switch-text-light {
    right: 7px;
  }

  /* Mobile-only: action tiles as bottom footer (desktop keeps topbar). */
  .topbar .auth-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 200;
    width: 100%;
    height: var(--mobile-tabbar-h);
    margin: 0;
    padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    justify-content: center;
    align-items: stretch;
    background: linear-gradient(
      to top,
      rgba(5, 5, 5, 0.92) 0%,
      rgba(5, 5, 5, 0.78) 70%,
      rgba(5, 5, 5, 0) 100%
    );
    pointer-events: none;
  }

  .topbar .auth-actions .user-actions {
    pointer-events: auto;
    height: 100%;
  }

  html[data-theme="light"] .topbar .auth-actions {
    background: linear-gradient(
      to top,
      rgba(232, 230, 225, 0.96) 0%,
      rgba(232, 230, 225, 0.88) 70%,
      rgba(232, 230, 225, 0) 100%
    );
  }

  .topbar .user-actions {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    justify-content: stretch;
    align-items: stretch;
    gap: 8px;
  }

  /* Mobile footer: Главная instead of Выйти; logout lives in Profile settings */
  .topbar .user-actions > .logout-btn {
    display: none !important;
  }

  /* Tap-bar (regular user): Главная | Профиль | Поддержка — equal width */
  .topbar .user-actions .home-link {
    display: inline-flex;
    order: 1;
  }

  .topbar .user-actions .profile-link {
    order: 2;
  }

  .topbar .user-actions .support-widget-btn {
    order: 3;
  }

  .topbar .user-actions .admin-link {
    order: 4;
  }

  .topbar .user-actions .vverh-app-link {
    display: none !important;
  }

  /* Non-admins: three equal taps across the bar */
  body:not([data-role="admin"]) .topbar .user-actions > .admin-link {
    display: none !important;
  }

  body:not([data-role="admin"]) .topbar .user-actions > .home-link,
  body:not([data-role="admin"]) .topbar .user-actions > .profile-link,
  body:not([data-role="admin"]) .topbar .user-actions > .support-widget-btn {
    flex: 1 1 0;
    max-width: none;
  }

  .profile-settings-section .profile-logout-btn {
    width: min(100%, 320px);
    justify-content: center;
  }

  .topbar .auth-tile {
    flex: 1 1 0;
    max-width: none;
    min-width: 0;
    min-height: 58px;
    padding: 8px 6px;
    border-radius: 12px;
    font-size: 12px;
    gap: 4px;
  }

  /* Active tap-bar tile: light-blue fill in both themes */
  .topbar .auth-tile.is-active,
  html[data-theme="light"] .topbar .auth-tile.is-active {
    color: #0f2744;
    background: #c9ddf8;
    border-color: rgba(96, 150, 220, 0.45);
    box-shadow: none;
  }

  .topbar .auth-tile.is-active .auth-tile-icon,
  .topbar .auth-tile.is-active .auth-tile-label,
  html[data-theme="light"] .topbar .auth-tile.is-active .auth-tile-icon,
  html[data-theme="light"] .topbar .auth-tile.is-active .auth-tile-label {
    color: #0f2744;
  }

  .topbar .auth-tile-icon {
    width: 22px;
    height: 22px;
  }

  .topbar .auth-tile-icon svg {
    width: 15px;
    height: 15px;
  }

  .topbar .auth-tile-label {
    line-height: 1.15;
    text-align: center;
  }

  /* Home scrollport always — do not wait for is-authenticated (avoids layout jump). */
  body:not(.page-profile):not(.page-admin) {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  body:not(.page-profile):not(.page-admin) .stage {
    margin-top: var(--mobile-header-h);
    min-height: 0 !important;
    height: calc(100dvh - var(--mobile-header-h) - var(--mobile-tabbar-h)) !important;
    max-height: calc(100dvh - var(--mobile-header-h) - var(--mobile-tabbar-h)) !important;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    box-sizing: border-box;
    padding: 16px !important;
    align-items: flex-start;
    justify-content: center;
  }

  /* Reserve tabbar tile slots before unlock — override desktop display:none */
  body:not(.is-authenticated) .topbar .user-actions,
  body:not(.is-authenticated) .topbar .user-actions[hidden] {
    display: flex !important;
    visibility: hidden;
    pointer-events: none;
  }

  body.is-authenticated .profile-stage {
    padding-bottom: var(--mobile-tabbar-clearance);
  }

  .search-stack {
    width: min(100%, 560px);
    /* auto margins center in the stage; collapse to start when content overflows */
    margin: auto;
    gap: 16px;
  }

  .search-dropdown {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    direction: rtl; /* scrollbar on the left */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.32) rgba(255, 255, 255, 0.06);
  }

  html[data-theme="light"] .search-dropdown {
    scrollbar-color: rgba(20, 20, 24, 0.35) rgba(20, 20, 24, 0.06);
  }

  .search-dropdown .search-item,
  .search-dropdown .search-empty {
    direction: ltr;
  }

  .search-dropdown::-webkit-scrollbar {
    width: 5px;
  }

  .search-dropdown::-webkit-scrollbar-track {
    margin: 8px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 999px;
  }

  .search-dropdown::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
  }

  .search-dropdown::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
  }

  html[data-theme="light"] .search-dropdown::-webkit-scrollbar-track {
    background: rgba(20, 20, 24, 0.05);
  }

  html[data-theme="light"] .search-dropdown::-webkit-scrollbar-thumb {
    background: rgba(20, 20, 24, 0.28);
    border-color: rgba(20, 20, 24, 0.08);
  }

  .search-bar {
    height: 56px;
    padding: 0 8px 0 14px;
    border-radius: 14px;
    gap: 8px;
  }

  #kb-search {
    font-size: 16px; /* avoids iOS input zoom */
  }

  .search-ai-btn {
    height: 34px;
    padding: 0 10px;
    border-radius: 10px;
    font-size: 12px;
  }

  .search-item {
    padding: 14px 16px;
    gap: 12px;
  }

  .search-item-title {
    font-size: 15px;
  }

  .misha-modal {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .misha-panel {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding: 14px 14px 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .misha-head {
    flex: 0 0 auto;
    margin-bottom: 12px;
  }

  .misha-log {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }

  .misha-form {
    flex: 0 0 auto;
    flex-wrap: wrap;
    margin-bottom: 10px;
  }

  .misha-form .auth-submit {
    width: 100%;
  }

  /* In-flow footer so «Вернуться назад» stays under the composer, not under it */
  .misha-panel > .mobile-modal-footer {
    display: flex !important;
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
    z-index: 5;
    padding: 10px 0 calc(12px + env(safe-area-inset-bottom, 0px));
    background: transparent;
    backdrop-filter: none;
  }

  .support-chat-panel > .mobile-modal-footer {
    display: flex !important;
    margin-top: 0;
    z-index: 260;
  }

  .support-chat-log {
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }

  .support-chat-footer {
    margin-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .explore-links {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    overflow: visible;
    width: 100%;
    max-width: 100%;
    padding: 0;
    justify-content: stretch;
    align-self: stretch;
  }

  .explore-links a,
  .explore-links .explore-link {
    width: 100%;
    max-width: none;
    min-width: 0;
    min-height: 104px;
    padding: 12px 8px;
    font-size: 14px;
    flex: none;
    border-radius: 14px;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .explore-link-label {
    text-align: center;
  }

  .explore-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .explore-icon svg {
    width: 18px;
    height: 18px;
  }

  .profile-stage {
    padding: calc(var(--mobile-header-h) + 28px) 16px var(--mobile-tabbar-clearance);
    box-sizing: border-box;
  }

  body.is-authenticated .profile-stage,
  body.page-profile .profile-stage {
    padding-bottom: var(--mobile-tabbar-clearance);
  }

  .profile-card,
  .admin-card {
    padding: 20px 16px 18px;
    border-radius: 14px;
  }

  .profile-panels,
  .profile-panel {
    padding-bottom: 8px;
  }

  .profile-panel .favorites-list,
  .profile-panel .points-ledger,
  .profile-panel[data-profile-panel="edits"] {
    padding-bottom: 12px;
    margin-bottom: 0;
  }

  .profile-head h1 {
    font-size: 22px;
  }

  .profile-head-top {
    align-items: flex-start;
    gap: 10px 12px;
  }

  .admin-stage .admin-live {
    font-size: 14px;
    margin-left: 0;
  }

  .profile-settings-section #change-password-btn {
    width: min(100%, 320px);
    justify-content: center;
    padding-left: 18px;
    padding-right: 18px;
  }

  .profile-settings-section .profile-revoke-sessions-btn {
    width: min(100%, 320px);
    justify-content: center;
    align-self: center;
    margin-left: auto;
    margin-right: auto;
  }

  .profile-progress-row {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .profile-progress-track {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }

  .profile-tab,
  .admin-tabs .profile-tab {
    padding: 10px 12px;
    font-size: 13px;
  }

  .articles-filters {
    grid-template-columns: 1fr;
  }

  .shot-card {
    width: 150px;
  }

  .media-viewer-nav {
    width: 48px;
    height: 48px;
    font-size: 32px;
  }

  .media-viewer-prev {
    left: 8px;
  }

  .media-viewer-next {
    right: 8px;
  }

  .article-form-footer {
    justify-content: stretch;
  }

  .article-form-footer .auth-submit {
    min-width: 0;
    flex: 1 1 auto;
  }

  .layout-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  /* Above tab-bar (200) / under theme switch (50000). Phone offsets header below. */
  .kb-modal,
  .info-modal,
  .sections-menu-modal,
  .misha-modal {
    z-index: 220;
  }

  /* Tag feed from article — above kb/info (220), under suggest (280). */
  .tag-feed-modal {
    z-index: 260;
  }

  /* Suggest must sit above the open article (kb-modal). */
  .suggest-modal {
    z-index: 280;
  }

  .confirm-modal,
  #logout-confirm-modal {
    z-index: 400;
  }

  body.info-modal-open .topbar .auth-actions,
  body.kb-open .topbar .auth-actions,
  body.misha-open .topbar .auth-actions,
  body.logout-confirm-open .topbar .auth-actions {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .auth-modal,
  .kb-modal,
  .suggest-modal,
  .info-modal {
    padding: 12px;
    align-items: flex-end;
  }

  .auth-modal {
    z-index: 230;
  }

  .auth-panel,
  .suggest-panel,
  .info-modal-panel,
  .sections-menu-panel,
  .favorites-menu-panel {
    width: 100%;
    max-height: min(92vh, 100%);
    border-radius: 16px 16px 12px 12px;
    padding: 20px 16px 16px;
    overflow: auto;
  }

  /* Desktop crumb → mobile footer back for tag feed / return-to-article */
  .tag-feed-crumb,
  .kb-tag-return-crumb {
    display: none !important;
  }

  .article-tags-field,
  .article-tags-wrap {
    overflow: visible;
  }

  .article-tags-dropdown {
    z-index: 140;
  }

  /* Login / register: keep the card centered on tablet+phone */
  .auth-modal {
    align-items: center;
    justify-content: center;
    padding: 16px;
  }

  .auth-panel {
    width: min(420px, 100%);
    max-height: min(92vh, 100%);
    min-height: 0;
    border-radius: 18px;
    margin: 0 auto;
  }

  /* Suggest edit — mobile bottom sheet */
  .suggest-modal {
    padding: 0;
    align-items: flex-end;
    justify-content: stretch;
  }

  .suggest-panel {
    width: 100%;
    min-height: 0;
    max-height: min(88dvh, 100%);
    margin: 0;
    border-radius: 18px 18px 0 0;
    padding: 18px 16px calc(14px + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .suggest-title {
    flex: 0 0 auto;
    margin-bottom: 6px;
  }

  .suggest-lead {
    flex: 0 0 auto;
    margin-bottom: 12px;
  }

  .suggest-form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    gap: 0;
  }

  .suggest-form > .auth-field {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .suggest-form textarea {
    min-height: 132px;
    max-height: 34dvh;
    resize: none;
    font-size: 16px;
  }

  .suggest-form .kb-actions,
  .suggest-form .kb-actions-stack {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
    padding-top: 0;
    border-top: 0;
  }

  .suggest-form .kb-actions .auth-submit {
    width: 100%;
    min-width: 0;
  }

  .suggest-form .kb-actions .auth-submit[type="submit"] {
    order: 2;
  }

  .suggest-form .kb-actions .auth-submit-secondary {
    order: 1;
  }

  .favorites-menu-panel,
  .changes-menu-panel {
    padding: 16px 0 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: min(92vh, 100%);
  }

  .favorites-menu-head,
  .changes-menu-head {
    padding: 0 16px 12px;
    flex: 0 0 auto;
  }

  .favorites-menu-body,
  .changes-menu-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 4px 16px 18px;
  }

  .favorites-menu-main {
    gap: 10px;
    padding: 12px 12px;
  }

  .favorites-menu-open {
    padding: 0 12px;
    font-size: 12px;
  }

  .sections-menu-panel {
    padding: 16px 0 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .sections-menu-head {
    padding: 0 12px 8px;
  }

  .articles-hub-head {
    gap: 8px;
  }

  .articles-hub-tab {
    padding: 8px 4px 10px;
    font-size: 12px;
  }

  .articles-hub-panels {
    flex: 1 1 auto;
    width: auto;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: hidden;
  }

  .articles-hub-panel.favorites-menu-body,
  .articles-hub-panel.changes-menu-body {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    /* Keep last rows above fixed «Вернуться назад» (beats desktop padding shorthand). */
    padding: 8px 16px calc(78px + env(safe-area-inset-bottom, 0px));
  }

  .sections-menu-shell {
    flex: 1 1 auto;
    min-height: 0;
  }

  .sections-menu-layout {
    flex-direction: column;
    min-height: 0;
    max-height: none;
    height: min(78vh, 680px);
    border-top: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  }

  .sections-menu-nav {
    /* Default: splitter in the middle of the sections layout */
    flex: 0 0 var(--sections-menu-nav-h, 50%);
    width: 100%;
    max-width: none;
    height: var(--sections-menu-nav-h, 50%);
    max-height: none;
    min-height: 72px;
    border-right: 0;
    border-bottom: 0;
    padding: 10px 12px 12px;
  }

  /* Desktop TOC column is unused on mobile; splitter sits in its place */
  .sections-menu-toc {
    display: none !important;
  }

  .sections-menu-toc-panel {
    display: none !important;
  }

  .sections-menu-splitter {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    position: relative;
    height: 18px;
    margin: 0;
    padding: 0;
    border: 0;
    border-top: 1px solid var(--glass-border, rgba(255, 255, 255, 0.14));
    border-bottom: 1px solid var(--glass-border, rgba(255, 255, 255, 0.14));
    background: rgba(0, 0, 0, 0.16);
    cursor: row-resize;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }

  .sections-menu-splitter-grip {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 44px;
    min-height: 18px;
    padding: 2px 10px;
  }

  .sections-menu-splitter-arrow {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
  }

  .sections-menu-splitter-arrow.is-up {
    border-bottom: 5px solid rgba(235, 242, 255, 0.78);
  }

  .sections-menu-splitter-arrow.is-down {
    border-top: 5px solid rgba(235, 242, 255, 0.78);
  }

  .sections-menu-layout.is-resizing,
  .sections-menu-layout.is-resizing * {
    cursor: row-resize !important;
    user-select: none !important;
  }

  html[data-theme="light"] .sections-menu-splitter {
    background: rgba(20, 24, 32, 0.06);
  }

  html[data-theme="light"] .sections-menu-splitter-arrow.is-up {
    border-bottom-color: rgba(28, 32, 40, 0.55);
  }

  html[data-theme="light"] .sections-menu-splitter-arrow.is-down {
    border-top-color: rgba(28, 32, 40, 0.55);
  }

  .sections-menu-toc > .kb-suggest-btn,
  .kb-toc > .kb-suggest-btn {
    display: none !important;
  }

  .kb-suggest-btn-footer {
    display: flex;
    width: 100%;
    margin-top: 14px;
    margin-bottom: 4px;
  }

  .sections-menu-sec {
    margin: 10px 6px 4px;
    font-size: 10px;
  }

  .sections-menu-link {
    font-size: 15px;
    padding: 10px 12px 10px 14px;
  }

  .sections-menu-close-link {
    font-size: 14px;
    padding: 10px 12px;
    margin-bottom: 6px;
  }

  .sections-menu-content {
    flex: 1 1 auto;
    min-height: 0;
    padding: 16px 14px 18px;
  }

  .sections-menu-welcome {
    min-height: 100%;
    padding: 24px 16px;
  }

  .sections-menu-welcome-desktop {
    display: none;
  }

  .sections-menu-welcome-mobile {
    display: block;
  }

  .sections-menu-welcome-text {
    font-size: 16px;
    max-width: 22rem;
  }

  .sections-menu-article-title {
    font-size: clamp(20px, 5.5vw, 26px);
  }

  /* Equal square tiles; scale images down with contain */
  .kb-shots,
  .sections-menu-content .kb-shots,
  #article-preview-body .kb-shots {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .kb-media-card,
  .kb-video-wrap {
    aspect-ratio: 1 / 1;
  }

  .kb-panel {
    width: 100%;
    max-height: min(92vh, 100%);
    border-radius: 16px 16px 12px 12px;
  }

  .kb-article {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .kb-toc {
    border-right: 0;
    border-bottom: 1px solid var(--glass-border);
    max-height: 40vh;
    overflow: auto;
  }

  .kb-main {
    padding: 18px 14px 16px;
  }

  .kb-article-head {
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
  }

  .kb-article-toolbar {
    margin-left: auto;
  }

  .kb-snippet {
    padding: 22px 16px 18px;
  }

  .admin-table {
    font-size: 14px;
  }

  .admin-table th,
  .admin-table td {
    padding: 10px 8px;
  }

  .admin-action {
    padding: 10px 12px;
    font-size: 13px;
  }

  .admin-metrics-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-metrics-toggles,
  .admin-metrics-subnav {
    width: 100%;
  }

  .admin-metrics-subtab,
  .admin-metrics-toggle {
    flex: 1 1 auto;
    text-align: center;
    min-height: 40px;
  }

  .admin-metrics-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .admin-metrics-card-value {
    font-size: 18px;
  }

  .admin-metrics-chart-wrap {
    padding: 8px 4px 2px;
    border-radius: 12px;
  }

  .admin-ai-logs-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-ai-logs-actions {
    margin-left: 0;
  }

  .admin-ai-logs-field input[type="date"] {
    width: 100%;
    min-width: 0;
  }

  .confirm-modal {
    padding: 16px;
    align-items: flex-end;
  }

  .confirm-modal-panel {
    width: 100%;
    border-radius: 16px 16px 12px 12px;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .confirm-modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .confirm-modal-actions .auth-submit {
    min-width: 0;
    width: 100%;
  }

  /* Download modal — bottom sheet on mobile */
  #download-vverh-modal {
    padding: 0;
    align-items: flex-end;
    justify-content: stretch;
  }

  #download-vverh-modal .info-modal-panel {
    width: 100%;
    max-width: none;
    margin: 0;
    min-height: 0;
    height: auto;
    max-height: min(88dvh, 100%);
    border-radius: 18px 18px 0 0;
    padding: 20px 0 calc(88px + env(safe-area-inset-bottom, 0px));
  }

  #download-vverh-modal .info-modal-head {
    padding-left: 12px;
    padding-right: 12px;
  }

  #download-vverh-modal .info-modal-body {
    padding-left: 0;
    padding-right: 0;
  }

  #download-vverh-modal .download-vverh-actions {
    align-items: stretch;
    justify-content: center;
    width: 100%;
    padding-left: 12px;
    padding-right: 12px;
    box-sizing: border-box;
  }

  #download-vverh-modal a.download-vverh-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 10px;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    font-size: 17px;
    min-height: 52px;
    text-align: left !important;
  }

  #download-vverh-modal a.download-vverh-btn .download-vverh-btn-label {
    display: block;
    width: auto;
    text-align: left !important;
  }

  #download-vverh-modal .mobile-modal-footer .mobile-modal-back-btn {
    text-align: center !important;
  }

  #career-modal .info-modal-panel {
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
  }

  #career-modal .info-modal-head,
  #career-modal .info-modal-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .mobile-modal-footer {
    display: flex;
    flex: 0 0 auto;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 240;
    width: 100%;
    max-width: none;
    margin: 0;
    box-sizing: border-box;
    padding: 12px 12px calc(14px + env(safe-area-inset-bottom, 0px));
    border-top: 0;
    background: rgba(10, 14, 22, 0.96);
    backdrop-filter: blur(12px);
  }

  html[data-theme="light"] .mobile-modal-footer {
    background: rgba(248, 250, 252, 0.98);
  }

  .mobile-modal-back-btn {
    appearance: none;
    display: block !important;
    visibility: visible !important;
    flex: 1 1 auto;
    width: 100%;
    max-width: none;
    min-height: 46px;
    box-sizing: border-box;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.16));
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text, #fff);
    font: inherit;
    font-size: 15px;
    font-weight: 550;
    cursor: pointer;
    padding: 10px 16px;
  }

  .mobile-modal-back-btn:active {
    transform: scale(0.98);
  }

  html[data-theme="light"] .mobile-modal-back-btn {
    background: rgba(15, 23, 42, 0.05);
  }

  /* Keep article/content scrollable above the fixed back footer */
  #download-vverh-modal .info-modal-body,
  #career-modal .info-modal-body,
  .favorites-menu-body,
  .changes-menu-body,
  .sections-menu-shell,
  .kb-modal-body {
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }

  /* Misha: footer is in-flow — only the log needs bottom room if content scrolls */
  .misha-panel {
    padding-bottom: 0;
  }

  .kb-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .kb-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
  }

  .kb-actions [data-kb-back] {
    display: none;
  }

  .article-scroll-top-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 10px;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    z-index: 31;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 12px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.18));
    background: rgba(10, 14, 22, 0.88);
    color: var(--text, #fff);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px);
    cursor: pointer;
  }

  .article-scroll-top-btn[hidden] {
    display: none !important;
  }

  .article-scroll-top-btn svg {
    width: 20px;
    height: 20px;
  }

  .article-scroll-top-btn:active {
    transform: scale(0.96);
  }

  html[data-theme="light"] .article-scroll-top-btn {
    background: rgba(248, 250, 252, 0.94);
    border-color: rgba(20, 20, 24, 0.14);
    color: #17171a;
  }

  #download-vverh-modal .info-modal-panel,
  #career-modal .info-modal-panel,
  .favorites-menu-panel,
  .changes-menu-panel,
  .sections-menu-panel {
    display: flex;
    flex-direction: column;
  }

  #download-vverh-modal .info-modal-body,
  #career-modal .info-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
  }

  .favorites-menu-body,
  .changes-menu-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  html[data-theme="light"] .kb-toc-item.is-active {
    background: rgba(17, 24, 39, 0.1);
    border-color: transparent;
    color: #111827;
    box-shadow: inset 3px 0 0 rgba(17, 24, 39, 0.75);
  }

  html[data-theme="light"] .kb-toc-item.is-active .kb-toc-num {
    color: #111827;
  }

  html[data-theme="light"] .kb-toc-empty {
    color: #111827;
  }

  .sections-menu-shell {
    flex: 1 1 auto;
    min-height: 0;
  }

  .sections-menu-close-link {
    display: none;
  }

  .article-preview-head-actions {
    gap: 6px;
  }

  .article-preview-download-btn {
    padding: 7px 10px;
    font-size: 12px;
  }

  .kb-actions-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .kb-actions-row .auth-submit {
    width: 100%;
  }

  /* Support chat: keep input + Send on one row, no overflow */
  .support-chat-panel {
    width: 100vw;
    max-width: 100%;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .support-chat-footer {
    gap: 10px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .support-chat-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 0;
  }

  .support-chat-toolbar #support-chat-send-logs {
    flex: 1 1 auto;
    min-width: 0;
  }

  .support-chat-form {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    width: 100%;
    max-width: 100%;
  }

  .support-chat-form .support-chat-attach-btn {
    width: 44px;
    height: 44px;
  }

  .support-chat-form input,
  .support-chat-form textarea {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    font-size: 16px; /* avoid iOS zoom on focus */
    padding: 12px;
  }

  .support-chat-form textarea {
    resize: none;
    overflow-y: auto;
    min-height: 44px;
    max-height: calc(1.4em * 10 + 24px);
    line-height: 1.4;
    field-sizing: content;
  }

  .support-chat-form .auth-submit {
    width: auto;
    min-width: 0;
    flex: none;
    white-space: nowrap;
    padding-inline: 14px;
    align-self: end;
    min-height: 44px;
  }

  .misha-form {
    align-items: end;
  }

  .misha-form input,
  .misha-form textarea {
    height: auto;
    min-height: 44px;
    max-height: calc(1.4em * 10 + 24px);
    padding: 10px 14px;
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
    font-size: 16px;
  }

  .misha-form .auth-submit {
    align-self: end;
    min-height: 44px;
  }

  .profile-devices-items {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sections-splitter-hint {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 320;
    pointer-events: auto;
  }

  .sections-splitter-hint[hidden] {
    display: none !important;
  }

  .sections-splitter-hint-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
  }

  .sections-splitter-hint-card {
    position: fixed;
    z-index: 321;
    width: min(300px, calc(100vw - 32px));
    box-sizing: border-box;
    padding: 14px 14px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(22, 26, 34, 0.98);
    color: #fff;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    transform: translateX(-50%);
  }

  .sections-splitter-hint-text {
    margin: 0 0 12px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
  }

  .sections-splitter-hint-ok {
    appearance: none;
    display: block;
    width: 100%;
    min-height: 42px;
    margin: 0;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font: inherit;
    font-size: 15px;
    font-weight: 550;
    cursor: pointer;
  }

  .sections-splitter-hint-ok:active {
    transform: scale(0.98);
  }

  .sections-splitter-hint-arrow {
    position: absolute;
    left: 50%;
    bottom: -8px;
    width: 16px;
    height: 16px;
    margin-left: -8px;
    background: rgba(22, 26, 34, 0.98);
    border-right: 1px solid rgba(255, 255, 255, 0.18);
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    transform: rotate(45deg);
  }

  html[data-theme="light"] .sections-splitter-hint-backdrop {
    background: rgba(10, 14, 22, 0.55);
  }

  html[data-theme="light"] .sections-splitter-hint-card {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(20, 20, 24, 0.14);
    color: #111;
    box-shadow: 0 12px 28px rgba(17, 24, 39, 0.18);
  }

  html[data-theme="light"] .sections-splitter-hint-ok {
    background: rgba(15, 23, 42, 0.06);
    border-color: rgba(15, 23, 42, 0.14);
    color: #111;
  }

  html[data-theme="light"] .sections-splitter-hint-arrow {
    background: rgba(255, 255, 255, 0.98);
    border-right-color: rgba(20, 20, 24, 0.14);
    border-bottom-color: rgba(20, 20, 24, 0.14);
  }
}

/* —— Phone (≤720px) —— */
@media (max-width: 720px) {
  .profile-devices-items {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 8px 12px 0;
  }

  .theme-switch {
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 12px;
  }

  .brand-title {
    max-width: 11em;
  }

  .auth-sep {
    display: none;
  }

  body:not(.page-profile):not(.page-admin) .stage {
    padding: 12px !important;
  }

  .search-stack {
    width: 100%;
  }

  .search-bar {
    height: 52px;
    border-radius: 12px;
  }

  .search-dropdown {
    border-radius: 12px;
    top: calc(100% + 8px);
  }

  .explore-links {
    gap: 8px;
  }

  .explore-links a,
  .explore-links .explore-link {
    min-height: 112px;
    padding: 12px 10px;
    font-size: 14px;
    gap: 8px;
  }

  .topbar .auth-actions {
    height: var(--mobile-tabbar-h);
    padding: 8px 10px calc(15px + env(safe-area-inset-bottom, 0px));
  }

  .topbar .user-actions {
    gap: 6px;
  }

  .topbar .auth-tile {
    min-height: 58px;
    padding: 8px 4px;
    font-size: 12px;
    border-radius: 11px;
  }

  .kb-history-row {
    grid-template-columns: minmax(0, 1fr) minmax(110px, 40%);
    gap: 8px;
  }

  .kb-history-date {
    font-size: 11px;
  }

  .kb-version-bar {
    gap: 8px;
  }

  .kb-version-current,
  .kb-version-history {
    font-size: 12px;
  }

  .profile-stage {
    padding: calc(var(--mobile-header-h) + 20px) 12px var(--mobile-tabbar-clearance);
  }

  body.is-authenticated .profile-stage {
    padding-bottom: var(--mobile-tabbar-clearance);
  }

  body.page-profile .profile-stage {
    padding-top: 8px !important;
    padding-bottom: 16px !important;
  }

  .profile-tabs,
  .admin-tabs {
    gap: 6px;
  }

  .profile-tab {
    flex: 1 1 calc(50% - 6px);
    text-align: center;
  }

  .shots-carousel {
    gap: 10px;
  }

  .shot-card {
    width: 132px;
  }

  .kb-modal,
  .info-modal,
  .sections-menu-modal,
  .misha-modal {
    top: var(--mobile-header-h);
    z-index: 220;
    padding: 0;
    align-items: stretch;
  }

  .suggest-modal {
    top: var(--mobile-header-h);
    z-index: 280;
    padding: 0;
    align-items: stretch;
  }

  .confirm-modal,
  #logout-confirm-modal {
    z-index: 400;
  }

  .auth-modal {
    padding: 16px;
    align-items: center;
    justify-content: center;
    z-index: 230;
  }

  .auth-panel,
  .suggest-panel,
  .info-modal-panel,
  .kb-panel,
  .sections-menu-panel {
    width: 100%;
    min-height: 100%;
    max-height: none;
    border-radius: 0;
    padding: 18px 14px 24px;
  }

  .auth-panel {
    width: min(420px, 100%);
    min-height: 0;
    max-height: min(92dvh, 100%);
    border-radius: 18px;
    padding: 24px 18px 18px;
    margin: 0 auto;
    overflow: auto;
  }

  /* Keep suggest as bottom sheet on phones (do not full-screen) */
  .suggest-modal {
    align-items: flex-end;
    justify-content: stretch;
  }

  .suggest-panel {
    width: 100%;
    min-height: 0;
    height: auto;
    max-height: min(88dvh, 100%);
    border-radius: 18px 18px 0 0;
    padding: 16px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .sections-menu-panel {
    padding: 14px 0 0;
    overflow: hidden;
    height: 100%;
    min-height: calc(100dvh - var(--mobile-header-h));
  }

  .sections-menu-head {
    padding: 0 14px 10px;
  }

  .sections-menu-layout {
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }

  .sections-menu-nav {
    flex-basis: var(--sections-menu-nav-h, 50%);
    height: var(--sections-menu-nav-h, 50%);
    max-height: none;
    padding: 8px 10px 10px;
  }

  .sections-menu-content {
    padding: 14px 12px 20px;
    min-height: 140px;
  }

  #career-modal .info-modal-panel,
  .favorites-menu-panel,
  .changes-menu-panel,
  .sections-menu-panel {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - var(--mobile-header-h));
    max-height: calc(100dvh - var(--mobile-header-h));
    overflow: hidden;
    padding-bottom: 0;
  }

  #download-vverh-modal {
    align-items: flex-end;
    justify-content: stretch;
  }

  #download-vverh-modal .info-modal-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    max-height: min(88dvh, 100%);
    height: auto;
    overflow: auto;
    border-radius: 18px 18px 0 0;
    margin: 0;
    margin-top: auto;
  }

  #career-modal .info-modal-body,
  .favorites-menu-body,
  .changes-menu-body,
  .sections-menu-shell {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
  }

  .favorites-menu-panel,
  .changes-menu-panel {
    padding: 14px 0 0;
  }

  .favorites-menu-head {
    padding: 0 14px 10px;
  }

  .favorites-menu-body {
    max-height: none;
    padding: 4px 14px calc(78px + env(safe-area-inset-bottom, 0px));
  }

  .changes-menu-head {
    padding: 0 14px 10px;
  }

  .changes-menu-body {
    max-height: none;
    padding: 4px 14px calc(78px + env(safe-area-inset-bottom, 0px));
  }

  .articles-hub-panel.favorites-menu-body,
  .articles-hub-panel.changes-menu-body {
    padding: 4px 14px calc(78px + env(safe-area-inset-bottom, 0px));
  }

  #career-modal .info-modal-panel {
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
  }

  #download-vverh-modal .info-modal-panel {
    padding: 20px 0 calc(88px + env(safe-area-inset-bottom, 0px));
  }

  #download-vverh-modal .info-modal-head {
    padding-left: 12px;
    padding-right: 12px;
  }

  #download-vverh-modal .info-modal-body {
    padding-left: 0;
    padding-right: 0;
  }

  #download-vverh-modal .download-vverh-actions {
    padding-left: 12px;
    padding-right: 12px;
  }

  #career-modal .info-modal-head,
  #career-modal .info-modal-body {
    padding-left: 14px;
    padding-right: 14px;
  }

  .mobile-modal-footer {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 240;
    width: 100%;
    max-width: none;
    box-sizing: border-box;
    padding: 12px 12px calc(14px + env(safe-area-inset-bottom, 0px));
    border-top: 0;
    background: rgba(10, 14, 24, 0.96);
    backdrop-filter: blur(12px);
  }

  html[data-theme="light"] .mobile-modal-footer {
    background: rgba(248, 250, 252, 0.98);
  }

  .mobile-modal-back-btn {
    appearance: none;
    display: block !important;
    visibility: visible !important;
    flex: 1 1 auto;
    width: 100%;
    max-width: none;
    min-height: 46px;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text, #fff);
    font: inherit;
    font-size: 15px;
    font-weight: 560;
    cursor: pointer;
    padding: 10px 16px;
  }

  .mobile-modal-back-btn:active {
    transform: scale(0.98);
  }

  html[data-theme="light"] .mobile-modal-back-btn {
    border-color: rgba(15, 23, 42, 0.14);
    background: rgba(15, 23, 42, 0.06);
  }

  .kb-panel {
    min-height: calc(100dvh - var(--mobile-header-h));
    max-height: calc(100dvh - var(--mobile-header-h));
    padding-bottom: 0;
  }

  .kb-modal-body {
    padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }

  .auth-field input,
  .article-form textarea,
  .article-form select,
  .article-form input[type="text"],
  .auth-field select,
  .articles-filters select,
  .suggest-form textarea {
    font-size: 16px; /* avoids iOS zoom on focus */
  }
}

/* —— Small phone (≤480px) —— */
@media (max-width: 480px) {
  .topbar-left {
    gap: 8px;
  }

  .brand {
    font-size: 15px;
  }

  .brand-title {
    max-width: 9.5em;
  }

  .theme-switch {
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 10px;
  }

  .theme-switch-track {
    width: 84px;
    height: 28px;
  }

  .theme-switch-thumb {
    width: 22px;
    height: 22px;
    top: 2px;
    left: 2px;
    transform: translateX(58px);
  }

  .theme-switch.is-light .theme-switch-thumb,
  html[data-theme="light"] .theme-switch .theme-switch-thumb {
    transform: translateX(0);
  }

  body:not(.page-profile):not(.page-admin) .stage {
    padding: 10px !important;
  }

  .explore-links {
    gap: 7px;
  }

  .explore-links a,
  .explore-links .explore-link {
    min-height: 108px;
    font-size: 14px;
  }

  .explore-icon {
    width: 30px;
    height: 30px;
  }

  .explore-icon svg {
    width: 16px;
    height: 16px;
  }

  .topbar .auth-tile-label {
    font-size: 12px;
  }

  .profile-head h1 {
    font-size: 20px;
  }

  .profile-user {
    font-size: 13px;
  }

  .layout-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .article-form-footer {
    flex-direction: column-reverse;
  }

  .article-form-footer .auth-submit {
    width: 100%;
  }

  /* Do not cap nav height here — splitter (--sections-menu-nav-h) owns both directions */
  .sections-menu-nav {
    max-height: none;
  }

  .sections-menu-link {
    font-size: 14px;
    padding: 9px 10px 9px 12px;
  }

  .sections-menu-article-title {
    font-size: 20px;
  }

  .sections-menu-content {
    padding: 12px 10px 18px;
  }
}
