/* ========================================================================
 *  KX-PAY V2 dashboard  ·  09-responsive.css
 * -----------------------------------------------------------------------
 *  Mobile layout (<=768px). LAST ON PURPOSE — these are overrides and
 *  must win the cascade.
 *
 *  Lifted verbatim from V1 dashboard.html lines 1394-1542.
 *  Load order matters — see the numeric prefix.
 * =======================================================================
 */

  /* ========================================================================
   *  MOBILE RESPONSIVE  (added 21-Jun-2026)
   *  Pragmatic minimum-viable layout for phones (≤768px). Goals:
   *    1. The top nav scrolls horizontally so all tabs stay reachable.
   *    2. (was: the header stacks. There is no header now -- the nav, the
   *       logo and the account block are all in the sidebar.)
   *    3. Tables already wrap in .table-wrap with overflow-x:auto, so they
   *       just need to be reminded that they CAN scroll.
   *    4. Modals fit the viewport with a small margin instead of overflowing.
   *    5. Padding is reduced so screens aren't wasted on whitespace.
   *  This is purely additive — no desktop layout changes.
   * ======================================================================== */
  @media (max-width: 768px) {
    /* There is no header any more, and no top nav. The logo, the nav and the
       account block all live in the sidebar, which becomes a slide-over
       drawer at this width — see 03-sidebar.css. The rules that used to be
       here stacked the top bar into three rows and made the tab strip scroll
       sideways; they are deleted rather than overridden, because bare
       `header` and `nav a` selectors would go looking for elements that are
       either gone or now mean something else. */
    .logo { font-size: 22px !important; }

    /* Main content padding — generous on desktop, tight on phone. */
    main { padding: 12px 8px !important; }

    /* Modals: fit the screen with a small margin. */
    .modal {
      width: auto !important;
      max-width: 95vw !important;
      margin: 16px auto !important;
      max-height: 90vh;
    }
    .modal.wide, .modal.xwide { width: auto !important; max-width: 95vw !important; }
    .modal-body { max-height: 70vh; overflow-y: auto; }
    .modal-actions {
      flex-wrap: wrap;
      gap: 6px;
    }
    .modal-actions button { flex: 1; min-width: 100px; }

    /* Tables: ensure they scroll horizontally + show a subtle hint at edges. */
    .table-wrap {
      overflow-x: auto !important;
      -webkit-overflow-scrolling: touch;
    }
    .table-wrap table { font-size: 12px !important; }
    .table-wrap th, .table-wrap td {
      padding: 6px 8px !important;
      white-space: nowrap;
    }

    /* ---- tables that were never given a .table-wrap ------------------
       Four on Settings (bank pricing, wallet switches, product codes) and
       the source-bank table on Automation. Every other table in the app is
       wrapped in .table-wrap, which scrolls; these five are not, so at phone
       width they pushed the WHOLE PAGE sideways -- 378px of it on Settings,
       which drags the heading and every card along with it.

       The scroll goes on the CONTAINER, not on the table.

       Putting `display:block; overflow-x:auto` on the table itself also
       stops the page overflowing, and was the first thing I tried -- but the
       computed overflow-x came back `hidden`, not `auto`. It still scrolled
       when driven from script, which is the trap: scrollWidth exceeding
       clientWidth proves the content is THERE, not that a finger can reach
       it, and an overflow:hidden box does not respond to a swipe. The
       container is a plain block with no table semantics to argue about, and
       it computes to `auto` as asked.

       Done in CSS rather than by adding a wrapper <div> in the HTML, because
       these tables are re-rendered from JavaScript and a static wrapper is
       only as durable as the next innerHTML that replaces it. */
    .settings-card,
    .ac-card .span-3 {
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }

    /* ---- the Reports tab strip ---------------------------------------
       Six buttons, flex-wrap:nowrap, no overflow rule -- so it ran 247px
       past the edge of the screen. It scrolls sideways now, the same way the
       top nav used to before it became the sidebar. */
    .rp-tabs {
      overflow-x: auto !important;
      -webkit-overflow-scrolling: touch;
      scrollbar-width: thin;
      padding-bottom: 4px;
    }
    .rp-tabs > * { flex-shrink: 0; }

    /* ---- touch targets -----------------------------------------------
       106 controls measured under 32px tall, most of them 26-28px, and 82 of
       those on Settings alone. That is fine with a mouse and fiddly with a
       thumb; Apple asks for 44px and Android for 48dp. 36px is the
       compromise that does not make every dense table twice as tall.

       Scoped to main so the sidebar keeps its own sizing, and checkboxes and
       radios are excluded -- stretching a 16px box to 36px just puts a large
       invisible target around a small visible control. */
    main button, main input, main select, main textarea { min-height: 36px; }
    main input[type="checkbox"],
    main input[type="radio"] { min-height: 0; }

    /* ---- fixed-layout tables whose columns are declared in pixels -----
       `table-layout: fixed` hands each column exactly the width it declares
       and gives whatever is left to the ones that declare nothing. On the
       Automation activity log that is 130 + 160 + 200 = 490px of declared
       columns inside a 317px phone screen, so Details -- the only column
       with no declared width -- got LITERALLY ZERO. Its cell also carries
       `overflow-wrap: anywhere`, so instead of overflowing it wrapped after
       every single character: 111 characters became 107 lines and one row
       stood 1,926px tall. That is the column of single letters in the
       screenshot.

       The cure is to stop pretending the table fits. Give it a real width,
       wider than the screen, and let the container scroll -- which is what
       every other table in the app already does. Details then gets 230px and
       wraps like ordinary text.

       !important throughout because these widths are inline attributes on
       the elements, and an inline style beats a stylesheet without it. */
    #ac-activity-table {
      width: 650px !important;
      min-width: 650px !important;
    }
    /* 05-tables.css sets "td { white-space: nowrap }" for every table in the
       app. With table-layout:fixed that is a bad pair: a cell too narrow for
       its text cannot wrap, and nothing clips it either, so it paints straight
       over the column to its right -- which is why the User column had
       "(super_admin)" sitting underneath "Automation settings".
       Let these cells wrap. break-word is the backstop for a username with no
       space in it to break at. */
    #ac-activity-table th,
    #ac-activity-table td {
      white-space: normal !important;
      overflow-wrap: break-word;
      word-break: break-word;
    }
    #ac-activity-table th:nth-child(1),
    #ac-activity-table td:nth-child(1) { width: 110px !important; }
    #ac-activity-table th:nth-child(2),
    #ac-activity-table td:nth-child(2) { width: 140px !important; }
    #ac-activity-table th:nth-child(3),
    #ac-activity-table td:nth-child(3) { width: 170px !important; }
    #ac-activity-table th:nth-child(4),
    #ac-activity-table td:nth-child(4) { width: 230px !important; }

    /* The Activity tab has the same bug in a six-column table: 745px of
       declared widths, Details declaring none. It lives in a .table-wrap,
       whose cells are already nowrap above, so the honest fix there is to
       drop the fixed layout entirely and let the content size the columns --
       exactly how the Transactions table behaves. */
    #tab-activity .table-wrap > table { table-layout: auto !important; }
    #tab-activity .table-wrap > table th,
    #tab-activity .table-wrap > table td { width: auto !important; }

    /* Two more of the same on Settings, found by looking for the pattern
       rather than waiting for them to be reported:
         · the PDGFID check-name card declares 110px + 250px of a 317px
           screen, so "Active SKU" -- the <select> you actually use -- came
           out 0px wide.
         · the deposit-account card declares 110px + 90px and leaves five SKU
           columns to share what is left: 26px each.
       Same cure. Real widths, and the card scrolls. */
    #pdgfid-cn-card table { width: 560px !important; }
    #pdgfid-cn-card table th:nth-child(2),
    #pdgfid-cn-card table td:nth-child(2) { width: 200px !important; }

    #dapc-card table { width: 800px !important; }
    #dapc-card table th:nth-child(n+2):nth-child(-n+6),
    #dapc-card table td:nth-child(n+2):nth-child(-n+6) { width: 120px !important; }

    /* ---- Transactions: collapse the filter bar ------------------------
       Brand, search, range, bank, transfer status and ticket status, plus
       three buttons, filled most of a phone screen before a single
       transaction appeared. Brand stays -- it is the one you change
       constantly -- and the rest hide behind a Filters button next to it.

       THE BADGE MATTERS MORE THAN THE COLLAPSE.
       A hidden filter that is still applied is dangerous here: the table says
       "No transactions match these filters", and if you cannot see that Bank
       is still set to DANA from yesterday, that reads as "no withdrawals
       waiting". So the button carries a count of what is active and turns
       amber when it is not zero. Collapsing is only safe because of this. */
    .filters-toggle {
      display: inline-flex; align-items: center; gap: 6px;
      padding: 8px 14px; border-radius: 10px;
      border: 1px solid #cbd5e1; background: white;
      font-family: inherit; font-size: 13px; font-weight: 600; color: #1d4ed8;
    }
    .filters-toggle::after { content: '▾'; font-size: 10px; }
    .filters.filters-open .filters-toggle::after { content: '▴'; }
    /* Amber, not blue: a filter is hiding rows from you right now. */
    .filters-toggle.has-active {
      background: #fef3c7; border-color: #f59e0b; color: #92400e;
    }

    #tx-filter-more { display: none; }
    .filters.filters-open #tx-filter-more {
      display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
      width: 100%;      /* its own row, under Brand */
    }

    /* ---- Automation: three columns down to one ------------------------
       This page stayed a 3-column grid on a phone. Nothing overflowed, so
       the earlier sweep called it clean -- but "fits on screen" is not the
       same as "usable": the fields were 92px wide and the source-bank
       dropdown was 66px, which is not enough to read a bank name in, let
       alone the brand identity card's Website name and Merchant code.

       The span helpers have to be reset too. `grid-column: span 2` in a
       one-column grid does not clamp to the one column -- it makes the
       browser invent a second one, and the layout overflows again in a way
       that is much harder to see the cause of. */
    #tab-automation .ac-grid,
    #tab-automation .ac-brand-card-grid {
      grid-template-columns: 1fr !important;
    }
    #tab-automation .ac-grid > .span-2,
    #tab-automation .ac-grid > .span-3,
    #tab-automation .ac-brand-card-grid > .span-3 {
      grid-column: 1 / -1 !important;
    }

    /* Cards / settings rows: drop multi-column layouts to single column. */
    .settings-card, .rp-summary-card {
      padding: 12px !important;
      min-width: 0 !important;
    }
    .settings-row {
      flex-direction: column !important;
      align-items: stretch !important;
      gap: 6px !important;
    }
    /* Overrides for the children that have fixed dimensions designed for
       the desktop row layout. When the row stacks (column flex), the
       desktop `flex: 0 0 280px` on the label becomes HEIGHT: 280px,
       which created huge empty gaps between label and input on phones.
       Reset to auto sizing so each child takes its natural content size. */
    .settings-row label {
      flex: 0 0 auto !important;
      width: auto !important;
      font-weight: 600 !important;
    }
    .settings-row input,
    .settings-row select {
      width: 100% !important;
      max-width: none !important;
      text-align: left !important;
    }
    .settings-row .suffix,
    .settings-row .hint {
      margin-left: 0 !important;
      font-size: 11px !important;
    }
    /* Save button rows: full-width buttons, stack vertically. */
    .save-btn-row {
      flex-direction: column !important;
      gap: 6px !important;
    }
    .save-btn-row button { width: 100% !important; }
    .rp-summary-grid {
      grid-template-columns: 1fr !important;
      gap: 8px !important;
    }

    /* Wallet badge, pp-banner, etc.: shrink + wrap. */
    #pp-banner {
      flex-direction: column !important;
      gap: 4px !important;
      font-size: 12px !important;
      padding: 8px !important;
      text-align: center !important;
    }
    #toast-container { width: 90vw; max-width: 480px; }

    /* Form fields: full width inputs on mobile. */
    .form-group input,
    .form-group select,
    .form-group textarea { width: 100% !important; max-width: none !important; }

    /* Filter bars (Deposits / Reports etc.): wrap nicely. */
    #dep-filter-bar { gap: 8px !important; padding: 10px !important; }
    #dep-filter-bar > div { min-width: 0 !important; }

    /* Login box: don't overflow on narrow phones. */
    .login-box { width: auto !important; max-width: 92vw; padding: 24px !important; }
  }

  /* Very small phones (≤360px) — extra-tight padding. */
  @media (max-width: 360px) {
    main { padding: 8px 4px !important; }
    .table-wrap table { font-size: 11px !important; }
    .table-wrap th, .table-wrap td { padding: 4px 6px !important; }
  }
