/* =====================================================================
   Cadence — admin dashboard
   RESPONSIVE — every media query in the app lives here, away from the
   component rules. Breakpoints: sidebar collapses to a top bar under
   900px, tables stack into labelled cards under 640px, and dialogs /
   stat grids compact further under 640px / 560px. Also the touch and
   reduced-motion behaviours.
   ===================================================================== */

/* ---------- Under 900px: the sidebar becomes an off-canvas drawer ----------
   A hamburger in the pagehead (hidden on desktop) opens it. The drawer is
   always present and translated off-canvas; `.is-open` slides it in over a
   scrim. Clicking a nav item, the scrim, or pressing Escape closes it (wired
   in main.js). z-index: sidebar 60 > scrim 55 > pagehead 30, and well below
   the slide-over (100) / dialogs so overlays still cover the drawer.
   `minmax(0, 1fr)` rather than a bare `1fr` is load-bearing: a grid track
   defaults to a min-content MINIMUM, so fixed-width children would widen the
   single column past the viewport and drag `.main` out with it. */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .main { min-width: 0; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(300px, 86vw); height: 100dvh;
    flex-direction: column; align-items: stretch; gap: 8px;
    padding: var(--space-md);
    border-right: 1px solid var(--border); border-bottom: none;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    z-index: 60;
    transform: translateX(-105%);
    transition: transform .28s var(--ease);
    overflow-y: auto;
  }
  .sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-float); }
  .sidebar__brand { padding: var(--space-xs) 0 var(--space-md); justify-content: flex-start; }
  /* The brand wordmark shows in the drawer. */
  .sidebar__word { display: flex; flex-direction: column; gap: 2px; overflow: visible; white-space: normal; }
  .nav {
    flex-direction: column; gap: 4px; flex: 1;
    overflow: visible; min-width: 0; align-items: stretch;
  }
  .nav__item {
    flex-direction: row; gap: 12px; width: 100%; height: auto;
    padding: 11px 14px; border-radius: 999px;
  }
  .nav__item .ic { width: var(--ic-sm); height: var(--ic-sm); }
  .nav__label { display: inline; flex: 1; }
  .nav__badge { display: inline-flex; }
  .sidebar__foot {
    flex-direction: column; align-items: stretch;
    padding-top: var(--space-sm); border-top: 1px solid var(--border-2);
  }
  .sidebar__actions { flex-direction: row; align-items: center; gap: var(--space-sm); }
  .who { justify-content: flex-start; padding: var(--space-xs); }
  .who__meta { display: flex; flex-direction: column; }
  .who__email { font-weight: 600; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .who__role { font-size: .74rem; color: var(--faint); }
  #sign-out { width: auto; height: auto; padding: 10px 18px; border-radius: 999px; }
  #sign-out .nav__label { display: inline; }
  .pagehead__menu { display: inline-flex; }
  .nav-backdrop {
    display: block;
    position: fixed; inset: 0; z-index: 55;
    background: rgba(13,16,12,.55);
    opacity: 0; pointer-events: none;
    transition: opacity .2s var(--ease);
  }
  .nav-backdrop.is-open { opacity: 1; pointer-events: auto; }
}

/* ---------- Very narrow phones: drop the brand wordmark entirely ----------
   Below ~400px even an ellipsised wordmark steals room the tab strip needs. */
@media (max-width: 400px) {
  .sidebar__word { display: none; }
  .sidebar { gap: var(--space-xs); padding: var(--space-sm); }
}

/* ---------- Revenue band stacks below 720px ---------- */
@media (max-width: 720px) {
  .revenue { grid-template-columns: 1fr; gap: 16px; }
  .revenue__side {
    border-left: none; padding-left: 0; padding-top: 16px;
    border-top: 1px solid var(--border-2);
  }
}
@media (max-width: 720px) {
  .revenue--out .revenue__side { border-top-color: var(--border-2); }
}

/* ---------- Under 640px: nav keeps short labels so the top bar stays usable ---------- */
@media (max-width: 640px) {
  .pagehead { padding: 14px 14px; }
  .pagehead__title { font-size: 1.15rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-tile { padding: 13px 13px 15px; }
  .stat-tile__value { font-size: 1.5rem; }
  .dialog__row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .slideover__panel { width: 100vw; }
}

/* ---------- Responsive tables — rows become stacked cards under 900px.
   The sidebar becomes a drawer at 900px, so the content column there is
   only ~600–850px wide — too narrow for the widest table (Users, ~1360px
   natural). Tables stay real tables only when the sidebar is visible; in
   the whole drawer zone they reflow to labelled cards instead of forcing
   horizontal panning. The JS tags every <td> with a data-label; on small
   screens the cell is relaid out as a label + value pair so the core
   workflows (grant, approve, claim, settle) stay one thumb away without
   horizontal panning. ---------- */
@media (max-width: 900px) {
  .table-wrap { background: transparent; border: 0; border-radius: 0; overflow: visible; }
  .table { min-width: 0; }
  .table, .table tbody, .table tr { display: block; width: 100%; }
  .table thead { display: none; }
  .table tbody tr {
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    box-shadow: var(--shadow-hair);
    padding: 4px 14px 10px;
    margin-bottom: 12px;
  }
  .table tbody tr:hover { background: var(--surface); }
  .table tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 9px 0; border-bottom: 1px solid var(--border-2); text-align: left;
  }
  .table tbody td:last-child { border-bottom: 0; }
  .table tbody td::before {
    content: attr(data-label);
    flex: none; max-width: 45%;
    font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
    color: var(--faint);
  }
  .table tbody td:not([data-label])::before,
  .table tbody td[data-label=""]::before { content: none; }
  .table .num { text-align: left; }
  .table tbody tr .row-actions { opacity: 1; justify-content: flex-start; }
  .table tbody td .row-actions { width: 100%; padding-top: 4px; }
  .table tbody .table__empty { display: block; text-align: center; padding: 32px 16px; }
}

/* ---------- Row actions: always show on touch devices ---------- */
@media (hover: none) {
  .table tbody tr .row-actions { opacity: 1; }
}

/* ---------- Dialog actions wrap below 560px ---------- */
@media (max-width: 560px) {
  .dialog__actions { flex-wrap: wrap; }
  .dialog__actions .btn--left { margin-right: 0; }
}

/* ---------- Reduced motion — respect the user's OS setting ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .001ms; animation-duration: .001ms; animation-iteration-count: 1; }
  .stat-tile, .revenue, .chart-card { animation: none; }
}
