/* Hanna phone layout fixes (Nov 2026). Loaded last on portal, shared workspace and 360 pages.
 * Everything is inside a phone-width media query, so desktop is unchanged. */
@media (max-width: 760px) {
  html, body { overflow-x: clip; }

  /* ---- Portal (/workspace): the desktop sidebar's !important width and offset beat the old phone rules */
  .shell .sidebar { position: sticky !important; top: 0; z-index: 20; width: auto !important; height: auto !important;
    padding: 10px 12px 8px !important; overflow: visible !important; border-right: 0 !important;
    border-bottom: 1px solid var(--ht-line, var(--line)); }
  .shell .main-shell { margin-left: 0 !important; width: auto; }
  .shell .sidebar .hm-sidebar-top { margin-bottom: 8px; }
  .shell .sidebar nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; padding-bottom: 4px; }
  .shell .sidebar nav .nav-item { flex: 0 0 auto; white-space: nowrap; scroll-snap-align: start; min-height: 40px; }
  .shell .sidebar .sidebar-bottom, .shell .sidebar .nav-label { display: none !important; }
  .shell .hm-sidebar-tools [data-action="popout-sidebar"] { display: none; }
  .shell .topbar { height: auto !important; min-height: 0 !important; position: relative !important; flex-wrap: wrap; gap: 8px;
    padding: 8px 12px !important; align-items: center; }
  .shell .hm-topbar-left { min-width: 0; flex: 1 1 auto; }
  .shell .hm-topbar-left select, .shell .hm-topbar-left .hm-ws-lock { max-width: 100%; min-width: 0; text-overflow: ellipsis; }
  .shell .topbar-right { margin-left: auto; gap: 8px; }
  .shell .topbar-right #iosInstallBtn { display: none !important; }
  .shell .content { padding: 12px 12px 0 !important; }
  .content .metric-row { flex-wrap: wrap; gap: 8px; }
  .content .metric-row > * { flex: 1 1 140px; min-width: 0; }
  .content .invite-row { flex-wrap: wrap; gap: 8px; }
  .content .invite-actions { flex-wrap: wrap; }
  .content .table-scroll { overflow-x: auto; max-width: 100%; }

  /* ---- Shared workspace pages (/shared/calendar, email, connect, voice, details) */
  .sw-header { height: auto !important; min-height: 48px; flex-wrap: wrap; row-gap: 6px; padding-top: 6px; padding-bottom: 6px; }
  .sw-header .hanna-brand-lockup-std { flex: 1 1 auto; min-width: 0; }
  .sw-header-right { margin-left: auto; flex-wrap: wrap; gap: 6px; }
  .cal-board, .cal-split { min-width: 0; max-width: 100%; }
  .cal-split, .cal-cards-row { grid-template-columns: minmax(0, 1fr) !important; }
  .cal-card, .cal-grid-card, .cal-right-pads { min-width: 0 !important; max-width: 100%; }
  .cal-right-pads { width: auto !important; }
  .cal-card > div { flex-wrap: wrap; gap: 6px; }
  .cal-grid-head, .cal-grid { grid-template-columns: repeat(7, minmax(0, 1fr)) !important; }
  .cal-week-load, .cal-load-lane { min-width: 0; max-width: 100%; overflow-x: auto; }
  .connect-card-footer, .connect-card-actions { flex-wrap: wrap; gap: 6px; min-width: 0; }
  .mc-shell { grid-template-columns: minmax(0, 1fr) !important; }
  .mc-shell > * { min-width: 0 !important; max-width: 100%; }
  .mc-side { flex-direction: column; flex-wrap: nowrap; }
  .mc-folders, .mc-tabs, .mc-toolbar { min-width: 0; max-width: 100%; overflow-x: auto; flex-wrap: nowrap; }

  /* ---- Hanna 360 */
  header.topbar.hanna-top-chrome { height: auto !important; min-height: 48px; flex-wrap: wrap; row-gap: 8px; padding-top: 6px; padding-bottom: 6px; }
  header.topbar .top-actions { margin-left: auto; }
  .hm-360-hero-lockup { flex-wrap: wrap; gap: 12px; }
  .hm-360-hero-meta { flex: 1 1 200px; min-width: 0; width: auto !important; }
}

/* ===== iphone1 (2026-11-08): iPhone fit pass. Portrait rules sit inside max-width 500px; landscape rules inside
 * max-width 932px + pointer: coarse. Desktop, tablet and mouse layouts are unchanged. Only fitting, no new look. ===== */
@media (max-width: 500px) {
  /* -- Workspace (/workspace): only the brand + nav strip stays pinned while scrolling; the workspace row scrolls away.
        Both bars were sticky at top 0, so the top bar slid over the brand pill and the pair covered ~30% of the screen. */
  html:not([data-hanna-fullscreen]) body .shell .main-shell > header.topbar.hanna-top-chrome { position: relative !important; top: auto !important; }
  /* Workspace selector, Options and avatar share one row (the selector had a 270px minimum, pushing Options to a second row) */
  .shell .main-shell > header.topbar { flex-wrap: nowrap !important; }
  .shell .hm-topbar-left { flex: 1 1 0% !important; min-width: 0 !important; }
  html body .shell .hm-topbar-left select#workspace-select#workspace-select { min-width: 0 !important; width: 100% !important; max-width: 100% !important; }
  .shell .main-shell > header.topbar .topbar-right { flex: 0 0 auto !important; width: auto !important; margin-left: 0 !important; }
  /* Pillar view: the hero row wraps so "← All Workspaces" stays on screen (it was pushed 90px past the right edge) */
  .hm-pillar-hero { flex-wrap: wrap !important; row-gap: 12px; }
  .hm-pillar-hero > .hm-reset-pillar { margin-left: 0 !important; }

  /* -- Hanna 360: the left nav was a 326px sticky block (38% of an iPhone 15, 49% of an SE) on every page.
        On a phone it scrolls with the page and each nav group is one swipeable row, like the Workspace nav. */
  #app > .shell { grid-template-columns: minmax(0, 1fr) !important; }
  #app > .shell > aside.sidebar, #app > .shell > aside.sidebar :is(#main-nav, #app-nav) { min-width: 0 !important; max-width: 100% !important; }
  #app > .shell > aside.sidebar { position: relative !important; top: auto !important; height: auto !important; padding: 6px 12px 6px !important; }
  #app > .shell > aside.sidebar :is(#main-nav, #app-nav) { flex-wrap: nowrap !important; overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; scrollbar-width: none; padding-bottom: 2px !important; }
  #app > .shell > aside.sidebar :is(#main-nav, #app-nav)::-webkit-scrollbar { display: none; }
  #app > .shell > aside.sidebar :is(#main-nav, #app-nav) > .nav-button { flex: 0 0 auto !important; white-space: nowrap; scroll-snap-align: start; min-height: 40px; }
  #app > .shell > aside.sidebar .hanna-pop-left { display: none !important; }

  /* -- Shared pages: Calendar's view tabs and actions wrap instead of running off the right edge */
  .cal-subnav-bar { flex-wrap: wrap !important; row-gap: 8px; }
  .cal-subnav-bar .ai-subnav-actions { flex-wrap: wrap; min-width: 0; }

  /* -- CRM top bar: the action buttons wrap instead of pushing Options off screen; the Ctrl K pill shows its label */
  header.topbar.hanna-top-chrome .topbar-actions { flex-wrap: wrap !important; min-width: 0 !important; max-width: 100% !important; row-gap: 8px; }
  header.topbar.hanna-top-chrome .topbar-actions kbd { color: inherit !important; background: none !important; border-color: currentColor !important; }
}

@media (max-width: 500px) {
  /* -- Writer / Sheets start pages: the 48px side padding left the recent list 297px wide, so dates broke over 3 lines */
  .start-shell .start { padding: 20px 14px 40px !important; }
  .start-shell .doc-table td.muted { white-space: nowrap; }
  /* The Tools / Hanna buttons belong to an open document; on the start page they covered the template cards */
  html.hm-phone body:not(:has(.workspace)) .hm-phone-bar.hm-phone-bar { display: none !important; }
  /* With the Tools or Hanna sheet open, the two buttons sat on the sheet's last row (Hanna's mic and Send).
     The open sheet now ends with room for them. */
  html.hm-phone.hm-ai-open body .workspace.workspace.workspace.workspace .work-area .side-panel.side-panel,
  html.hm-phone.hm-tools-open body .workspace.workspace.workspace.workspace section.ribbon.ribbon {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)) !important; }

  /* -- AI chat: the top strip (apps, F2 full screen, + New chat, MIC, Canvas, Show me, Sign out) ran 1,450px wide and
        was clipped at 393px, so everything after "CRM" could not be reached. It now swipes sideways. */
  .ai-shell .ai-top-chrome { overflow-x: auto !important; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .ai-shell .ai-top-chrome::-webkit-scrollbar { display: none; }
  .ai-shell .ai-top-chrome > :is(.ai-top-left, .ai-top-right) { flex: 0 0 auto !important; }
  /* "Send to" and "Quick actions" share the row half and half (the grid kept three 110px columns for two fields) */
  .ai-shell .ai-floating-roles-group { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .ai-shell .ai-floating-roles-group > .ai-floating-field { width: auto !important; min-width: 0; }
  .ai-shell .ai-floating-roles-group .ai-floating-select { width: 100% !important; }
}

@media (max-width: 500px) {
  /* -- Calendar: NEW EVENT / SYNC / ASK HANNA / SETTINGS wrap instead of running past the right edge */
  .cal-header-bar .cal-header-actions { flex-wrap: wrap !important; min-width: 0; row-gap: 8px; }

  /* -- Form fields: iOS zooms the whole page into any field under 16px when it is tapped, and stays zoomed.
        Fields keep their look; only the type size moves to 16px. Document text (Writer page, Design Lab report text)
        and the editors' dense ribbons are left alone. The ID-weighted :not() beats the top-bar pill rules. */
  html body :is(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=button]):not([type=submit]):not([type=reset]):not([type=file]):not([type=color]):not([type=image]), textarea, select):not(#\#):not(#\#):not(section.ribbon *):not(.ribbon *):not(.sheet-grid *):not(.grid *) {
    font-size: 16px !important; }
}

/* -- Install banner (Safari, first visit): the page gets room below its last line so the banner can't hide the
      sign-in buttons or anything else at the bottom (it covered "Continue with Google" on an iPhone SE). */
@media (max-width: 500px), (max-width: 932px) and (pointer: coarse) and (max-height: 500px) {
  body:has(> .hanna-ios-banner) { padding-bottom: calc(150px + env(safe-area-inset-bottom, 0px)) !important; }
}

/* -- Options panel. (1) Its layer had no z-index, so app tiles (z-index 1-2) were painted over the open panel.
      (2) The panel opens right-aligned to the Options button, so wherever the button was not the right-most control
      the panel ran off the left edge (by 30px on Workspace, 70px on 360, 139px on Email/Chat/Calendar, 155px on
      Accounting, 209px on Design Lab). On a phone the button moves to the right end of its row. */
@media (max-width: 500px), (max-width: 932px) and (pointer: coarse) and (max-height: 500px) {
  html > [data-hanna-options-layer] { z-index: 2147482000 !important; }
}
@media (max-width: 500px) {
  :is(.topbar-right, .top-actions, .sw-header-right, .topbar-actions, header.hanna-top-chrome, .app > .top) > hanna-options:not([inline]) {
    order: 99 !important; margin-left: auto !important; }
}

@media (max-width: 500px) {
  /* -- Admin tables (Activity, People & access ...): they already swipe sideways; a minimum width stops the Details
        column being crushed to one character per line */
  .content .table-scroll > table { min-width: 600px; }
}

/* ===== Landscape phones (iPhone 15: 852 x 393). Writer / Sheets now use phone mode here too (hanna-phone-editor.js);
 * their three-row title bar becomes one row so the document keeps the height. ===== */
@media (max-width: 932px) and (pointer: coarse) and (max-height: 500px) {
  html.hm-phone body .titlebar.titlebar { flex-wrap: nowrap !important; }
  html.hm-phone body .titlebar .title-center { order: 2 !important; flex: 1 1 auto !important; min-width: 0; justify-content: center !important; }
  html.hm-phone body .titlebar .titlebar-right { order: 3 !important; margin-left: 0 !important; flex-wrap: nowrap !important; }
  html.hm-phone body .titlebar .qat { flex: 0 1 auto !important; flex-wrap: nowrap !important; }
}

/* ===== iphone1 · approved proposals (Nasir, 2026-11-08 08:44Z): F14 chat drawer, F18 Design Lab row, F19 Plans header,
 * F22 40px pills and targets, F23 safe-area insets, F25 11px minimum type. F11 is in the Writer/Sheets/Design Lab
 * viewport meta; the Options button height and the chat drawer's close/Plans pill link are in hanna-phone-fit.js. ===== */
@media (max-width: 500px) {
  /* F14 · AI chat: the Navigation panel (Find, Conversation, Saved chats, New chat, GO LIVE, look-ups, attachments) slides
     in from the left. The chat's own NAVIGATION button opens it and comes first in the top strip. */
  .ai-shell .ai-top-chrome #top-btn-nav { order: -1 !important; }
  .ai-shell.ai-coordinator .ai-nav-sidebar.ai-nav-sidebar { position: fixed !important; top: 0 !important; bottom: 0 !important; left: 0 !important;
    order: 0 !important; width: min(86vw, 340px) !important; min-width: 0 !important; height: auto !important; max-height: none !important;
    z-index: 2147481500 !important; overflow-y: auto !important; overscroll-behavior: contain; border-top: 0 !important;
    border-right: 1px solid var(--ht-line, #2a3d53) !important; border-radius: 0 12px 12px 0;
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
    padding-left: max(14px, env(safe-area-inset-left, 0px)) !important;
    transform: translateX(-105%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; }
  .ai-shell.ai-coordinator.is-nav-open .ai-nav-sidebar.ai-nav-sidebar { transform: none; visibility: visible; transition: transform .22s ease;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45), 18px 0 48px rgba(0, 0, 0, .35); }
  .ai-shell.ai-coordinator .ai-nav-sidebar .ai-sidebar-nav-title { cursor: pointer; min-height: 40px; display: flex; align-items: center; }

  /* F18 · Design Lab: the top bar is one row that swipes sideways (it wrapped into six rows of pills) */
  .app > header.top { flex-wrap: nowrap !important; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .app > header.top::-webkit-scrollbar { display: none; }
  .app > header.top > * { flex: 0 0 auto !important; }
  .app > header.top > .grow { display: none !important; }

  /* F19 · Plans: one swipeable header row that starts with the standard HANNA WORKSPACE · Plans pill (it stays put while
     the row moves). Light themes: no pill fill, accent outline, as everywhere else. */
  header.top:has(> #planSel) { flex-wrap: nowrap !important; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; gap: 8px !important; align-items: center !important; }
  header.top:has(> #planSel)::-webkit-scrollbar { display: none; }
  header.top:has(> #planSel) > * { flex: 0 0 auto !important; }
  header.top:has(> #planSel) > .spacer { display: none !important; }
  header.top:has(> #planSel) > .ready { white-space: nowrap; }
  header.top:has(> #planSel) > .brand { position: sticky; left: 0; z-index: 2; height: 40px; box-sizing: border-box; display: inline-flex !important;
    align-items: center; gap: 8px; padding: 0 14px 0 8px !important; border-radius: 7px !important; cursor: pointer; font-size: 0 !important;
    background-color: var(--chassis-2, var(--ht-chrome, #0b1220)); background-image: linear-gradient(var(--hm-pill-bg, var(--ht-accent, #35c8ee)), var(--hm-pill-bg, var(--ht-accent, #35c8ee)));
    border: 1px solid var(--hm-pill-line, transparent); color: var(--hm-pill-ink, var(--ht-accent-ink, #06131e)); box-shadow: 0 0 0 6px var(--chassis-2, var(--ht-chrome, #0b1220)); }
  header.top:has(> #planSel) > .brand > i { display: none !important; }
  header.top:has(> #planSel) > .brand hanna-seal { --seal-size: 22px; width: 22px; height: 22px;
    --seal-ink: var(--hm-pill-ink, var(--ht-accent-ink, #06131e)); --seal-ring: var(--hm-pill-ink, var(--ht-accent-ink, #06131e));
    --seal-a: var(--hm-pill-ink, var(--ht-accent-ink, #06131e)); --seal-b: var(--hm-pill-ink, var(--ht-accent-ink, #06131e)); }
  header.top:has(> #planSel) > .brand::after { content: "Hanna Workspace \00B7  Plans"; font: 700 12px/1 var(--ht-font, Inter, "Segoe UI", system-ui, sans-serif);
    letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
  header.top:has(> #planSel) > :is(button, select, .seg) { min-height: 40px; }

  /* F22 · Touch targets: the standard pill goes from 34px (chat 30px) to 40px tall on phones; icon buttons become 40 x 40.
     Same look, corners and colours (the pill rules in hanna-pill-guard.js); only the height changes. */
  html body header:has(> .hm-master-typo-center) :is(button, select, .demo-badge, .hm-ws-lock, .pill, .back-360-link, .back-360, #sw-back, #sw-360-badge):not(.search-button):not(.hanna-panel-ctrl-btn):not(.brand):not(.sw-brand):not(.has-seal):not(.avatar):not(.icon-button):not(.hm-icon-btn):not(.hm-master-typo-center *):not(.hm-merge-l):not(.hm-merge-r):not(#\#):not(#\#),
  html body header:has(> .hm-master-typo-center) > :is(button, select, .pill, .demo-badge):not(#\#):not(#\#),
  html body header:has(> .hm-master-typo-center) :is(.hm-apps-btn, .hm-chat-only):not(#\#):not(#\#),
  html body header:has(> .hm-master-typo-center) :is(.top-actions, .topbar-right, .sw-header-right, .hm-topbar-left) > :is(button, a, span, select):not(.avatar):not(.icon-button):not(.hm-icon-btn):not(.status-dot):not(.brand):not(.hm-merge-l):not(.hm-merge-r):not(#\#):not(#\#),
  html body .sw-layout :is(.sw-trigger-btn, .sw-btn, .sw-button, .sw-button-quiet, .connect-btn, .btn-action-sm, .btn-refresh, .mc-tool, .cal-btn, .sw-link, .sw-chip):not(#\#):not(#\#),
  html body .ai-shell :is(.ai-top-btn, .ai-tool-pill-btn, .ai-find-btn, .ai-btn-new-chat, .ai-btn-go-live):not(#\#):not(#\#),
  html body .hm-merge-l.hm-merge-l.hm-merge-l.hm-merge-l.hm-merge-l.hm-merge-l:not(#\#):not(#\#), html body .hm-merge-r.hm-merge-r.hm-merge-r.hm-merge-r.hm-merge-r.hm-merge-r:not(#\#):not(#\#),
  html body :is(.sidebar .hm-sidebar-top > a.brand, header.topbar a.brand.hm-brand-inline):not(#\#):not(#\#),
  html body .titlebar #hanna-report-lab-link#hanna-report-lab-link:not(#\#) {
    height: 40px !important; min-height: 40px !important; max-height: 40px !important; }
  html body .ai-shell :is(.ai-nav-pill, .ai-toggle-pill):not(#\#) { min-height: 40px !important; }
  html body header:has(> .hm-master-typo-center) :is(.icon-button, .hm-icon-btn, button.avatar, span.avatar, #close):not(#\#):not(#\#) {
    width: 40px !important; height: 40px !important; min-height: 40px !important; }
  :is(.hanna-panel-ctrl-btn, .start-shell .doc-actions .icon-btn, .app > header.top > button, .cal-btn) { min-width: 40px; min-height: 40px; }
  .app > header.top :is(select, label.fld > select) { min-height: 40px; }

  /* F23 · Safe areas. Workspace pages draw under the status bar in the installed app (viewport-fit=cover): the pinned
     brand + nav strip now clears it. Bottom bars and drawers clear the home bar. (env() is 0 where it does not apply.) */
  .shell > .sidebar { padding-top: max(10px, env(safe-area-inset-top, 0px)) !important; }
  .shell.pills > .pill-rail { bottom: calc(34px + env(safe-area-inset-bottom, 0px)) !important; }

  /* F25 · No text under 11px on phones: every label measured at 9-10.5px in the scan (eyebrows, badges, table heads,
     footers, small captions). Document text, report pages and chart labels keep their own sizes. */
  :is(.eyebrow, .sw-eyebrow, .auth-tag, .auth-form .fine, .cal-card-eyebrow, .cal-status-badge, #cal-card-view-label, .badge-tag, .app-tag,
      .event-detail, .ai-sidebar-section-title, .ai-sidebar-nav-title, .left-panel-master-title, .hm-sf-l, .file-badges .pill, .heading-row .pill,
      .section-title .pill, .hanna-univ-left-ctrl > span, .ribbon-group-label > span, .ribbon-tabs > button, .app-footer > :is(button, span),
      .page-footer > span, .destination-form > label, .subscription-item > button, .top-actions > button.avatar, #pdf-workflows > button,
      .template > small, .co-asst > small, .bar-col > small, .cal-load-lane > :is(small, span), .content th, .subscription-item small,
      .destination-form small, .file-row small, header .ghost > kbd) { font-size: 11px !important; }
}
