/* ============================================================================
   viyabook-mobile.css — ViyaBook Wave-style Mobile Layout
   Inspired by Wave (next.waveapps.com) mobile UX patterns.
   Loaded on every app page via components/layout.js injection.
   All rules scoped to ≤767px (PHONES only). Tablets (768–1024) use tablet.css and
   the desktop shell — iPad portrait is 768px, so it is a TABLET, never a phone.
   ============================================================================ */

/* ─── GLOBAL MOBILE SHELL ──────────────────────────────────────────────────── */
@media (max-width: 767px) {

  /* Page container */
  .dashboard-shell { display: block !important; }
  .sidebar { display: none !important; }
  .topbar { display: none !important; }

  /* Main content: safe bottom padding for floating nav */
  body .main-content,
  body .main {
    padding: 12px 14px calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
    background: #f4f6f9 !important;
  }

  /* ─── PAGE HEADER ── */
  .page-head {
    display: block !important;
    padding: 0 0 14px !important;
    margin-bottom: 0 !important;
    background: transparent !important;
  }
  .page-head h1, .page-h1 {
    font-size: 22px !important;
    font-weight: 800 !important;
    color: #0b2148 !important;
    margin: 0 0 2px !important;
    letter-spacing: -0.02em !important;
  }
  .page-head p, .page-head .sub, .page-head .subtitle {
    font-size: 13px !important;
    color: var(--muted, #64748b) !important;
    margin: 0 0 12px !important;
  }

  /* Actions: horizontal scrolling pill row */
  .head-actions, .page-actions, .actions {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 7px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    padding-bottom: 2px !important;
    width: auto !important;
    margin-top: 10px !important;
  }
  .head-actions::-webkit-scrollbar,
  .page-actions::-webkit-scrollbar { display: none !important; }
  .head-actions .btn, .page-actions .btn, .actions .btn,
  .head-actions button, .page-actions button, .actions button {
    flex: 0 0 auto !important;
    height: 38px !important;
    min-height: 38px !important;
    padding: 0 14px !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    border-radius: 10px !important;
    white-space: nowrap !important;
    box-shadow: none !important;
  }

  /* ─── SUMMARY / KPI CARDS ── */
  .summary-grid, .stats-grid, .metrics, .kpis, .vb-summary-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
  }
  .summary-card, .summary, .stat, .metric {
    min-height: 88px !important;
    padding: 10px 12px !important;
    border-radius: 12px !important;
    box-shadow: 0 2px 10px rgba(15,23,42,.05) !important;
  }
  .summary-card span, .stat h3, .metric h3 {
    font-size: 11px !important;
    font-weight: 600 !important;
    color: var(--muted) !important;
  }
  .summary-card strong, .stat .value, .metric h2 {
    font-size: 18px !important;
    font-weight: 800 !important;
    letter-spacing: -0.02em !important;
  }
  .summary-card small, .stat p { font-size: 10px !important; }

  /* ─── TYPE/FILTER TABS ── */
  .type-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 7px !important; }
  .type-card { min-height: 0 !important; padding: 12px !important; border-radius: 12px !important; }
  .type-card h2 { font-size: 14px !important; }
  .type-card p { font-size: 11px !important; }

  /* ─── GENERIC CARDS / PANELS ── */
  .card, .panel, .table-card, .tool-card, .vb-card {
    border-radius: 14px !important;
    padding: 12px !important;
    box-shadow: 0 2px 10px rgba(15,23,42,.04) !important;
    margin-bottom: 10px !important;
  }

  /* ─── WAVE-STYLE LIST ROWS (table → flat rows) ── */
  /* Hide table header */
  table thead { display: none !important; }

  /* Each row = full-width card with divider between fields */
  table tbody tr {
    display: block !important;
    background: #ffffff !important;
    border: none !important;
    border-bottom: 1px solid #f0f2f5 !important;
    border-radius: 0 !important;
    padding: 14px 16px !important;
    margin-bottom: 0 !important;
    box-shadow: none !important;
  }
  table tbody tr:first-child { border-top: 1px solid #f0f2f5 !important; border-radius: 14px 14px 0 0 !important; }
  table tbody tr:last-child { border-radius: 0 0 14px 14px !important; }

  /* Each cell: label left, value right */
  table tbody td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 12px !important;
    border: none !important;
    border-bottom: 1px solid #f8fafc !important;
    padding: 6px 0 !important;
    text-align: right !important;
    font-size: 13px !important;
    width: auto !important;
  }
  table tbody tr td:last-child { border-bottom: none !important; }
  table tbody td::before {
    content: attr(data-label);
    font-size: 11px !important;
    font-weight: 700 !important;
    color: var(--muted, #64748b) !important;
    text-align: left !important;
    flex: 0 0 auto !important;
    white-space: nowrap !important;
  }
  table tbody td[data-label=""]::before { content: none !important; }
  table tbody td:first-child {
    font-size: 14px !important;
    font-weight: 700 !important;
    color: var(--text, #0b2148) !important;
    text-align: left !important;
    padding-bottom: 8px !important;
  }
  table tbody td:first-child::before { content: none !important; }

  /* Override: wrap table in white card */
  .table-card, .table-wrap, .table-shell {
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    overflow-x: visible !important;
  }

  /* ─── MODALS → BOTTOM SHEETS ── */
  .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal, .modal-lg, .modal-card, .modal-inner,
  .modal-overlay > div:not(.vb-modal-overlay) {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    margin: 0 !important;
    overflow-y: auto !important;
  }
  .modal-actions, .modal-footer, .save-row {
    position: sticky !important;
    bottom: 0 !important;
    background: #fff !important;
    padding: 12px 0 !important;
    gap: 8px !important;
  }
  .modal-actions .btn, .modal-footer .btn, .save-row .btn {
    flex: 1 !important;
    min-height: 44px !important;
  }
  /* VB Modal (newer) */
  .vb-modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .vb-modal {
    border-radius: 20px 20px 0 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh !important;
  }

  /* ─── FORMS ── */
  .form-grid, .modal-grid, .detail-grid, .grid-top, .notes-totals {
    grid-template-columns: 1fr !important;
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select, textarea {
    max-width: 100% !important;
    box-sizing: border-box !important;
    font-size: 16px !important; /* prevents iOS zoom */
  }

  /* ─── FILTERS ── */
  .filter-grid, .filter-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
  }
  .filter-grid > *, .filter-row > * { width: 100% !important; }
  .vb-filter-bar {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 7px !important;
  }
  .vb-filter-search-wrap { flex: 1 1 100% !important; min-width: 0 !important; }
  .vb-filter-select {
    height: 36px !important;
    font-size: 13px !important;
    flex: 1 1 auto !important;
  }

  /* ─── SEARCH ── */
  .search-wrap, .search-box { width: 100% !important; }

  /* ─── TABS (chips) ── */
  .vb-tab-row {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  .vb-tab {
    height: 30px !important;
    padding: 0 12px !important;
    font-size: 12px !important;
    border-radius: 999px !important;
  }

  /* ─── PAGINATION ── */
  .pagination {
    flex-wrap: wrap !important;
    gap: 4px !important;
    justify-content: center !important;
  }
  .page-btn {
    min-height: 32px !important;
    min-width: 32px !important;
    font-size: 12px !important;
    border-radius: 8px !important;
  }

  /* ─── SETTINGS: horizontal tab scroll ── */
  .settings-menu, .settings-nav {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    gap: 4px !important;
    padding: 8px 0 !important;
    border-bottom: 1px solid var(--border) !important;
    border-right: none !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    position: sticky !important;
    top: 0 !important;
    background: #f4f6f9 !important;
    z-index: 5 !important;
  }
  .settings-menu::-webkit-scrollbar { display: none !important; }
  .settings-link {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 6px 14px !important;
    border-radius: 20px !important;
    font-size: 12px !important;
  }
  .settings-layout {
    display: block !important;
  }

  /* ─── GRIDS COLLAPSE ── */
  .grid-2, .grid-3, .grid-4,
  .dashboard-grid, .bottom-grid, .plan-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .quick-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  /* ─── HIDE DESKTOP-ONLY ELEMENTS ── */
  .desktop-only, .hide-mobile { display: none !important; }

  /* ─── TABLE OVERFLOW FOR COMPLEX TABLES (invoice line items etc) ── */
  .items-card, .line-items-card { overflow-x: auto !important; }
  .items-card table, .line-items-card table { min-width: 560px !important; }
}

/* ─── SMALL PHONES (≤480px) ── */
@media (max-width: 480px) {
  body .main-content, body .main {
    padding: 10px 12px calc(96px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .page-head h1, .page-h1 { font-size: 19px !important; }
  .summary-grid, .kpis, .vb-summary-grid {
    gap: 7px !important;
  }
  .summary-card strong, .stat .value { font-size: 16px !important; }
}
