/* v0.10 mobile overrides. Load after styles.css and portal.css.
   Keep wide tables locally scrollable; never conceal page overflow globally. */
@media (max-width: 767px) {
  :root { --mobile-gutter: 16px; --mobile-touch: 44px; }
  html { scroll-padding-top: 76px; scroll-padding-bottom: 110px; }
  .content { padding-inline: var(--mobile-gutter); }
  .content, .content > *, .panel, .holding, .stat,
  .admin-layout > *, .trade-grid > *, .split > *, .form-grid > *,
  .support-layout > *, .portal-product-grid > *, .portal-market-links > * {
    min-width: 0;
  }
  .trade-grid, .split, .holding-grid, .help-grid, .admin-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .product { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-scroll { max-width: 100%; min-width: 0; overscroll-behavior-x: contain; }
  .table { min-width: 100%; }
  .tabs, .admin-side { max-width: 100%; overscroll-behavior-x: contain; scrollbar-width: thin; }
  .tabs > *, .admin-side > button { flex-shrink: 0; }
  .tabs { gap: 22px; padding-top: 4px; }
  .tabs.small { gap: 16px; }

  button, .tabs a, .drawer nav a, .mobile-nav a,
  .portal-link-button, a.badge, .market-link {
    min-height: var(--mobile-touch);
  }
  button { max-width: 100%; }
  .menu-btn, .modal-close, .icon-btn, .star {
    width: var(--mobile-touch); min-width: var(--mobile-touch);
    height: var(--mobile-touch); padding: 6px; flex-shrink: 0;
  }
  .topbar-right .primary, .topbar-right .outline { min-height: var(--mobile-touch); }
  .checkbox-label { min-height: var(--mobile-touch); }
  input[type="checkbox"] { width: 22px; min-width: 22px; min-height: 22px; height: 22px; }
  input:not([type="checkbox"]), select, textarea, .portal-editor, .chat-compose textarea {
    font-size: 16px; max-width: 100%; min-width: 0;
  }
  input:not([type="checkbox"]), select { min-height: 48px; }
  label { min-width: 0; }
  .form-grid, .portal-form-columns { gap: 16px; }
  .payment-filter { max-width: 100%; }
  .search { min-width: 0; }

  h1, h2, h3, .note, .form-error, .field-note, .toast,
  .product-name strong, .holding strong, .staff-card small,
  .chat-message small, .quote-meta, .bot-card, .portal-sample {
    overflow-wrap: anywhere;
  }
  .between > *, .page-head > *, .detail-row > *, .modal-summary > * { min-width: 0; }
  .panel > .between, .panel-head, .detail-row, .modal-summary, .chart-panel > .between {
    flex-wrap: wrap;
  }
  .detail-row { gap: 8px 12px; }
  .detail-row > strong, .detail-row > span:last-child { overflow-wrap: anywhere; }
  .big-balance { font-size: clamp(26px, 8vw, 36px); overflow-wrap: anywhere; }
  .asset-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .asset-actions > :first-child { grid-column: 1 / -1; }
  .asset-actions button { white-space: normal; }
  .company-metrics { grid-template-columns: minmax(0, 1fr); }
  .loading { padding: 36px 12px; }
  .empty { padding: 36px 12px; }

  .chart-tools { flex-wrap: wrap; gap: 6px; }
  .chart-tools button { min-width: 44px; padding: 8px; }
  .chart-tools .badge { white-space: normal; margin-left: 0; }
  .chart { height: clamp(210px, 65vw, 280px); max-width: 100%; }
  .chart-caption { flex-wrap: wrap; gap: 8px; overflow-wrap: anywhere; }
  .chart-caption > * { min-width: 0; max-width: 100%; }
  .quote-source > small { flex-basis: 100%; overflow-wrap: anywhere; }
  .quote-source > button { min-height: 44px; }

  .modal-backdrop {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  .modal {
    max-width: 100%;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
  }
  .modal-header { gap: 8px; padding: 12px 14px; }
  .modal-header h2 { min-width: 0; font-size: 19px; line-height: 1.4; }
  .modal-content { padding: 16px; }
  .modal-footer { padding: 14px 16px; }
  .modal-summary { gap: 12px; }
  .timeline-row { grid-template-columns: 16px minmax(0, 1fr); min-height: 74px; }
  .timeline-row strong { grid-column: 2; margin-top: -8px; font-size: 13px; overflow-wrap: anywhere; }
  .drawer {
    max-width: min(360px, calc(100vw - 20px)); width: 100%;
    padding: max(20px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
    max-height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  }
  .drawer > .between { gap: 8px; }
  .drawer h2 { font-size: 20px; }
  .drawer nav { gap: 6px; margin-top: 20px; }
  .drawer nav a { display: flex; align-items: center; overflow-wrap: anywhere; }
  .chat-messages { height: clamp(120px, 32dvh, 230px); }
  .chat-compose .between { flex-wrap: wrap; gap: 8px; }
  .chat-compose .between > button { flex: 1 0 100%; }
  .chat-message { max-width: 92%; min-width: 0; }
  .support-thread { flex: 0 0 190px; min-width: 0; }
  #support-threads { max-width: 100%; }
  .mobile-nav { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .mobile-nav a { min-width: 0; flex: 1; padding: 2px; line-height: 1.25; text-align: center; }
  .mobile-nav .nav-icon { line-height: 1.2; }
  .support-launcher { max-width: calc(100vw - 32px); bottom: calc(86px + env(safe-area-inset-bottom)); }
  .footer { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  .footer .row { flex-wrap: wrap; }
  #notifications { bottom: calc(144px + env(safe-area-inset-bottom)); }
  .toast { max-height: 40dvh; overflow-y: auto; padding: 12px 16px; }

  /* Reduce fixed-layer crowding while a form or the native keyboard is active. */
  body:has(input:focus, textarea:focus, select:focus) .mobile-nav,
  body:has(input:focus, textarea:focus, select:focus) .support-launcher { display: none; }
  body:has(input:focus, textarea:focus, select:focus) #notifications {
    bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 390px) {
  .topbar { padding-inline: 12px; gap: 8px; }
  html[lang="en"] .topbar { gap: 8px; }
  .brand { font-size: 20px; gap: 6px; }
  .brand-mark { flex-shrink: 0; }
  .topbar .brand .badge { display: inline-flex !important; font-size: 8px; padding: 2px 3px; margin-left: 0; }
  .topbar-right { min-width: 0; gap: 0; }
  .topbar-right > button { padding: 8px; font-size: 12px; }
  .panel, .holding { padding: 16px; }
  .page-head .row { flex-wrap: wrap; }
  .portal-home-head h1 { font-size: 26px; }
  .portal-market-quote .between { flex-wrap: wrap; gap: 4px; }
  .portal-market-quote .portal-quote-price { font-size: 21px; }
  .portal-quick { gap: 8px; }
  .portal-quick > * { padding-inline: 8px; }
}

@media (max-width: 374px) {
  :root { --mobile-gutter: 12px; }
  .portal-market-links { grid-template-columns: minmax(0, 1fr); }
  .product { padding: 16px; gap: 14px; }
  .portal-product-card { padding: 16px; }
  .product-number { overflow-wrap: anywhere; }
  .portal-announcement { flex-wrap: wrap; }
  .portal-announcement > a:first-of-type { flex-basis: 65%; }
}

/* Keyboard-sized and landscape viewports: make the footer reachable by scrolling. */
@media (max-width: 767px) and (max-height: 520px) {
  .modal-form { display: block; overflow-y: auto; overscroll-behavior: contain; }
  .modal-content { overflow: visible; }
  .modal-footer { position: static; }
  .modal-header { min-height: 56px; padding-block: 6px; }
  .chat-messages { height: 130px; }
}
