/* Phone layout. Keep desktop rules and the existing sidebar store intact. */
@media (max-width:768px) {
  html,body { width:100%; height:100%; height:100dvh; min-width:0; }
  body > .container { height:100%; min-height:0; }
  #right-panel { width:100%!important; margin-left:0!important; min-width:0!important; padding-top:96px!important; }
  #left-panel { position:fixed!important; inset:0 auto 0 0!important; width:min(86vw,300px)!important; min-width:0!important; height:100dvh!important; z-index:1200!important; padding-bottom:env(safe-area-inset-bottom); }
  #left-panel.hidden { display:none!important; }
  .sidebar-overlay { display:none!important; position:fixed!important; inset:0!important; z-index:1190!important; background:rgba(0,0,0,.45); }
  .sidebar-overlay.visible { display:block!important; }
  #sidebar-header-panel { position:fixed!important; top:env(safe-area-inset-top,0px)!important; left:8px!important; z-index:1210!important; }
  #sidebar-header-panel:not(.sidebar-header-panel-open) { width:88px!important; min-width:88px!important; }
  #sidebar-header-panel #hide-button { gap:4px!important; }
  #sidebar-header-panel :is(#toggle-sidebar,#ma-chat-search-trigger) { width:40px!important; min-width:40px!important; height:44px!important; }
  #sidebar-header-panel .ma-header-server { position:fixed!important; left:8px!important; top:calc(52px + env(safe-area-inset-top,0px))!important; transform:none!important; }
  #sidebar-header-panel.sidebar-header-panel-open .ma-header-server { display:none!important; }
  /* Server selector in fixed header: compact on mobile */
  .ma-server-trigger { max-width:calc(100vw - 100px)!important; height:36px!important; font-size:12px!important; padding:0 10px!important; border-radius:9px!important; }
  .ma-server-menu { position:fixed!important; top:100px!important; left:8px!important; width:min(340px,calc(100vw - 16px))!important; max-width:calc(100vw - 16px)!important; max-height:60dvh; }
  /* margin-top:5.6px on the element shifts it from top:4px → visual y≈9.6px. Remove margin and
     set top:1px so 42px-tall bell button center lands at y=22 (matches 44px toggle center). */
  #time-date-container { position:fixed!important; top:1px!important; right:56px!important; max-width:calc(100vw - 156px)!important; gap:4px!important; transform:none!important; margin-top:0!important; }
  #time-date-container .project-dropdown-button { max-width:96px!important; min-width:0!important; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  #time-date-container .dropdown-menu { position:fixed!important; top:54px!important; right:8px!important; left:auto!important; max-width:calc(100vw - 16px)!important; max-height:65dvh; overflow:auto; }
  /* top:0 → 44px-tall monitor button center at y=22, same as toggle */
  .ma-theme { top:0!important; right:8px!important; }
  .ma-theme-trigger { width:44px!important; height:44px!important; }
  #right-panel #chat-history { padding-inline:12px!important; padding-top:8px!important; overscroll-behavior:contain; }
  #input-section { flex:none!important; width:calc(100% - 16px)!important; padding-bottom:max(8px,env(safe-area-inset-bottom))!important; }
  .welcome-container { padding:12px 8px 20px!important; min-height:0!important; overflow-y:auto!important; }
  .welcome-shell { width:100%!important; flex-basis:auto!important; min-width:0!important; }
  /* Hide redundant model name title on welcome screen (already visible in input bar's model button) */
  .welcome-hero .welcome-current-model { display:none!important; }
  .welcome-hero { margin-bottom:0!important; }
  #right-panel :is(.welcome-composer,#input-section) .input-row { grid-template-columns:40px 40px minmax(0,1fr) auto!important; grid-template-rows:minmax(40px,auto) 44px!important; column-gap:4px!important; padding:10px!important; min-width:0!important; }
  #right-panel :is(.welcome-composer,#input-section) #chat-input { font-size:16px!important; max-height:30dvh!important; overflow-y:auto!important; }
  .attachment-trigger-label { display:none!important; }
  #right-panel :is(.welcome-composer,#input-section) #chat-buttons-wrapper { gap:4px!important; }
  #right-panel :is(.welcome-composer,#input-section) #send-button { width:44px!important; min-width:44px!important; height:44px!important; }
  #right-panel .ma-composer-actions summary { width:40px; height:44px; }
  .ma-composer-actions-menu { position:fixed!important; left:8px!important; right:8px!important; bottom:160px!important; width:auto!important; max-height:50dvh; overflow:auto; }
  .welcome-model-dropdown,.model-switcher-dropdown,.context-window-popover { max-width:calc(100vw - 24px)!important; }
  #chat-history :is(.message-body,.msg-content,.markdown-block-wrap,.agent-file-cards) { min-width:0; max-width:100%; }
  #chat-history :is(pre,.message-markdown-table-wrap) { max-width:100%; overflow-x:auto; }
  #chat-history img { max-width:100%; height:auto; }
  #chat-history .agent-file-card { min-width:0; flex-wrap:wrap; overflow-wrap:anywhere; }
  .modal.show > .modal-inner { left:50vw!important; top:50dvh!important; width:calc(100vw - 16px)!important; max-width:calc(100vw - 16px)!important; max-height:calc(100dvh - 16px)!important; }
  .modal.show > .modal-inner > .modal-scroll { min-width:0!important; padding:12px!important; overflow:auto!important; }
  .modal-footer { flex-wrap:wrap!important; gap:8px!important; }
  .ma-settings { grid-template-columns:minmax(0,1fr)!important; min-width:0!important; }
  .ma-tabs { display:flex!important; overflow-x:auto!important; padding:8px!important; }
  .ma-tabs button { flex:none; min-height:44px; }
  .ma-content { min-width:0!important; padding:12px!important; }
  .ma-plans,.ma-info-grid,.ma-metrics,.ma-theme-options { grid-template-columns:minmax(0,1fr)!important; }
  .ma-renew-modal > article { width:calc(100vw - 32px)!important; max-height:calc(100dvh - 32px); overflow:auto; padding:20px!important; }
  .modal input:not([type=checkbox]):not([type=radio]),.modal textarea,.modal select { font-size:16px!important; max-width:100%; box-sizing:border-box; }
  .ma-admin { min-width:0!important; padding:8px!important; }
  .ma-admin .cards article { flex-wrap:wrap; }
  .ma-admin nav button { flex:none; min-height:44px; }
  .ma-admin .form-grid { grid-template-columns:minmax(0,1fr)!important; }
  .ma-admin .ma-rich-toolbar { flex-wrap:wrap!important; }
  /* Touch improvements */
  button,a,[role="button"],input,select,textarea,summary { touch-action:manipulation; }
  #chat-history { overscroll-behavior-y:contain; }
  /* ── top-right icon buttons: remove card styling on mobile ──
     .notification-toggle and .ma-theme-trigger have white bg + border + box-shadow
     (card look) on desktop. On mobile they should be flat like #toggle-sidebar
     (transparent, no border, no shadow). */
  /* .ma-theme-trigger: no competing !important rule, (0,1,0) wins */
  .ma-theme-trigger {
    background:transparent!important;
    background-color:transparent!important;
    border:none!important;
    box-shadow:none!important;
  }
  /* .notification-toggle: inline <style> has .notification-toggle{background:var(--surface)!important}
     which loads AFTER external CSS in cascade, so equal specificity (0,1,0) !important loses.
     Use #time-date-container .notification-toggle (specificity 1,1,0) to win. */
  #time-date-container .notification-toggle {
    background:transparent!important;
    background-color:transparent!important;
    border:none!important;
    box-shadow:none!important;
  }
  /* ── model picker dropdown: prevent viewport overflow ──
     .welcome-model-menu / .model-switcher-dropdown are position:absolute relative
     to a parent that starts at x≈107, so the 330px-wide menu overflows right by 62px.
     On mobile switch to position:fixed so coords are viewport-relative. */
  /* Use .welcome-composer .welcome-model-menu (specificity 0,2,0) to beat
     mineassist-theme.css .welcome-composer .welcome-model-menu (0,2,0) which has
     top:auto!important; bottom:calc(100%+0.5rem)!important.
     mineassist-mobile.css loads AFTER theme → equal-specificity !important = later wins. */
  .welcome-composer .welcome-model-menu,
  .model-switcher-dropdown {
    position:fixed!important;
    top:96px!important; /* below header (52px) + server label (36px) + 8px gap */
    left:8px!important;
    right:8px!important;
    bottom:auto!important;
    width:auto!important;
    max-width:none!important;
    max-height:calc(100dvh - 80px)!important;
    overflow-y:auto!important;
    z-index:2000!important;
    transform:none!important;
  }
  /* ── settings modal: tab overflow fade indicator ──
     8 tabs total, only ~3 fit in 335px. The mask gradient fades the last 48px
     of the tab strip to signal there are more tabs to swipe. */
  .settings-modal .ma-tabs {
    -webkit-mask-image:linear-gradient(to right,black 0%,black calc(100% - 48px),transparent 100%);
    mask-image:linear-gradient(to right,black 0%,black calc(100% - 48px),transparent 100%);
  }
  /* Ensure settings content scrolls properly within the modal */
  .settings-modal .modal-scroll { overflow:auto!important; }
  .settings-modal .ma-content { overflow-y:auto!important; }
}
/* ── mobile-fix v2 2026-10-04 ────────────────────────────────────────────────
   Fix double sidebar overlay: left-sidebar.html already renders one .sidebar-overlay
   inside .sidebar-shell; the one inside #sidebar-overlay wrapper in index.html
   is redundant on mobile and doubles the darkening (45%+45% → ~70%).
   Hiding the wrapper version restores the intended 45% opacity. */
#sidebar-overlay > .sidebar-overlay { display:none!important; }
/* ── chat-nav-buttons: hide on mobile (position:absolute; right:20px overlaps AI messages) ──
   On desktop the chat area is wide enough; on ≤768px the buttons at x≈327 cut into
   the AI response text (process-group-response right-edge ≈343px → 16px overlap).
   Mobile users scroll naturally, so removing these navigation arrows is safe. */
@media (max-width:768px) {
  #chat-nav-buttons { display:none!important; }
  /* .ma-header-server lives inside #sidebar-header-panel (z-index:1210).
     When sidebar is open (.sidebar-header-panel-open), position:fixed moves it to
     left:8px top:52px — still within the sidebar area and above #left-panel (z-index:1200)
     because it inherits the 1210 stacking context. This causes it to overlap the
     "Новый чат" button.
     mineassist-panel-layout.css has: #sidebar-header-panel #hide-button > .ma-header-server
     with display:block!important (specificity 2-1-0). Match that selector + add class condition
     for specificity 2-2-0 to win. */
  #sidebar-header-panel.sidebar-header-panel-open #hide-button > .ma-header-server { display:none!important; }
}
