/* =============================================================================
   ИИ ГОСТ Справочник — Mobile & Responsive Styles
   Mobile-First approach | All breakpoints covered
   Breakpoints: 375 / 390 / 393 / 412 / 430 / 480 / 600 / 768 / 834 / 1024 / 1280 / 1440 / 1920px
   ============================================================================= */

/* ── CSS Custom Properties (mobile overrides) ──────────────────────────── */
:root {
  /* Safe area insets for iPhone notch/Dynamic Island */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);

  /* Bottom nav height (mobile) */
  --bottom-nav-h: 60px;

  /* Navbar height */
  --navbar-h: 56px;

  /* Touch targets */
  --touch-min: 44px;

  /* Mobile spacing */
  --m-gap-xs:  8px;
  --m-gap-sm:  12px;
  --m-gap-md:  16px;
  --m-gap-lg:  24px;

  /* Mobile transitions */
  --transition-slide: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fade:  opacity 0.2s ease;

  /* Chat input height (mobile) */
  --chat-input-h: 72px;
}

/* ── Utility: show / hide helpers ───────────────────────── */
.mobile-only   { display: none !important; }
.desktop-only  { display: block !important; }
.tablet-only   { display: none !important; }

/* ── Responsive root scale (tablet / desktop) ───────────── */
@media (min-width: 768px) {
  :root { font-size: 17.5px; }
}
@media (min-width: 1024px) {
  :root { font-size: 18px; }
}

/* ── Base mobile resets ─────────────────────────────────── */
* {
  /* Remove 300ms tap delay everywhere */
  touch-action: manipulation;
}

/* iOS: prevent rubber-band on whole page but allow scroll in containers */
html {
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}

/* Inputs must be ≥16px to prevent iOS zoom */
input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
  font-size: max(16px, 1em) !important;
  -webkit-appearance: none;
}

/* ============================================================================
   LANDING DRAWER — hidden on desktop (burger not shown); mobile handles via .sidebar rules below
   ============================================================================ */
.landing-drawer {
  display: none;
}

/* ============================================================================
   BURGER MENU BUTTON (shown only on mobile, placed in navbar)
   ============================================================================ */
.burger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.burger-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.2s ease, width 0.2s ease;
  transform-origin: center;
}

.burger-btn.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.burger-btn.open span:nth-child(2) {
  opacity: 0;
  width: 0;
}
.burger-btn.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ============================================================================
   MOBILE DRAWER / SIDEBAR OVERLAY
   ============================================================================ */
.mobile-overlay {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 299;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-fade);
  visibility: hidden;
}

.mobile-overlay.visible {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

/* ============================================================================
   BOTTOM NAVIGATION BAR (Mobile)
   ============================================================================ */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--marine-900);
  border-top: 1px solid var(--marine-700);
  z-index: 200;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.bottom-nav-inner {
  display: flex;
  align-items: stretch;
  height: var(--bottom-nav-h);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.03em;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
  min-width: var(--touch-min);
  padding: 0 4px;
}

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.bottom-nav-item.active,
.bottom-nav-item:hover {
  color: var(--copper-400);
  text-decoration: none;
}

.bottom-nav-item.active svg {
  stroke: var(--copper-400);
}

/* Badge on bottom nav items */
.bottom-nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 20px);
  background: var(--color-danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.bottom-nav-item { position: relative; }

/* ============================================================================
   TYPING INDICATOR
   ============================================================================ */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--surface-light);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 2px;
  width: fit-content;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-light-muted);
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1;   }
}

/* ============================================================================
   PULL-TO-REFRESH INDICATOR
   ============================================================================ */
.pull-refresh-indicator {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--text-light-muted);
  transition: top 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
}

.pull-refresh-indicator.visible {
  top: 8px;
}

.pull-refresh-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-light);
  border-top-color: var(--marine-400);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================================
   SWIPE-TO-DELETE for history items
   ============================================================================ */
.swipeable-item {
  position: relative;
  overflow: hidden;
}

.swipe-action {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.swipeable-item.swiped .swipe-action {
  transform: translateX(0);
}

.swipeable-item .swipe-content {
  transition: transform 0.2s ease;
}

.swipeable-item.swiped .swipe-content {
  transform: translateX(-80px);
}

/* ============================================================================
   TOAST NOTIFICATIONS (mobile-friendly)
   ============================================================================ */
.mobile-toast-container {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(90vw, 400px);
}

.mobile-toast {
  background: var(--marine-900);
  color: var(--text-light-primary);
  border: 1px solid var(--marine-600);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.875rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35);
  pointer-events: auto;
  animation: toastIn 0.25s ease forwards;
  max-width: 100%;
}

.mobile-toast.toast-success { border-color: var(--color-success); }
.mobile-toast.toast-error   { border-color: var(--color-danger);  }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================================
   SEARCH SHEET (slide-up on mobile)
   ============================================================================ */
.search-sheet {
  position: fixed;
  bottom: -100%;
  left: 0;
  right: 0;
  background: var(--surface-light);
  border-top: 1px solid var(--border-light);
  border-radius: 16px 16px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  z-index: 400;
  transition: bottom 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -8px 32px rgba(0,0,0,0.25);
}

.search-sheet.open {
  bottom: 0;
}

.search-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  margin: 0 auto 16px;
}

/* ============================================================================
   PLAN CARDS — horizontal scroll on mobile
   ============================================================================ */
.plans-scroll-wrapper {
  -webkit-overflow-scrolling: touch;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  display: flex;
  gap: 16px;
  padding: 0 16px 16px;
  margin: 0 -16px;
}

.plans-scroll-wrapper::-webkit-scrollbar { display: none; }

.plans-scroll-wrapper .plan-card {
  scroll-snap-align: center;
  flex: 0 0 min(280px, 80vw);
}

/* ============================================================================
   PLANS PAGE (/plans) — vertical cards on phone & tablet
   ============================================================================ */
@media (max-width: 1023px) {
  .plans-page__header {
    margin-bottom: 1.5rem;
  }

  .plans-page__title {
    font-size: 1.375rem;
  }

  .plans-page__lead {
    font-size: 0.9375rem;
    padding: 0 4px;
  }

  .plans-page .plans-grid {
    display: flex !important;
    flex-direction: column !important;
    overflow-x: visible !important;
    scroll-snap-type: none !important;
    gap: 1.25rem;
    margin: 0;
    padding: 0;
  }

  .plans-page .plans-grid .plan-card {
    flex: none !important;
    width: 100% !important;
    max-width: none !important;
    scroll-snap-align: none;
    padding: 1.5rem 1.25rem;
  }

  .plans-page .plan-card:hover {
    transform: none;
  }

  .plans-page .plan-feature {
    align-items: flex-start;
  }

  .plans-page .plan-subscribe-form .consent-text {
    font-size: 0.8125rem;
  }

  .plans-page .plan-price {
    font-size: 2rem;
  }

  .plans-enterprise {
    margin-top: 1.75rem;
    padding: 1.25rem;
  }

  .plans-enterprise__actions {
    flex-direction: column;
  }

  .plans-enterprise__actions .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .plans-faq {
    margin-top: 2rem;
  }

  .plans-faq__item summary {
    font-size: 0.9375rem;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .plans-page .plans-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (min-width: 1024px) {
  .plans-page .plans-grid {
    margin-top: 2rem;
  }
}

/* ============================================================================
   DARK THEME MOBILE OVERRIDES
   ============================================================================ */
/* Already handled by :root variables — dark is default */

/* ============================================================================
   LIGHT THEME MOBILE OVERRIDES
   ============================================================================ */
body.light-theme .mobile-bottom-nav {
  background: rgba(255, 255, 255, 0.98);
  border-top-color: var(--border-light);
}

body.light-theme .bottom-nav-item {
  color: #989898;
}

body.light-theme .bottom-nav-item.active,
body.light-theme .bottom-nav-item:hover {
  color: var(--marine-900, #1E1E1E);
}

body.light-theme .bottom-nav-item.active svg {
  stroke: var(--marine-900, #1E1E1E);
}

body.light-theme .mobile-toast {
  background: #FFFFFF;
  color: var(--text-light-primary);
  border-color: var(--border-light);
}

body.light-theme .search-sheet {
  background: #FFFFFF;
}

/* ============================================================================
   prefers-color-scheme (system theme override if no cookie)
   ============================================================================ */
@media (prefers-color-scheme: dark) {
  :root:not(.forced-light) {
    color-scheme: dark;
  }
}

@media (prefers-color-scheme: light) {
  :root:not(.forced-dark) {
    color-scheme: light;
  }
}

/* ============================================================================
   prefers-reduced-motion
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html { scroll-behavior: auto; }
}

/* ============================================================================
   HIGH-DPI / RETINA screens
   ============================================================================ */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .navbar::after {
    /* sharper ruler on retina */
    background-size: 8px 1px;
  }
}

/* ============================================================================
   ██████████████████  BREAKPOINTS  ██████████████████
   Mobile-first: rules apply from the stated width upward (min-width)
   unless noted as (max-width) for desktop-down overrides.
   ============================================================================ */

/* ─────────────────────────────────────────────────────────────────────────────
   BASE MOBILE  (< 375px — very small phones)
───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 374px) {
  .navbar {
    padding: 0 8px;
    height: 52px;
    gap: 6px;
  }

  .navbar-brand span { font-size: 0.8rem; }

  .message-bubble { font-size: 0.875rem; }

  .plans-scroll-wrapper .plan-card {
    flex: 0 0 90vw;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   375px  (iPhone SE, iPhone 6/7/8)
───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  /* ── Show/hide helpers ── */
  .mobile-only  { display: block !important; }
  .desktop-only { display: none  !important; }

  /* ── Viewport compensation for bottom nav ── */
  body {
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding-top: var(--safe-top);
  }
  body.no-bottom-nav {
    padding-bottom: var(--safe-bottom);
  }

  body.no-bottom-nav .mobile-bottom-nav {
    display: none !important;
  }

  /* ── Bottom nav: show ── */
  .mobile-bottom-nav { display: block; }

  /* ── Burger: show ── */
  .burger-btn { display: flex; }

  /* ── Hide desktop sidebar ── */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(280px, 85vw);
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    z-index: 310;
    transform: translateX(-100%);
    transition: var(--transition-slide);
    border-right: 1px solid var(--border-light) !important;
    border-bottom: none !important;
    display: flex !important;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    padding: 0;
    padding-top: calc(var(--navbar-h) + var(--safe-top));
    padding-bottom: max(12px, var(--safe-bottom));
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.28);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Кнопка закрытия (бургер/X) остаётся поверх drawer */
  body:has(.sidebar.open) .navbar,
  body.sidebar-open .navbar {
    z-index: 320;
  }

  /* Длинное меню (профиль + админ): не обрезать через overflow:hidden у inner */
  .sidebar-inner {
    height: auto;
    min-height: 0;
    overflow: visible;
    flex: 1 1 auto;
  }

  .sidebar .sessions-section {
    flex: none;
    min-height: auto;
  }

  .sidebar .sessions-list {
    flex: none;
    max-height: min(40vh, 280px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* mobile-overlay display is handled by JS via .visible class */

  /* ── App shell: single column ── */
  .app-shell {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto 1fr;
  }

  body.page-scroll .app-shell {
    grid-template-rows: auto !important;
    min-height: auto !important;
  }

  body.page-scroll .main-content {
    overflow: visible !important;
    overflow-y: visible !important;
    min-height: auto !important;
  }

  /* ── Navbar: hamburger layout ── */
  .navbar {
    padding: 0 12px 0 12px;
    padding-left: max(12px, var(--safe-left));
    padding-right: max(12px, var(--safe-right));
    height: var(--navbar-h);
    position: sticky;
    top: 0;
    z-index: 200;
  }

  /* Hide desktop navigation links; keep font/palette + theme + user menu */
  .navbar-nav {
    display: none;
  }

  .navbar-user-btn {
    margin-left: 0;
    max-width: min(10rem, 34vw);
    padding: 0.25rem 0.45rem 0.25rem 0.25rem;
    font-size: 0.75rem;
  }

  .user-menu-modal {
    padding: calc(var(--navbar-h, 56px) + 0.35rem) 0.75rem 0.75rem;
    align-items: flex-start;
    justify-content: stretch;
  }

  .user-menu-panel {
    width: 100%;
    max-width: 20rem;
    margin-left: auto;
  }

  .navbar > nav {
    margin-left: auto;
    flex: 0 1 auto;
    gap: 0.35rem;
  }

  .navbar-preferences {
    display: none;
  }

  /* Theme toggle & eng mode: keep visible, smaller */
  .btn-eng-mode {
    display: none;
  }

  /* Show mobile theme toggle (separate element in layout) */
  .mobile-theme-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.75);
    -webkit-tap-highlight-color: transparent;
    margin-left: auto;
  }

  /* ── Main content ── */
  .main-content {
    padding: 16px 12px;
    min-height: 0;
  }

  /* ── Buttons: touch-friendly ── */
  .btn {
    min-height: var(--touch-min);
    padding: 10px 16px;
  }

  .btn-sm {
    min-height: 36px;
    padding: 6px 12px;
  }

  .btn-lg {
    min-height: 52px;
    padding: 14px 20px;
    font-size: 1rem;
    width: 100%;
    justify-content: center;
  }

  /* ── Forms ── */
  .form-control {
    font-size: 16px !important; /* prevents iOS zoom */
    padding: 13px 16px;
    min-height: var(--touch-min);
    border-radius: 10px;
    line-height: 1.55;
  }

  .form-group { margin-bottom: 18px; }

  /* ── Cards ── */
  .card {
    padding: 16px;
    border-radius: 12px;
  }

  /* ── Chat layout: full-height single-column ── */
  .chat-layout {
    height: calc(100dvh - var(--navbar-h));
    margin: -16px 0 0;
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr auto;
    display: flex !important;
    flex-direction: column;
  }

  /* ── Chat messages ── */
  .chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 0;
    gap: 16px;
    padding-bottom: 8px;
    scroll-padding-bottom: 8px;
  }

  /* ── Message bubbles ── */
  .message {
    max-width: 100%;
    gap: 8px;
  }

  .message-bubble {
    max-width: calc(100% - 36px);
    padding: 11px 14px;
    font-size: 0.9375rem;
    line-height: 1.7;
  }

  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 0.6875rem;
    flex-shrink: 0;
  }

  /* ── Chat input bar: прижат к низу через flex, без sticky ── */
  .chat-input-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    padding: 10px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-light);
    background: var(--surface-light);
    z-index: 200;
  }

  .chat-input-form {
    gap: 8px;
    align-items: flex-end;
  }

  .chat-input-form textarea,
  .chat-input-form input[type="text"] {
    font-size: 16px !important;
    min-height: 44px;
    max-height: 120px;
    resize: none;
    border-radius: 22px;
    padding: 11px 14px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-width: 0;
  }

  /* Send button: round, inside input */
  .chat-send-btn,
  .chat-input-form .btn-primary[type="submit"] {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Sessions panel: hidden by default on mobile ── */
  .sessions-panel {
    display: none !important;
  }

  .chat-layout.sessions-open .sessions-panel {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 88vw);
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    z-index: 310;
    overflow: hidden;
    padding: 0;
    padding-top: var(--navbar-h, 56px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.28);
    border-right: 1px solid var(--border-light);
  }

  .chat-layout.sessions-open .sessions-panel .chat-sidebar-inner {
    flex: 1;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .chat-layout.sessions-open .sessions-panel .sessions-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .chat-layout.sessions-open .sessions-panel .sessions-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── History cards ── */
  .history-card,
  .session-item {
    padding: 14px 16px;
    min-height: var(--touch-min);
    border-radius: 10px;
  }

  /* ── Plans: horizontal scroll (overridden by .plans-page on /plans) ── */
  .plans-grid {
    display: flex !important;
    flex-direction: row;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 16px;
    padding: 4px 0 16px;
    margin: 0 -12px;
    padding-left: 12px;
    padding-right: 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .plans-grid::-webkit-scrollbar { display: none; }

  .plans-grid .plan-card,
  .plan-card {
    flex: 0 0 min(280px, 82vw);
    scroll-snap-align: center;
    max-width: 320px;
    width: min(280px, 82vw) !important;
  }

  /* ── Tables: make responsive ── */
  .data-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
  }

  .data-table {
    min-width: 600px;
  }

  /* ── Alerts ── */
  .alert {
    padding: 0.8125rem 1rem;
    font-size: 0.875rem;
    border-radius: var(--radius);
    line-height: 1.6;
  }

  /* ── Profile page ── */
  .profile-page__header {
    margin-bottom: 1.25rem;
  }

  .profile-page__title {
    font-size: 1.375rem;
  }

  .profile-card {
    padding: 1.125rem 1rem;
    margin-bottom: 1rem;
    border-radius: 12px;
  }

  .profile-section-title {
    font-size: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }

  .profile-form-grid,
  .profile-password-grid {
    grid-template-columns: 1fr !important;
    gap: 0.875rem;
  }

  .profile-password-confirm {
    grid-column: auto;
  }

  .profile-form-grid .form-group {
    margin-bottom: 0;
  }

  .profile-form-actions {
    margin-top: 1rem;
  }

  .profile-form-actions .btn,
  .profile-sub-card__receipt {
    min-height: var(--touch-min);
  }

  .profile-sub-card {
    border-radius: 12px;
    padding: 1rem;
  }

  .profile-grid,
  .profile-layout {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }

  /* ── Auth forms ── */
  .auth-card {
    margin: 16px 0;
    border-radius: 16px;
    padding: 24px 20px;
  }

  /* ── Admin tables: stack on mobile ── */
  .admin-grid,
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px;
  }

  /* ── Hide long text on small screens ── */
  .hide-mobile { display: none !important; }
  .show-mobile { display: block !important; }

  /* ── GOST source items ── */
  .gost-source-item {
    flex-direction: column;
    gap: 6px;
  }

  /* ── Subscription sidebar status: move to top ── */
  .sidebar .sidebar-section:last-child {
    padding: 12px;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   390px  (iPhone 12/13/14 Mini)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 390px) and (max-width: 767px) {
  .message-bubble { max-width: calc(100% - 36px); }

  .plans-grid .plan-card {
    flex: 0 0 min(300px, 82vw);
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   393px  (iPhone 14/15/16, Pixel 7/8)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 393px) and (max-width: 767px) {
  .chat-messages { padding: 16px 0; }

  .main-content { padding: 16px 14px; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   412px  (Samsung Galaxy S20–S24, Pixel 7/8 Pro)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 412px) and (max-width: 767px) {
  .plans-grid .plan-card {
    flex: 0 0 min(320px, 80vw);
  }

  .admin-grid,
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   430px  (iPhone 15/16 Pro Max)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 430px) and (max-width: 767px) {
  .main-content { padding: 20px 16px; }

  .chat-messages { padding: 20px 0; }

  .message-bubble { max-width: calc(100% - 36px); }

  .plans-grid .plan-card {
    flex: 0 0 320px;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   480px  (Phones landscape)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 480px) and (max-width: 767px) {
  .admin-grid,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .message-bubble { max-width: calc(100% - 36px); }

  .plans-grid {
    justify-content: flex-start;
  }

  .plans-grid .plan-card {
    flex: 0 0 300px;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   600px  (Surface Duo, iPad mini portrait)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 600px) and (max-width: 767px) {
  .admin-grid,
  .stats-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  .plans-grid {
    justify-content: center;
  }

  .plans-grid .plan-card {
    flex: 0 0 260px;
  }

  .message-bubble {
    max-width: 460px;
  }

  .main-content { padding: 20px 20px; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   768px  (iPad portrait, tablets) — TRANSITION POINT
   At 768px we start showing the sidebar again
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  /* ── Restore desktop patterns ── */
  .mobile-bottom-nav { display: none; }
  .burger-btn        { display: none; }
  .mobile-overlay    { display: none !important; }

  .mobile-only  { display: none !important; }
  .desktop-only { display: block !important; }
  .tablet-only  { display: block !important; }

  body { padding-bottom: 0; }

  /* ── Sidebar: slide back in ── */
  .sidebar {
    position: static !important;
    transform: none !important;
    display: flex !important;
    flex-direction: column;
    width: 220px;
    transition: none;
    border-right: 1px solid var(--border-light) !important;
  }

  /* ── App shell: two columns (sidebar + main) ── */
  .app-shell {
    display: grid !important;
    grid-template-columns: 220px 1fr !important;
    grid-template-rows: 1fr;
  }

  body.page-scroll .app-shell {
    grid-template-rows: auto !important;
    min-height: auto !important;
  }

  /* ── Navbar: restore ── */
  .navbar-nav {
    display: flex;
  }

  .btn-eng-mode {
    display: flex;
  }

  .main-content { padding: 1.5rem; }

  /* ── Plans ── */
  .plans-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)) !important;
    gap: 20px;
    overflow-x: visible;
    margin: 0;
    padding: 0;
  }

  .plan-card { flex: unset; width: auto !important; }

  /* ── Chat ── */
  .chat-layout {
    height: calc(100dvh - 56px);
    margin: -1.5rem -1.5rem 0;
    display: grid !important;
    flex-direction: unset;
  }

  /* Панель сессий видна начиная с 768px */
  .sessions-panel {
    display: flex !important;
  }

  .chat-input-bar {
    position: static;
    padding: 1rem 1.5rem;
    padding-bottom: 1rem;
  }

  /* ── Tables ── */
  .data-table-wrapper { margin: 0; padding: 0; }
  .data-table { min-width: auto; }

  .admin-grid,
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) !important;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   834px  (iPad Pro 11" portrait)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 834px) {
  .app-shell {
    grid-template-columns: 240px 1fr !important;
  }

  .sidebar { width: 240px; }

  .chat-layout {
    grid-template-columns: 260px 1fr !important;
    grid-template-rows: 1fr auto;
  }

  .sessions-panel {
    display: flex !important;
  }

  .plans-grid {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)) !important;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   1024px  (iPad landscape, Chromebook)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 1024px) {
  .app-shell {
    grid-template-columns: 240px 1fr !important;
  }

  .chat-layout {
    grid-template-columns: 280px 1fr !important;
  }

  .main-content { padding: 2rem 1.5rem; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   1280px  (Laptops)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 1280px) {
  .app-shell {
    grid-template-columns: 260px 1fr !important;
  }

  .sidebar { width: 260px; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   1440px  (Desktops)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 1440px) {
  .container { max-width: 1400px; }

  .chat-messages { padding: 2rem; }

  .message-bubble { max-width: 800px; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   1920px  (Wide monitors)
───────────────────────────────────────────────────────────────────────────── */
@media (min-width: 1920px) {
  .container { max-width: 1600px; }

  .app-shell {
    grid-template-columns: 280px 1fr !important;
  }

  .sidebar { width: 280px; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   Landscape orientation fixes
───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 767px) and (orientation: landscape) {
  :root {
    --navbar-h: 44px;
    --bottom-nav-h: 52px;
  }

  .navbar { height: 44px; }

  .chat-layout {
    height: calc(100dvh - 44px);
  }

  .chat-messages { padding: 8px 0; }

  /* In landscape on small phones, sidebar draw could be wider */
  .sidebar {
    width: min(320px, 60vw);
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   iOS Safari specific fixes
───────────────────────────────────────────────────────────────────────────── */
/* Prevent elastic scroll on iOS for fixed elements */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .mobile-bottom-nav,
  .chat-input-bar,
  .search-sheet {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .navbar {
    padding-top: env(safe-area-inset-top);
  }
}

/* Disable 300ms delay on iOS older than 13 */
a,
button,
input[type="button"],
input[type="submit"],
.btn,
.session-item,
.sidebar-link,
.bottom-nav-item {
  -webkit-tap-highlight-color: transparent;
}

/* Fix for 100vh on iOS Safari (use dvh where available) */
@supports (height: 100dvh) {
  .chat-layout {
    height: calc(100dvh - var(--navbar-h));
  }
}

/* ============================================================================
   LIGHT THEME — detailed overrides for all mobile components
   ============================================================================ */
body.light-theme .burger-btn span {
  background: rgba(15, 23, 42, 0.75);
}

body.light-theme .mobile-theme-btn {
  color: rgba(15, 23, 42, 0.65);
}

body.light-theme .pull-refresh-indicator {
  color: var(--text-light-muted);
}

body.light-theme .pull-refresh-spinner {
  border-color: var(--border-light);
  border-top-color: var(--marine-600);
}

body.light-theme .typing-indicator {
  background: #fff;
  border-color: var(--border-light);
}

body.light-theme .typing-dot {
  background: var(--text-light-muted);
}

body.light-theme .swipe-action {
  background: var(--color-danger);
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */
@media (forced-colors: active) {
  .burger-btn span { background: ButtonText; }
  .mobile-bottom-nav { border-top-color: ButtonBorder; }
  .bottom-nav-item { color: ButtonText; }
  .bottom-nav-item.active { color: Highlight; }
}

/* Focus-visible for keyboard nav */
.burger-btn:focus-visible,
.btn:focus-visible,
.bottom-nav-item:focus-visible,
.form-control:focus-visible,
.sidebar-link:focus-visible {
  outline: 2px solid var(--marine-400);
  outline-offset: 2px;
}
