/* ════════════════════════════════════════════════════════════════════
   Scapa — mobile responsive layer (loaded last; overrides scapa-theme).
   Focus: the top header and the data grids, which were the two things
   that broke / clipped on phones. Additive, low-risk overrides.
   ════════════════════════════════════════════════════════════════════ */

/* ── Top header: keep it to one tidy row on phones ────────────────── */
@media (max-width: 640px) {
  .volt-header { padding: 0 0.85rem; height: 60px; gap: 0.5rem; }

  /* Branding lives in the sidebar; the page has its own <h1>. Drop the
     header title text so the action buttons have room and never overlap. */
  .volt-header-kicker,
  .volt-header-copy { display: none !important; }
  .volt-header-left { flex: 0 0 auto; gap: 0.5rem; }

  .volt-header-actions { gap: 0.3rem; flex: 1 1 auto; justify-content: flex-end; flex-wrap: nowrap; min-width: 0; }

  /* Compact unit switch */
  .volt-unit-switch button { padding: 0.28rem 0.5rem; font-size: 0.68rem; }

  /* Slightly smaller round controls */
  .volt-theme-toggle,
  .scapa-help-btn,
  .volt-notif-bell { width: 34px; height: 34px; }

  /* "New dive" → icon only (the + is enough; full action is in the sidebar/grids) */
  .volt-tour-newdive .rz-button-text { display: none; }
  .volt-tour-newdive { padding: 0 0.6rem !important; min-width: 0; }
  .volt-tour-newdive .rzi,
  .volt-tour-newdive .rz-button-icon-left { margin: 0 !important; }
}

/* Hide the unit switch on very narrow screens (still available in Settings). */
@media (max-width: 380px) {
  .volt-unit-switch { display: none; }
}

/* ── Data grids: make the existing horizontal scroll DISCOVERABLE ──
   The Radzen grid body (.rz-data-grid-data) already scrolls horizontally,
   but on touch screens there's no scrollbar, so columns looked "cut off".
   Add a visible thin scrollbar + a right-edge fade that signals "more →". */
@media (max-width: 820px) {
  .rz-data-grid.rz-datatable-scrollable { position: relative; }

  .rz-data-grid-data {
    overflow-x: auto !important;
    scrollbar-width: thin;
    scroll-snap-type: x proximity;
  }
  .rz-data-grid-data::-webkit-scrollbar { height: 7px; }
  .rz-data-grid-data::-webkit-scrollbar-track { background: transparent; }
  .rz-data-grid-data::-webkit-scrollbar-thumb {
    background: var(--volt-primary, #e8631c);
    border-radius: 99px;
    opacity: 0.6;
  }

  /* Right-edge fade cue (pinned to the non-scrolling outer wrapper). */
  .rz-data-grid.rz-datatable-scrollable::after {
    content: "";
    position: absolute;
    top: 0; right: 0; bottom: 14px;
    width: 30px;
    background: linear-gradient(to right, transparent, var(--volt-card, #fff));
    pointer-events: none;
    z-index: 2;
  }

  /* A small "swipe" hint shown above every grid on small screens. */
  .rz-data-grid.rz-datatable-scrollable::before {
    content: "← swipe to see all columns →";
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--volt-text-muted, #8a93a6);
    padding: 0.35rem 0.1rem;
    text-align: center;
  }

  /* Keep cells from wrapping to weird heights while scrolling. */
  .rz-data-grid .rz-grid-table td,
  .rz-data-grid .rz-grid-table th { white-space: nowrap; }
}

/* ── General small-screen polish ──────────────────────────────────── */
@media (max-width: 640px) {
  /* Page header + its action buttons stack full width. */
  .scapa-page-header,
  .volt-page-header { flex-direction: column; align-items: stretch; gap: 0.75rem; }

  /* Cards: trim padding so content has more room. */
  .scapa-card,
  .volt-card { padding: 1rem; }

  /* Two-column form rows collapse to one column when very tight. */
  .scapa-field-row,
  .scapa-form-grid { grid-template-columns: 1fr !important; }
}

/* ── Phones: data grids become stacked label:value cards (no swipe) ──
   scapa-grid-cards.js tags each <td> with data-label = its column header;
   here we restyle the table so every row is a self-contained card. */
@media (max-width: 640px) {
  /* Turn off the swipe affordances — we show full rows as cards now. */
  .rz-data-grid.rz-datatable-scrollable::before,
  .rz-data-grid.rz-datatable-scrollable::after { display: none !important; }
  .rz-data-grid-data { overflow-x: visible !important; }

  .rz-data-grid table.rz-grid-table { display: block; width: 100%; min-width: 0 !important; }
  .rz-grid-table thead { display: none; }            /* headers shown inline as labels */
  .rz-grid-table tbody { display: block; }

  .rz-grid-table tbody tr {
    display: block;
    margin: 0 0 0.7rem;
    padding: 0.25rem 0.15rem;
    border: 1px solid var(--volt-border);
    border-radius: 12px;
    background: var(--volt-card) !important;
    box-shadow: var(--volt-shadow-sm);
  }

  .rz-grid-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: auto !important;
    max-width: none !important;
    min-height: 0 !important;
    border: none !important;
    border-bottom: 1px solid var(--volt-border-soft, rgba(140,150,170,0.14)) !important;
    padding: 0.5rem 0.85rem !important;
    white-space: normal !important;
    text-align: right;
  }
  .rz-grid-table tbody tr td:last-child { border-bottom: none !important; }

  /* The column name (from data-label) sits on the left of each cell. */
  .rz-grid-table tbody td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    text-align: left;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--volt-text-muted);
  }

  /* Cells with no header (actions, select, expander) span full width, centered. */
  .rz-grid-table tbody td[data-label=""] { justify-content: center; }
  .rz-grid-table tbody td[data-label=""]::before { content: none; }

  /* Keep editor/cover/action controls from being squeezed. */
  .rz-grid-table tbody td .rz-cell-data { width: auto; }
}
