/* IOOK mobile-safe-fix v2
   Responsive-only overrides. Desktop remains unchanged.
*/

@media (max-width: 800px) {
  html, body {
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    overflow-x: hidden;
  }

  html.mobileSheetOpen,
  html.mobileSheetOpen body {
    overflow: hidden;
  }

  body, .shell { min-height: 100dvh; }

  main {
    width: 100%;
    max-width: 100%;
    padding: 22px 16px calc(88px + env(safe-area-inset-bottom));
    overflow-x: hidden;
  }

  .topbar {
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
  }

  .topbar h1 {
    max-width: calc(100vw - 32px);
    font-size: clamp(32px, 8.6vw, 38px);
    line-height: 1.02;
  }

  /* Native-style bottom navigation. */
  .sidebar {
    position: fixed;
    z-index: 100;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: auto;
    min-height: 0;
    display: block;
    padding: 6px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    border-right: 0;
    border-top: 1px solid var(--line);
    background: rgba(9, 10, 13, .97);
    box-shadow: 0 -14px 36px rgba(0,0,0,.28);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
  }

  .sidebar .brand,
  .sidebar .sidebarBottom,
  .currencyPickerTop {
    display: none !important;
  }

  .sidebar nav {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 2px !important;
    overflow: visible !important;
  }

  .sidebar .nav {
    display: none !important;
  }

  .sidebar .nav.mobile-primary,
  .mobileMoreButton {
    min-width: 0;
    min-height: 56px;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 13px;
    padding: 6px 2px;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 10px;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
  }

  .sidebar .nav[data-view="inbox"] { order: 1; }
  .sidebar .nav[data-view="accounts"] { order: 2; }
  .sidebar .nav[data-view="flights"] { order: 3; }
  .sidebar .nav[data-view="memory"] { order: 4; }
  .mobileMoreButton { order: 5; }

  .sidebar .nav span,
  .mobileMoreButton > span {
    font-size: 19px;
    line-height: 1;
  }

  .sidebar .nav b { display: none !important; }
  .mobileMoreButton small { font-size: 10px; color: inherit; }

  .sidebar .nav.active,
  .mobileMoreButton.active {
    background: rgba(255,255,255,.055);
    color: var(--text);
  }

  /* More bottom sheet keeps secondary tools without crowding the tab bar. */
  .mobileMoreBackdrop {
    position: fixed;
    inset: 0;
    z-index: 190;
    background: rgba(0,0,0,.62);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }

  .mobileMoreBackdrop.show {
    opacity: 1;
    pointer-events: auto;
  }

  .mobileMoreSheet {
    position: fixed;
    z-index: 200;
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    max-height: min(72dvh, 650px);
    overflow: auto;
    padding: 10px 14px 16px;
    border: 1px solid #2b303a;
    border-radius: 26px;
    background: linear-gradient(180deg, #171a20, #0f1115);
    box-shadow: 0 32px 90px rgba(0,0,0,.6);
    transform: translateY(calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
    transition: transform .24s ease, opacity .2s ease;
  }

  .mobileMoreSheet.show {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .mobileSheetHandle {
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: #3a3f49;
    margin: 2px auto 12px;
  }

  .mobileSheetHead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
  }

  .mobileSheetHead div span {
    display: block;
    color: var(--accent);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .18em;
  }

  .mobileSheetHead div strong {
    display: block;
    margin-top: 3px;
    font-size: 22px;
  }

  .mobileSheetClose {
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #111318;
    color: var(--soft);
    font-size: 25px;
  }

  .mobileSheetGrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }

  .mobileSheetGrid button {
    min-height: 78px;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: #111318;
    color: var(--text);
    padding: 13px;
    text-align: left;
  }

  .mobileSheetGrid button > span {
    display: block;
    color: var(--accent);
    font-size: 18px;
    margin-bottom: 8px;
  }

  .mobileSheetGrid button strong {
    display: block;
    font-size: 12px;
  }

  .mobileSheetGrid button small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 9px;
  }

  .mobileSheetSetting {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #0d0f13;
  }

  .mobileSheetSetting label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
  }

  .mobileSheetSetting select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel2);
    color: var(--text);
    padding: 0 12px;
  }

  .mobileSheetLogout {
    width: 100%;
    min-height: 46px;
    margin-top: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: transparent;
    color: var(--muted);
  }

  /* Home / capture screen */
  .pillarGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
  }

  .pillarCard {
    min-width: 0;
    min-height: 110px;
    padding: 14px;
  }

  .pillarCard strong { font-size: 14px; }
  .pillarCard span { font-size: 10px; line-height: 1.4; }

  .captureCard { border-radius: 18px; }

  textarea {
    width: 100%;
    min-width: 0;
    height: 165px;
    min-height: 155px;
    padding: 18px;
    font-size: 16px;
  }

  .captureFooter { padding: 12px; }

  .captureActions {
    width: 100%;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  }

  .captureActions .primary { grid-column: 1 / -1; }

  .speechLanguage,
  .speechBtn,
  .captureActions .primary { min-height: 48px; }

  .upload { min-height: 44px; flex-wrap: wrap; }

  .examples {
    margin: 12px 0 18px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .examples::-webkit-scrollbar { display: none; }
  .examples button { flex: 0 0 auto; }

  .emptyState { padding: 30px 14px; }

  .porusExactArtwork {
    width: min(220px, 62vw) !important;
    margin: 22px auto 6px !important;
  }

  /* Prevent dashboard rows from forcing the viewport wider than the phone. */
  .view,
  .captureCard,
  .accountsHero,
  .accountPanel,
  .flightHero,
  .memoryHero,
  .porusHero,
  .futurePanel,
  .bankConnect {
    max-width: 100%;
    min-width: 0;
  }

  .accountGrid,
  .porusGrid,
  .memoryGrid,
  .flightComposer { min-width: 0; }

  .accountQuestionRow,
  .bankConnectRow { grid-template-columns: 1fr !important; }

  .accountQuestionRow input,
  .bankConnectRow input,
  .memoryToolbar input {
    min-width: 0;
    width: 100%;
  }

  .accountRecordsHead,
  .sectionHead {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .noTasks { padding: 36px 16px; }

  /* Login */
  .authGate {
    min-height: 100dvh;
    place-items: start center;
    padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  }

  .authCard {
    width: 100%;
    max-width: 460px;
    margin-top: 12px;
    padding: 22px;
    border-radius: 22px;
  }

  .authBrand { margin-bottom: 26px; }
  .authCard h1 { font-size: 34px; }
  .authForm input, .authPrimary { min-height: 52px; }
  .authLinks { gap: 2px; }

  .authTextButton {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .authSafety { margin-top: 18px; }

  /* Touch/accessibility */
  button, select, input, textarea { touch-action: manipulation; }

  button:focus-visible,
  select:focus-visible,
  input:focus-visible,
  textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: calc(82px + env(safe-area-inset-bottom));
    text-align: center;
  }
}

@media (max-width: 390px) {
  main { padding-left: 13px; padding-right: 13px; }
  .topbar h1 { font-size: 30px; }
  .pillarCard { padding: 12px; }
  .mobileSheetGrid { grid-template-columns: 1fr; }
}
