/* Mobile UX overhaul — designed as a real mobile app, not a shrunk desktop. */
@media (max-width: 760px) {
  :root {
    --mobile-nav-h: 70px;
    --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
    --mobile-page-pad: 14px;
  }

  html { overscroll-behavior-y: none; }
  body { overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
  body.mobile-ux-open { overflow: hidden; }

  .main {
    max-width: none;
    padding: 14px var(--mobile-page-pad) calc(var(--mobile-nav-h) + var(--mobile-safe-bottom) + 28px);
  }

  /* One-thumb navigation: 4 core destinations + More. */
  .bottom-nav {
    min-height: calc(var(--mobile-nav-h) + var(--mobile-safe-bottom));
    align-items: stretch;
    padding: 4px 4px var(--mobile-safe-bottom);
    box-shadow: 0 -10px 30px rgba(20,35,70,.08);
    backdrop-filter: blur(18px);
    background: color-mix(in srgb, var(--card) 94%, transparent);
  }
  .bottom-nav button {
    min-width: 0;
    min-height: 58px;
    border-radius: 14px;
    font-size: 10.5px;
    font-weight: 500;
    touch-action: manipulation;
  }
  .bottom-nav button:nth-child(n+5) { display: none; }
  .bottom-nav .mobile-more-button { display: flex !important; }
  .bottom-nav .ico { font-size: 20px; line-height: 1; }

  /* Floating capture stays clear of navigation and review inbox button. */
  .fab {
    width: 56px;
    height: 56px;
    right: 14px;
    bottom: calc(var(--mobile-nav-h) + var(--mobile-safe-bottom) + 12px);
    box-shadow: 0 10px 24px rgba(23,134,255,.34);
  }
  .uc-fab { display: none !important; }

  /* Bigger, predictable touch targets everywhere. */
  button, .btn, .nav-btn, .tag-cloud button, .chip, input, select, textarea {
    touch-action: manipulation;
  }
  button, .btn { min-height: 44px; }
  input, select, textarea {
    min-height: 46px;
    font-size: 16px !important; /* prevents iOS zoom-on-focus */
  }
  textarea { line-height: 1.45; }

  /* Cards and rows become easier to scan/tap. */
  .card { padding: 16px; margin-bottom: 12px; border-radius: 16px; }
  .task { gap: 10px; padding: 11px 0; align-items: center; }
  .task .t-title { min-width: 0; overflow-wrap: anywhere; }
  .row { gap: 8px; }

  /* Pending-captures banner becomes actionable instead of a dead warning. */
  .mobile-review-alert {
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 16px;
  }
  .mobile-review-alert .mobile-review-copy { flex: 1; min-width: 0; }
  .mobile-review-alert .mobile-review-copy b { display: block; }
  .mobile-review-alert .mobile-review-actions { display: flex; gap: 6px; flex-shrink: 0; }
  .mobile-review-alert .mobile-review-open,
  .mobile-review-alert .mobile-review-hide {
    border: 0;
    border-radius: 12px;
    min-height: 42px;
    padding: 0 11px;
    font: 600 12px/1 Sora, sans-serif;
  }
  .mobile-review-alert .mobile-review-open { background: #7a5310; color: #fff; }
  .mobile-review-alert .mobile-review-hide { width: 42px; padding: 0; background: rgba(122,83,16,.1); color: #7a5310; font-size: 20px; }

  /* Every mobile sheet/dialog is a full-screen task, avoiding tiny floating windows. */
  .sheet-bg { align-items: stretch; }
  .sheet {
    max-width: none;
    width: 100%;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    padding: calc(18px + env(safe-area-inset-top)) 16px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }
  .sheet .row { position: sticky; bottom: 0; padding-top: 10px; background: var(--card); }
  .sheet .row .btn { flex: 1; }

  .uc-panel {
    inset: 0 !important;
    width: 100% !important;
    height: 100dvh !important;
    max-height: none !important;
    border-radius: 0 !important;
    padding: calc(16px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom)) !important;
    transform: translateX(102%) !important;
  }
  .uc-sheet[aria-hidden="false"] .uc-panel { transform: translateX(0) !important; }
  .uc-header { position: sticky; top: calc(-16px - env(safe-area-inset-top)); z-index: 4; padding: 12px 0; background: rgba(249,251,255,.97); backdrop-filter: blur(16px); }
  .uc-intro { margin-top: 8px; }
  .uc-card { border-radius: 16px; padding: 14px; }
  .uc-actions { position: sticky; bottom: -1px; padding: 10px 0 max(2px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(255,255,255,0), #fff 24%); }
  .uc-actions button { min-height: 48px; }

  /* Chat behaves like a phone messenger and follows the visual viewport when keyboard opens. */
  .chat-wrap {
    height: calc(var(--mobile-vh, 100dvh) - var(--mobile-nav-h) - var(--mobile-safe-bottom) - 28px);
    min-height: 360px;
  }
  .chat-scroll { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .chat-input {
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding: 8px 0 max(4px, env(safe-area-inset-bottom));
    background: var(--surface);
    align-items: flex-end;
  }
  .chat-input textarea { min-height: 48px; max-height: 112px; }
  .chat-input .mic, .chat-input .btn { min-width: 48px; min-height: 48px; }
  .msg { max-width: 90%; }

  /* More menu: a single full-height sheet instead of eight tiny nav items. */
  .mobile-more-sheet {
    position: fixed;
    inset: 0;
    z-index: 140;
    visibility: hidden;
    pointer-events: none;
  }
  .mobile-more-sheet[aria-hidden="false"] { visibility: visible; pointer-events: auto; }
  .mobile-more-backdrop { position: absolute; inset: 0; border: 0; background: rgba(11,16,32,.42); }
  .mobile-more-panel {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
    border-radius: 24px 24px 0 0;
    background: var(--card);
    box-shadow: 0 -24px 70px rgba(20,35,70,.2);
    transform: translateY(102%);
    transition: transform .22s ease;
  }
  .mobile-more-sheet[aria-hidden="false"] .mobile-more-panel { transform: translateY(0); }
  .mobile-more-grabber { width: 42px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; }
  .mobile-more-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
  .mobile-more-head h2 { margin: 0; font-size: 18px; }
  .mobile-more-close { width: 44px; height: 44px; border: 0; border-radius: 14px; background: var(--surface); font-size: 22px; }
  .mobile-more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .mobile-more-grid button {
    min-height: 72px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    color: var(--ink);
    text-align: left;
    padding: 12px;
    display: grid;
    grid-template-columns: 28px 1fr;
    align-items: center;
    gap: 8px;
    font: 600 14px/1.25 Sora, sans-serif;
  }
  .mobile-more-grid button span { font-size: 21px; }
  .mobile-more-grid button.active { border-color: #b9d7ff; background: var(--blue-soft); color: var(--blue); }

  /* Avoid nested-scroll traps in ordinary pages. */
  #page > *:not(.chat-wrap):not(.brain-wrap-v2) { max-width: 100%; }
  .card, .alert, .sheet, .uc-panel { overflow-wrap: anywhere; }

  /* Respect reduced motion and low-power usage. */
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
  }
}
