/* =========================================================
   mobile.css — Mobile layout (767px and below)
   Sizes/colors/type stay identical to desktop; only layout changes.
   Depends on: tokens.css, base.css, components.css
   ========================================================= */

@media (max-width: 767px) {

  /* Hide desktop-only chrome */
  .desktop-only, .topbar-search-wide { display: none !important; }

  /* Prevent iOS zoom on input focus without changing token sizes */
  .input, .select, .textarea { font-size: 16px; line-height: var(--line-height-lg); }

  /* ---------- App shell: topbar + content + bottom nav ---------- */
  .app {
    display: flex; flex-direction: column;
    min-height: 100vh;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  }

  .topbar {
    position: sticky; top: 0; z-index: var(--z-sticky);
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-12);
    height: var(--topbar-height);
    padding: 0 var(--space-16);
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
  }
  .topbar-actions { display: flex; align-items: center; gap: var(--space-4); }
  .menu-toggle { display: inline-flex; }

  .main { flex: 1; min-width: 0; }

  .page {
    display: flex; flex-direction: column; gap: var(--space-16);
    padding: var(--space-16);
  }

  .page-header { display: flex; flex-direction: column; align-items: stretch; gap: var(--space-12); }
  .page-actions { display: flex; gap: var(--space-8); }
  .page-actions > .btn { flex: 1; }

  /* ---------- Sidebar becomes off-canvas drawer ---------- */
  .sidebar {
    display: none;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: var(--z-drawer);
    width: min(var(--sidebar-width), 85vw);
    flex-direction: column; gap: var(--space-24);
    padding: var(--space-16);
    background: var(--color-bg-card);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
  }
  .sidebar.is-open { display: flex; }
  .sidebar-brand { display: flex; align-items: center; gap: var(--space-12); height: var(--control-md); padding: 0 var(--space-12); }
  .sidebar-nav { display: flex; flex-direction: column; gap: var(--space-4); }
  .sidebar-footer { margin-top: auto; }

  /* Backdrop for drawer (toggle .is-visible with JS) */
  .overlay { display: none; }
  .overlay.is-visible { display: block; }

  /* ---------- Bottom navigation ---------- */
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky);
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--color-bg-card);
    border-top: 1px solid var(--color-border);
  }
  .bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: var(--text-pair-gap);
    font-size: var(--font-size-xs); line-height: var(--line-height-xs); font-weight: var(--font-weight-xs);
    color: var(--color-text-secondary); text-decoration: none;
  }
  .bottom-nav-item:hover { text-decoration: none; background: var(--color-bg-hover); }
  .bottom-nav-item.is-active, .bottom-nav-item[aria-current="page"] { color: var(--color-primary); }

  /* ---------- Grids: single column; stats 2-up ---------- */
  .grid { display: grid; gap: var(--space-16); grid-template-columns: minmax(0, 1fr); }
  .grid-2, .grid-3, .grid-4, .grid-sidebar-right, .grid-sidebar-left { grid-template-columns: minmax(0, 1fr); }
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-12); }
  .col-span-2, .col-span-3 { grid-column: auto; }

  /* ---------- Cards: tighter padding (same type size) ---------- */
  .card-header, .card-body, .card-footer, .stat { padding: var(--space-16); }

  /* ---------- Forms: one column, full-width actions ---------- */
  .form { display: flex; flex-direction: column; gap: var(--space-16); }
  .form-row, .form-row-3 { display: flex; flex-direction: column; gap: var(--space-16); }
  .form-actions { display: flex; flex-direction: column-reverse; gap: var(--space-8); }
  .form-actions > .btn { width: 100%; }

  /* ---------- Toolbar: stacked, filters scroll sideways ---------- */
  .toolbar { display: flex; flex-direction: column; align-items: stretch; gap: var(--space-12); }
  .toolbar-filters { display: flex; gap: var(--space-8); overflow-x: auto; padding-bottom: var(--space-4); }
  .toolbar .input-group { width: 100%; }

  /* ---------- Tables: horizontal scroll by default ---------- */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .table { min-width: 560px; }

  /* Optional: stacked "card rows" — add .table-responsive and data-label on <td> */
  .table-responsive { min-width: 0; }
  .table-responsive thead { display: none; }
  .table-responsive, .table-responsive tbody, .table-responsive tr, .table-responsive td { display: block; width: 100%; }
  .table-responsive tr { padding: var(--space-12) var(--space-16); border-bottom: 1px solid var(--color-border); }
  .table-responsive tbody tr:last-child { border-bottom: 0; }
  .table-responsive td { display: flex; justify-content: space-between; gap: var(--space-16); padding: var(--space-4) 0; border: 0; text-align: right; }
  .table-responsive td::before { content: attr(data-label); color: var(--color-text-secondary); font-size: var(--font-size-sm); line-height: var(--line-height-sm); text-align: left; }
  .table-responsive tbody tr:hover td { background: transparent; }

  /* ---------- Modal → bottom sheet ---------- */
  .modal-backdrop { align-items: flex-end; justify-content: center; padding: 0; }
  .modal {
    max-width: 100%; max-height: 90vh;
    border-radius: var(--radius-20) var(--radius-20) 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .modal-lg { max-width: 100%; }
  .modal-footer { flex-direction: column-reverse; align-items: stretch; }
  .modal-footer > .btn { width: 100%; }

  /* ---------- Drawer (right panel) → full screen ---------- */
  .drawer {
    position: fixed; inset: 0; z-index: var(--z-drawer);
    display: flex; flex-direction: column;
    background: var(--color-bg-card);
  }

  /* ---------- Dropdown → bottom sheet style ---------- */
  .dropdown > .menu {
    position: fixed; left: var(--space-16); right: var(--space-16);
    bottom: calc(var(--space-16) + env(safe-area-inset-bottom, 0px));
    z-index: var(--z-modal); min-width: 0;
  }
  .menu-item { height: var(--control-md); }

  /* Tabs scroll horizontally */
  .tabs { gap: var(--space-20); scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }

  /* Comfortable touch targets */
  .btn-sm { height: var(--control-sm); }
  .nav-item, .list-item { min-height: var(--control-md); }
}
