/* Portal Ausa: mobile presentation only. Loaded after the current portal styles.
   Behaviour hooks: portalMobileOverlayOpen, portalMobileCalendar and
   portalMobileChatConversation. Navigation column count remains owned by JS. */
@media (max-width: 760px) {
  :root {
    --portal-mobile-bg: #f6f6f3;
    --portal-mobile-line: #e3e2da;
    --portal-mobile-muted: #696961;
    --portal-mobile-header-height: calc(64px + env(safe-area-inset-top));
    --portal-mobile-nav-height: calc(74px + env(safe-area-inset-bottom));
    --portal-mobile-bottom-space: var(--portal-mobile-nav-height);
  }

  html { scroll-padding-top: calc(var(--portal-mobile-header-height) + 12px); }
  body { font-size: 14px; line-height: 1.45; background: var(--portal-mobile-bg); }
  body .app { width: 100% !important; min-width: 0; margin-left: 0 !important; }
  body .content {
    width: 100%; min-width: 0;
    padding: 20px max(16px, env(safe-area-inset-right)) calc(var(--portal-mobile-bottom-space) + 32px) max(16px, env(safe-area-inset-left)) !important;
  }
  body .view { min-width: 0; }
  body button { touch-action: manipulation; }
  body button:focus-visible, body a:focus-visible, body summary:focus-visible {
    outline: 3px solid #9b7100; outline-offset: 3px;
  }
  body .btn { min-height: 44px !important; border-radius: 11px; font-size: 13px; line-height: 1.3; }
  body .btn.small { min-height: 42px !important; padding: 9px 12px !important; font-size: 12px; }
  body .pageHead { gap: 14px; margin-bottom: 20px !important; }
  body .pageHead h1, body .heroTitle { font-size: 30px !important; line-height: 1.08 !important; letter-spacing: -.025em !important; }
  body .pageHead p { font-size: 13px !important; line-height: 1.55 !important; color: var(--portal-mobile-muted); }
  body .eyebrow { font-size: 10px; line-height: 1.4; }
  body .sectionTitle { font-size: 21px !important; margin: 24px 0 12px !important; }
  body .card { padding: 16px !important; border-radius: 16px !important; border-color: var(--portal-mobile-line); }
  body .pill { font-size: 10px; line-height: 1.3; letter-spacing: .025em; }
  body .empty { font-size: 13px; line-height: 1.6; padding: 24px 16px; }
  body .tableWrap, body .accountingTable { overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }

  /* One quiet header, with search in its own row when requested. */
  body .topbar {
    position: sticky; top: 0; z-index: 40 !important;
    display: grid !important; grid-template-columns: minmax(0, 1fr) !important;
    min-height: var(--portal-mobile-header-height) !important; height: auto !important;
    gap: 8px !important;
    padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)) !important;
    background: rgba(246, 246, 243, .97); border-bottom: 1px solid var(--portal-mobile-line);
  }
  body .topbar .mobileMenu, body #quickAddTop { display: none !important; }
  body .topbar .topActions {
    grid-column: 1; grid-row: 1; width: 100%; max-width: none !important; min-width: 0;
    display: grid !important; grid-template-columns: minmax(0, 1fr) 44px 44px !important;
    gap: 8px !important; margin: 0 !important; min-height: 44px;
  }
  body .topbar .accessSwitcher {
    width: 100% !important; min-width: 0 !important; max-width: none !important;
    height: 44px !important; min-height: 44px !important; padding: 4px 0 !important;
    border: 0; background: transparent; box-shadow: none; border-radius: 0 !important;
  }
  body .topbar .accessSwitcher .cloudUser { font-size: 13px !important; line-height: 1.4; color: #171717; font-weight: 700 !important; }
  body .topbar .mobileSearchToggle, body .topbar .topProfileButton {
    width: 44px !important; height: 44px !important; min-width: 44px !important;
    border-radius: 13px !important;
  }
  body .topbar .search { grid-row: 2 !important; margin: 0 !important; }
  body .topbar .search input { min-height: 46px !important; border-radius: 12px; font-size: 16px !important; }
  body .globalSearchResults {
    z-index: 100 !important; top: calc(var(--portal-mobile-header-height) + 56px) !important;
    left: max(12px, env(safe-area-inset-left)) !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    max-height: min(58dvh, 520px) !important; border-radius: 14px !important;
  }
  body .globalSearchResult { min-height: 64px; padding: 12px; }
  body .globalSearchResult b { font-size: 13px; line-height: 1.4; }
  body .globalSearchResult small { font-size: 11px; }
  body .topProfileMenu { top: var(--portal-mobile-header-height) !important; z-index: 130 !important; }
  body .topProfileMenu button { min-height: 48px; font-size: 13px; }

  /* A single stacking order: content 0, header 40, navigation 80,
     menu backdrop 110, menu 120, profile 130, dialogs 140/150. */
  body #mobileBottomNav {
    position: fixed !important; inset: auto 0 0 !important; z-index: 80 !important;
    min-height: var(--portal-mobile-nav-height) !important;
    padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)) !important;
    gap: 4px; background: rgba(255, 255, 255, .98) !important;
    border-top: 1px solid var(--portal-mobile-line) !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, .045) !important;
  }
  body #mobileBottomNav button {
    min-width: 0 !important; min-height: 56px !important; padding: 6px 2px !important;
    gap: 4px !important; border-radius: 12px !important;
    font-size: 10px !important; line-height: 1.2; font-weight: 600 !important;
    color: #65655e !important;
  }
  body #mobileBottomNav button.active { background: #ffbd00 !important; color: #111 !important; font-weight: 700 !important; }
  body #mobileBottomNav .mobileNavIcon { font-size: 22px !important; line-height: 24px !important; height: 24px !important; }
  body #mobileQuickAdd {
    right: max(16px, env(safe-area-inset-right)) !important;
    bottom: calc(var(--portal-mobile-nav-height) + 14px) !important;
    z-index: 75 !important; width: 52px !important; height: 52px !important;
    border-radius: 17px !important; box-shadow: 0 5px 18px rgba(0, 0, 0, .17) !important;
  }
  body.mobileMenuOpen, body.portalMobileOverlayOpen { overflow: hidden !important; }
  body.mobileMenuOpen #mobileNavBackdrop {
    display: block !important; position: fixed !important; inset: 0 !important;
    background: rgba(0, 0, 0, .48) !important; backdrop-filter: blur(3px); z-index: 110 !important;
  }
  body .sidebar {
    z-index: 120 !important; width: 100% !important; inset: auto 0 0 !important;
    display: block !important; overflow-y: auto !important; overscroll-behavior: contain;
    height: min(82dvh, 760px) !important; max-height: calc(var(--portal-mobile-viewport-height, 100dvh) - 28px) !important;
    border-radius: 24px 24px 0 0 !important;
    padding: 12px max(14px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)) !important;
  }
  body .sidebar .workspace { padding: 4px 4px 18px !important; }
  body .sidebar .nav { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px !important; padding: 0 0 12px !important; overflow: visible !important; }
  body .sidebar .nav button { min-height: 62px !important; padding: 12px !important; gap: 10px; font-size: 13px !important; border-radius: 13px !important; }
  body .sidebar .nav button.aiNavButton { min-height: 54px !important; }
  body .sidebar .nav .ico { width: 24px !important; flex: 0 0 24px; }
  body .sidebar .sideBottom { padding: 10px 0 0 !important; margin-top: 8px !important; }
  body .sidebar #ausa-applications,
  body .sidebar #ausa-app-links { max-height: none !important; overflow: visible !important; }
  body .sidebar .portalMobileMenuClose {
    position: absolute; top: 17px; right: max(16px, env(safe-area-inset-right)); z-index: 2;
    display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
    border: 1px solid #414141; border-radius: 13px; background: #202020;
    color: #fff; font: inherit; font-size: 21px; cursor: pointer;
  }
  body .sidebar:has(.portalMobileMenuClose) .workspace { padding-right: 56px !important; }
  body .sidebar #ausa-app-links a, body .sidebar #ausa-applications > a {
    min-height: 46px; padding: 12px !important; font-size: 14px !important;
    line-height: 1.5 !important; border-radius: 11px !important;
  }
  body.mobileMenuOpen #mobileQuickAdd,
  body.portalMobileChatOpen #mobileQuickAdd,
  body.portalMobileOverlayOpen #mobileBottomNav,
  body.portalMobileOverlayOpen #mobileQuickAdd {
    display: none !important; visibility: hidden !important; pointer-events: none !important;
  }
  /* Authentication is opt-in: even the legacy !important navigation rules
     must stay hidden during session restoration and the first-password gate. */
  body:not(.portalMobileAuthenticated) #mobileBottomNav,
  body:not(.portalMobileAuthenticated) #mobileQuickAdd,
  body:not(.portalMobileAuthenticated) .topbar,
  body:not(.portalMobileAuthenticated) .sidebar,
  body:not(.portalMobileAuthenticated) #mobileNavBackdrop,
  body:not(.portalMobileAuthenticated) #desktopSidebarToggle {
    display: none !important; visibility: hidden !important; pointer-events: none !important;
  }
  body .toast { z-index: 180 !important; bottom: calc(var(--portal-mobile-bottom-space) + 12px); border-radius: 12px; font-size: 13px; }
  body.portalMobileOverlayOpen .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }

  /* Task workspace: visible view controls and readable compact cards. */
  body .portal-task-tabs {
    display: flex; flex-wrap: nowrap; gap: 6px; margin: 0 0 20px;
    padding: 4px; border: 1px solid var(--portal-mobile-line); border-radius: 13px; background: #ecece6;
    overflow-x: auto; scrollbar-width: none;
  }
  body .portal-task-tabs::-webkit-scrollbar { display: none; }
  body .portal-task-tabs button {
    flex: 1 0 auto; min-height: 42px; padding: 9px 11px; border: 0;
    border-radius: 9px; background: transparent; font-size: 12px; font-weight: 600; white-space: nowrap;
  }
  body .portal-task-tabs button[aria-current="page"] { background: #fff; box-shadow: 0 1px 5px #0000000d; }
  body .workViewTabs { display: flex !important; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
  body .workViewTabs .btn { flex: 1 1 130px; width: auto !important; min-height: 44px !important; }
  body #view-work .workLayoutTabs { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 7px; margin-bottom: 14px; }
  body #view-work .workLayoutTabs .btn { min-width: 0; font-size: 11px; padding: 9px 7px !important; white-space: normal; }
  body .filterbar, body .workFilterBar { gap: 8px !important; }
  body .filterbar input, body .filterbar select,
  body .field input, body .field select, body .field textarea,
  body .calendarFilter select {
    min-width: 0; min-height: 46px !important; font-size: 16px !important;
    border-radius: 11px; line-height: 1.4;
  }
  body .workFilterBar { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; margin-bottom: 14px; }
  body .workFilterBar input { grid-column: 1 / -1; }
  body #view-work .workListRow {
    grid-template-columns: minmax(0, 1fr) !important; gap: 12px; padding: 15px;
    border-radius: 15px; transform: none !important;
  }
  body #view-work .workDeadlineBlock { display: flex !important; align-items: center; flex-wrap: wrap; gap: 5px 10px; padding: 10px 11px; border-radius: 10px; }
  body #view-work .workDeadlineBlock .label { font-size: 9px; }
  body #view-work .workDeadlineBlock .date { margin: 0; font-size: 22px !important; line-height: 1.1; }
  body #view-work .workDeadlineBlock .relative { margin: 0 0 0 auto; font-size: 11px; text-align: left; }
  body #view-work .workListTitle { margin-top: 8px; font-size: 18px; line-height: 1.35; overflow-wrap: anywhere; }
  body #view-work .workListMeta { font-size: 12px; line-height: 1.5; gap: 8px 12px; }
  body #view-work .workListActions { grid-column: auto; justify-content: flex-start; gap: 7px; padding-top: 10px; border-top: 1px solid #efefe9; }
  body #view-work .workListActions .btn { flex: 1 1 auto; }
  body #view-work .kanban { display: grid !important; grid-template-columns: minmax(0, 1fr) !important; gap: 16px; }
  body #view-work .kanCol { min-height: 0; padding: 12px; border-radius: 15px; }
  body #view-work .kanHead { padding: 2px 2px 12px; font-size: 14px; }
  body #view-work .taskCard { padding: 14px; margin-bottom: 9px; }
  body #view-work .taskTitle { font-size: 14px; line-height: 1.45; }
  body #view-work .taskMeta { font-size: 11px; line-height: 1.5; }
  body .archiveTaskTitle { font-size: 14px; line-height: 1.4; }
  body .archiveTaskRow .btn { justify-self: stretch; }

  /* Calendar enhancement is opt-in, so failed or delayed JS leaves the old views usable. */
  body #view-calendar .calendarHead { grid-template-columns: 44px minmax(0, 1fr) 44px !important; gap: 8px; }
  body #view-calendar .calendarHead .heroTitle { font-size: 20px !important; line-height: 1.25 !important; }
  body #view-calendar .calendarHead .btn { min-width: 44px; min-height: 44px !important; }
  body #view-calendar .calendarTodayBtn { grid-column: 1 / -1; width: 100%; }
  body #view-calendar .calendarViewTabs { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  body #view-calendar .calendarViewTabs .btn { font-size: 12px; }
  body #view-calendar.portalMobileCalendar > .calendarScroll,
  body #view-calendar.portalMobileCalendar > .calendarWeekScroll,
  body #view-calendar.portalMobileCalendar > .calendarDayView { display: none !important; }
  body .portalMobileAgendaPageHead {
    display: flex; flex-direction: row !important; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 20px;
  }
  body .portalMobileAgendaPageHead > div { min-width: 0; }
  body .portalMobileAgendaPageHead h1 { margin: 0; font-size: 30px; line-height: 1.15; letter-spacing: -.025em; }
  body .portalMobileAgendaPageHead .eyebrow { margin-bottom: 4px; }
  body .portalMobileAgendaPageHead .btn { flex: 0 0 auto; width: auto; padding: 10px 12px !important; white-space: nowrap; }
  body #view-calendar .portalMobileModeTabs {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px;
    padding: 4px; margin: 0 0 16px; border: 1px solid var(--portal-mobile-line);
    border-radius: 13px; background: #ecece6;
  }
  body .portalMobileModeTabs button {
    min-width: 0; min-height: 44px; padding: 10px 8px; border: 0; border-radius: 9px;
    background: transparent; color: #62625b; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  }
  body .portalMobileModeTabs button.active,
  body .portalMobileModeTabs button[aria-pressed="true"],
  body .portalMobileModeTabs button[aria-selected="true"] { color: #111; background: #fff; box-shadow: 0 1px 5px #0000000d; }
  body .portalMobileCalendarRange {
    display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px auto;
    align-items: center; gap: 6px; margin: 0 0 12px;
  }
  body .portalMobileCalendarRange h2, body .portalMobileCalendarRange .heroTitle,
  body .portalMobileCalendarRange > strong {
    min-width: 0; margin: 0; font-size: 18px !important; line-height: 1.3 !important; text-align: center;
    letter-spacing: -.015em !important; overflow-wrap: anywhere;
  }
  body .portalMobileCalendarRange .btn, body .portalMobileCalendarRange > button {
    min-width: 44px; min-height: 44px !important; padding: 8px !important;
    border: 1px solid var(--portal-mobile-line); border-radius: 11px;
    background: #fff; color: #171717; font-size: 13px; line-height: 1.2; cursor: pointer;
  }
  body .portalMobileCalendarRange .calendarTodayBtn { grid-column: auto; width: auto; }
  body .portalMobileFilters { margin: 12px 0 16px; border: 1px solid var(--portal-mobile-line); border-radius: 13px; background: #fff; overflow: hidden; }
  body .portalMobileFilters > summary { min-height: 46px; padding: 12px 14px; cursor: pointer; font-size: 13px; font-weight: 600; }
  body .portalMobileFilters[open] > summary { border-bottom: 1px solid var(--portal-mobile-line); }
  body .portalMobileFilters .calendarFilters { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 12px; }
  body .portalMobileFilters .calendarFilter { border-radius: 10px; padding: 5px 9px; gap: 10px; }
  body .portalMobileFilters .calendarFilter label { font-size: 10px; }
  body .portalMobileFilters .calendarFilter select { width: 100%; max-width: none; font-size: 16px !important; }
  body .portalMobileAgenda { min-width: 0; margin: 16px 0 0; }
  body .portalMobileDays { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; margin: 0 0 20px; }
  body .portalMobileDay {
    appearance: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 0; min-height: 76px; gap: 4px; padding: 8px 2px;
    border: 1px solid var(--portal-mobile-line); border-radius: 13px; background: #fff; color: #595951; cursor: pointer;
    font: inherit; font-size: 11px; line-height: 1.2;
  }
  body .portalMobileDay .weekday { font-size: 10px; font-weight: 500; }
  body .portalMobileDay b, body .portalMobileDay strong, body .portalMobileDay .number { font-size: 19px; line-height: 1.1; font-weight: 700; }
  body .portalMobileDay small, body .portalMobileDay .count { font-size: 9px; font-weight: 600; min-height: 11px; }
  body .portalMobileDay.today { border-color: #bca35b; }
  body .portalMobileDay[aria-pressed="true"] { color: #111; background: #ffbd00; border-color: #ffbd00; box-shadow: 0 3px 8px #a57b0015; }
  body .portalMobileMonthGrid {
    display: grid; grid-template-columns: repeat(7, minmax(44px, 1fr)); gap: 3px;
    width: 100%; min-width: 0; margin: 0 0 20px; overflow-x: auto;
    overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; padding-bottom: 3px;
  }
  body .portalMobileMonthGrid > .portalMobileDay { min-width: 44px; min-height: 62px; gap: 4px; padding: 8px 2px; border-radius: 10px; }
  body .portalMobileMonthGrid > .portalMobileDay b,
  body .portalMobileMonthGrid > .portalMobileDay strong,
  body .portalMobileMonthGrid > .portalMobileDay .number { font-size: 17px; }
  body .portalMobileMonthGrid > .portalMobileMonthDow,
  body .portalMobileMonthGrid > .weekday,
  body .portalMobileMonthGrid > span { padding: 5px 0 7px; font-size: 10px; font-weight: 600; text-align: center; color: var(--portal-mobile-muted); }
  body .portalMobileMonthGrid .portalMobileDay.out { background: #efefe9; color: #76766d; border-color: transparent; }
  body .portalMobileMonthGrid .portalMobileDay.out[aria-pressed="true"] { background: #ffbd00; color: #111; border-color: #ffbd00; }
  body .portalMobileAgendaHead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; }
  body .portalMobileAgendaHead h2, body .portalMobileAgendaHead h3 { margin: 0; font-size: 19px; line-height: 1.3; }
  body .portalMobileAgendaHead small, body .portalMobileAgendaHead > span { color: var(--portal-mobile-muted); font-size: 12px; }
  body .portalMobileAgendaList { display: flex; flex-direction: column; gap: 10px; }
  body .portalMobileEvent {
    appearance: none; display: grid; grid-template-columns: 48px minmax(0, 1fr); align-items: start;
    gap: 10px; width: 100%; min-width: 0; min-height: 94px; padding: 14px 12px;
    border: 1px solid var(--portal-mobile-line); border-left: 3px solid #d2ae45; border-radius: 13px;
    background: #fff; color: #171717; text-align: left; cursor: pointer; font: inherit;
  }
  body .portalMobileEvent.meeting { border-left-color: #6a91c6; }
  body .portalMobileEvent.inProgress { border-left-color: #4072c6; background: #f6f9ff; }
  body .portalMobileEvent.done { border-left-color: #8bad91; }
  body .portalMobileEventTime { display: block; padding-top: 2px; font-size: 12px; font-weight: 600; color: #6e6e65; font-variant-numeric: tabular-nums; }
  body .portalMobileEventMain { min-width: 0; }
  body .portalMobileEventTitle, body .portalMobileEvent b, body .portalMobileEvent strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.45; overflow-wrap: anywhere; }
  body .portalMobileEventMeta, body .portalMobileEvent small { display: block; margin-top: 6px; font-size: 12px; line-height: 1.5; color: var(--portal-mobile-muted); overflow-wrap: anywhere; }
  body .portalMobileEventState { display: inline-flex; grid-column: 2; justify-self: start; margin-top: 0; padding: 3px 7px; border-radius: 6px; background: #f0f0eb; font-size: 10px; font-weight: 600; }
  body .portalMobileDone { margin: 16px 0 0; border: 1px solid var(--portal-mobile-line); border-radius: 13px; background: #fff; overflow: hidden; }
  body .portalMobileDone > summary {
    display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 12px 14px;
    color: #5f665c; font-size: 13px; font-weight: 600; line-height: 1.5; cursor: pointer; list-style: none;
  }
  body .portalMobileDone > summary::-webkit-details-marker { display: none; }
  body .portalMobileDone > summary::after { content: '⌄'; margin-left: auto; font-size: 18px; line-height: 1; }
  body .portalMobileDone[open] > summary::after { transform: rotate(180deg); }
  body .portalMobileDone > .portalMobileAgendaList { padding: 12px; border-top: 1px solid var(--portal-mobile-line); }
  body .portalMobileDone .portalMobileEvent { background: #fafbf8; }

  /* Chat has one mobile screen at a time: list, then conversation. */
  body #view-chat .chatHeadActions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body #view-chat .chatLayout { display: block; min-height: 0 !important; height: auto; }
  body #view-chat .chatThreads { padding: 0 !important; }
  body #view-chat .chatThreadsHead { padding: 15px; }
  body #view-chat .chatThreadsHead b { font-size: 14px; }
  body #view-chat .chatThreadsHead span { font-size: 11px; }
  body #view-chat .chatThreadList { max-height: none !important; }
  body #view-chat .chatThreadRow { min-height: 82px; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 11px; padding: 14px 12px; }
  body #view-chat .chatThreadMain b { font-size: 14px; line-height: 1.35; }
  body #view-chat .chatThreadMain span { margin-top: 5px; font-size: 12px; line-height: 1.4; }
  body #view-chat .chatThreadMeta small { font-size: 10px; }
  body #view-chat .chatThreadMeta strong { min-width: 22px; height: 22px; font-size: 10px; }
  body #view-chat:not(.portalMobileChatConversation) .chatConversationCard { display: none !important; }
  body #view-chat.portalMobileChatConversation > .pageHead,
  body #view-chat.portalMobileChatConversation .chatThreads { display: none !important; }
  body #view-chat.portalMobileChatConversation .chatLayout { height: max(180px, calc(var(--portal-mobile-viewport-height, 100dvh) - var(--portal-mobile-header-height) - var(--portal-mobile-bottom-space) - 40px)); }
  body #view-chat.portalMobileChatConversation .chatConversationCard { display: flex !important; height: 100%; padding: 0 !important; border-radius: 15px !important; }
  body #view-chat .chatConversation { display: flex !important; flex-direction: column; height: 100%; min-height: 0 !important; max-height: none !important; }
  body #view-chat .chatConversationHead { flex: 0 0 auto; flex-wrap: wrap; gap: 8px; padding: 10px; }
  body #view-chat .portalMobileChatBack { flex: 0 0 44px; width: 44px; height: 44px; min-height: 44px; border: 1px solid var(--portal-mobile-line); border-radius: 11px; background: #fff; color: #111; cursor: pointer; font-size: 21px; }
  body #view-chat .chatConversationIdentity { flex: 1; min-width: 0; }
  body #view-chat .chatConversationIdentity b { font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
  body #view-chat .chatConversationIdentity span { font-size: 11px; line-height: 1.4; }
  body #view-chat .chatConversationTools { flex: 0 0 100%; justify-content: flex-end; gap: 6px; }
  body #view-chat .chatRealtimeStatus { margin-right: auto; font-size: 10px; }
  body #view-chat .chatConversationTools .btn { min-height: 38px !important; padding: 7px 9px !important; font-size: 11px; }
  body #view-chat .chatMessages { flex: 1 1 auto; min-height: 0; padding: 13px !important; gap: 10px; scrollbar-gutter: auto; }
  body #view-chat .chatMessage { max-width: 90%; }
  body #view-chat .chatBubble { font-size: 14px; line-height: 1.55; padding: 10px 12px; }
  body #view-chat .chatMessageSender, body #view-chat .chatMessageTime { font-size: 10px; }
  body #view-chat .chatSearchPanel { flex: 0 0 auto; max-height: 35%; overflow-y: auto; padding: 10px; }
  body #view-chat .chatSearchPanel input { font-size: 16px; min-height: 44px; }
  body #view-chat .chatSearchModes { flex-wrap: wrap; }
  body #view-chat .chatComposer {
    position: static !important; bottom: auto !important; flex: 0 0 auto; z-index: auto !important;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 10px !important; background: #fff !important;
  }
  body #view-chat .chatComposer textarea { min-height: 46px !important; max-height: 110px; padding: 11px; font-size: 16px !important; line-height: 1.4; resize: none; }
  body #view-chat .chatComposer > .btn { min-height: 46px !important; }
  body #view-chat .chatComposerExtras { max-height: 30dvh; overflow: auto; }
  body #view-chat .chatComposerToolbar .btn { min-height: 40px !important; font-size: 12px; }
  body #view-chat .chatComposerToolbar > small { font-size: 11px; line-height: 1.4; }
  body #view-chat .chatFileCard b, body #view-chat .chatRecordResult b { font-size: 13px; }
  body #view-chat .chatFileCard small, body #view-chat .chatRecordResult small { font-size: 11px; }
  body #view-chat .chatEmpty { padding: 24px 16px; font-size: 13px; }

  /* Forms use one scrolling body, with header and actions always outside it. */
  body .modalBack, body .drawerBack {
    position: fixed; inset: var(--portal-mobile-viewport-offset-top, 0px) 0 auto !important;
    height: var(--portal-mobile-viewport-height, 100dvh) !important; padding: 0 !important;
    display: grid; place-items: stretch !important; overflow: hidden;
  }
  body .drawerBack { z-index: 140 !important; }
  body .modalBack { z-index: 150 !important; }
  body .modalBack .modal, body .modalBack .modal.socialComposerModal,
  body .drawerBack .drawer, body .drawerBack .drawer.wide {
    display: flex; flex-direction: column; width: 100% !important; max-width: none !important;
    height: 100% !important; min-height: 0 !important; max-height: 100% !important;
    margin: 0 !important; padding: 0 !important; border: 0; border-radius: 0 !important; overflow: hidden !important;
  }
  body .modalBack .modalHead, body .drawerBack .drawerHead {
    position: sticky !important; top: 0 !important; z-index: 3; flex: 0 0 auto;
    padding: calc(14px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 14px max(16px, env(safe-area-inset-left)) !important;
  }
  body .modalBack .modalHead { background: #fff; gap: 12px; }
  body .modalBack .modalHead > b { font-size: 17px; line-height: 1.4; }
  body .modalBack .modalHead .btn { flex: 0 0 44px; min-width: 44px; padding: 8px !important; }
  body .drawerBack .drawerHead { background: #111 !important; color: #fff; }
  body .drawerBack .drawerHead h2 { font-size: 27px; line-height: 1.15; }
  body .modalBack .modalBody, body .drawerBack .drawerBody {
    flex: 1 1 auto; min-height: 0; overflow-y: auto !important; overscroll-behavior: contain;
    padding: 18px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)) !important;
    scroll-padding: 18px; -webkit-overflow-scrolling: touch;
  }
  body .drawerBack .drawerBody { padding-bottom: calc(24px + env(safe-area-inset-bottom)) !important; }
  body .modalBack .modalFoot {
    position: sticky !important; bottom: 0 !important; z-index: 3; flex: 0 0 auto; gap: 8px;
    margin: 0; padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)) !important;
    background: #fff !important; border-top: 1px solid var(--portal-mobile-line); box-shadow: 0 -4px 16px #00000006;
  }
  body .modalBack .modalFoot .btn { flex: 1 1 120px; min-height: 46px !important; font-size: 13px !important; }
  body .modalBack .formGrid, body .modalBack .taskFormGrid, body .modalBack .taskRecurrenceFields { grid-template-columns: minmax(0, 1fr) !important; gap: 16px; }
  body .field { min-width: 0; gap: 7px; }
  body .field > label { font-size: 11px; line-height: 1.5; letter-spacing: .04em; color: #59594f; }
  body .field textarea { min-height: 120px; }
  body .field > small, body .field .muted { font-size: 12px; line-height: 1.5; }
  body .drawerBack .drawerTabs { position: sticky; top: -18px; z-index: 2; margin: -18px -16px 16px !important; padding: 10px 16px !important; background: #f7f7f4; }
  body .drawerBack .drawerTabs button { min-height: 42px; font-size: 12px; }
  body .mobileActionSheetBack { z-index: 150 !important; }
  body .mobileActionSheet { max-height: calc(var(--portal-mobile-viewport-height, 100dvh) - 24px); padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }
  body .mobileActionItem { min-height: 76px; padding: 12px; }
  body .mobileActionItem b { font-size: 14px; }
  body .mobileActionItem small { font-size: 12px; line-height: 1.5; }

  /* Composer styles may be lazy-loaded later: these selectors stay more specific. */
  body .modalBack .socialComposerForm input,
  body .modalBack .socialComposerForm select,
  body .modalBack .socialComposerForm textarea { min-height: 46px; font-size: 16px !important; }
  body .modalBack .socialComposerForm .field > label { font-size: 13px; }
  body .modalBack .socialComposerForm .socialTargetChooser { grid-template-columns: minmax(0, 1fr); }
  body .modalBack .socialComposerForm .socialTargetOption { min-height: 64px; gap: 10px; padding: 12px; }
  body .modalBack .socialComposerForm .socialTargetOption b { font-size: 13px !important; }
  body .modalBack .socialComposerForm .socialTargetOption small { font-size: 11px !important; }
  body .modalBack .socialComposerForm .socialComposerCanvas select { width: 100% !important; min-width: 0; }
  body .modalBack .socialComposerCardActions { flex-wrap: wrap; gap: 6px; }
  body .modalBack .socialComposerCardActions button { min-height: 42px; min-width: 42px; }
  body .modalBack .socialComposerDrag { width: 42px; height: 42px; }
  body #view-content .socialFilters { grid-template-columns: minmax(0, 1fr) !important; gap: 8px; }
  body #view-content .socialFilters select { min-height: 46px; font-size: 16px; }
  body #view-content .socialPostCardBody > b { font-size: 13px !important; line-height: 1.4; }
  body #view-content .socialPostCardBody > small { font-size: 11px !important; line-height: 1.5; }

  /* Optional viewport hook set by JS when the software keyboard is visible. */
  body.portalMobileKeyboardOpen { --portal-mobile-bottom-space: 0px; }
  body.portalMobileKeyboardOpen #mobileBottomNav,
  body.portalMobileKeyboardOpen #mobileQuickAdd { display: none !important; }
}

@media (max-width: 380px) {
  body .content { padding-left: max(12px, env(safe-area-inset-left)) !important; padding-right: max(12px, env(safe-area-inset-right)) !important; }
  body .portal-task-tabs button { font-size: 11px; padding-left: 9px; padding-right: 9px; }
  body .portalMobileDays { gap: 4px; }
  body .portalMobileDay { border-radius: 11px; }
  body #view-work .workFilterBar { grid-template-columns: minmax(0, 1fr) !important; }
  body #view-work .workFilterBar input { grid-column: auto; }
}
