/* ═══════════════════════════════════════════════════════════════════
   BILLMASTER PRO — MOBILE & TABLET RESPONSIVE FIXES
   Targets: Android/iOS phones (≤480px) + tablets (≤960px)
   Fixes: overflow, cut-off content, topbar crowding, hero layout,
          stats grid, invoice cards, inventory table, forms
═══════════════════════════════════════════════════════════════════ */

/* ── 1. Global overflow guard ─────────────────────────────────────── */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

.app-shell,
.main-content,
.content-area {
  max-width: 100%;
  overflow-x: hidden;
}

/* ── 2. Topbar — prevent right-side cut-off ───────────────────────── */
.topbar {
  padding: 0 12px;
  gap: 8px;
  min-height: var(--topbar-h);
  height: auto;
  flex-wrap: nowrap;
  overflow: hidden;
}

.topbar-left {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.page-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.topbar-actions {
  flex-shrink: 0;
  gap: 6px;
  flex-wrap: nowrap;
}

/* Compact the "+ New Invoice" button on small screens */
@media (max-width: 480px) {
  .topbar { padding: 0 10px; gap: 6px; height: auto; min-height: var(--topbar-h); }
  .topbar-actions .btn { font-size: 12px; padding: 6px 10px; gap: 4px; white-space: nowrap; }
  .page-title { font-size: 14px !important; }
}
@media (max-width: 360px) {
  .page-title { font-size: 13px !important; }
  .topbar-actions .btn { font-size: 11px; padding: 5px 8px; }
}

/* ── 3. Sidebar — correct z-index and full-height on mobile ───────── */
@media (max-width: 960px) {
  .sidebar {
    transform: translateX(-100%);
    top: 0;
    height: 100%;
    height: 100dvh;
    z-index: 300;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { z-index: 299; }
  .main-content { margin-left: 0 !important; width: 100%; }
}

/* ── 4. Content area padding ──────────────────────────────────────── */
@media (max-width: 960px) {
  .content-area { padding: 14px 12px; }
}
@media (max-width: 480px) {
  .content-area { padding: 10px 10px; }
}

/* ── 5. Dashboard Revenue Hero ────────────────────────────────────── */
@media (max-width: 960px) {
  .revenue-hero { padding: 20px 18px; border-radius: 14px; }
  .revenue-hero-inner {
    flex-direction: column;
    gap: 14px;
    align-items: flex-start;
  }
  .revenue-hero-amount { font-size: 36px; }
  .hero-minis {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .rev-mini {
    min-width: unset;
    padding: 10px 10px;
    border-radius: 10px;
  }
  .rev-mini-val { font-size: 15px; }
  .rev-mini-label { font-size: 9px; }
}

@media (max-width: 480px) {
  .revenue-hero { padding: 16px 14px; margin-bottom: 12px; }
  .revenue-hero-amount { font-size: 30px; }
  .hero-minis { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .rev-mini { padding: 8px 8px; }
  .rev-mini-val { font-size: 14px; }
}

/* ── 6. Stats Row (dashboard 4-column) ────────────────────────────── */
@media (max-width: 960px) {
  .stats-row { grid-template-columns: 1fr 1fr !important; gap: 10px; }
}
@media (max-width: 380px) {
  .stats-row { grid-template-columns: 1fr !important; }
}

.stat-card-v2 {
  min-width: 0;
  overflow: hidden;
}

.stat-val-v2 { font-size: 22px !important; }

@media (max-width: 480px) {
  .stat-icon-v2 { width: 40px; height: 40px; }
  .stat-val-v2 { font-size: 19px !important; }
  .stat-lbl-v2 { font-size: 10px; }
}

/* ── 7. Stats grid (general, reports) ─────────────────────────────── */
@media (max-width: 960px) {
  .stats-grid { grid-template-columns: 1fr 1fr !important; }
}
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr !important; }
}

/* ── 8. Dashboard grid + charts ──────────────────────────────────── */
@media (max-width: 960px) {
  .dashboard-grid-v2 { grid-template-columns: 1fr !important; }
  .charts-top { grid-template-columns: 1fr !important; }
  .chart-wrap-bar { height: 200px !important; }
  .chart-wrap-line { height: 180px !important; }
}

@media (max-width: 480px) {
  .donut-inner { flex-direction: column; }
  .donut-canvas-wrap { align-self: center; }
  .chart-controls { gap: 6px; }
  .pill-btn { font-size: 10px !important; padding: 3px 7px !important; }
}

/* ── 9. Invoice Summary strip (invoices page) ─────────────────────── */
.inv-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 480px) {
  .inv-summary { grid-template-columns: 1fr 1fr; gap: 8px; }
}
@media (max-width: 320px) {
  .inv-summary { grid-template-columns: 1fr; }
}

.sum-card { min-width: 0; overflow: hidden; }
.sum-val { font-size: 20px !important; }
@media (max-width: 400px) {
  .sum-val { font-size: 17px !important; }
}

/* ── 10. Invoice filter pills row — scrollable ────────────────────── */
.inv-filters {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
  flex-wrap: nowrap !important;
}
.inv-filters::-webkit-scrollbar { display: none; }
.inv-filters .pill { flex-shrink: 0; }

/* ── 11. Invoice cards (mobile card view) ─────────────────────────── */
.inv-card {
  border-radius: 12px !important;
  padding: 14px 14px !important;
}
.inv-card-top { flex-wrap: nowrap; gap: 8px; }
.inv-card-num { font-size: 13px !important; }
.inv-card-amount { font-size: 16px !important; }

/* ── 12. Inventory / Products table ──────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { min-width: 320px; }

@media (max-width: 600px) {
  thead th { font-size: 9.5px; padding: 8px 10px; letter-spacing: .5px; }
  td { font-size: 12px; padding: 9px 10px; }
  .td-actions { gap: 4px; }
  .td-actions .btn { padding: 5px 8px; font-size: 11px; }
}

/* ── 13. Invoice form ─────────────────────────────────────────────── */
@media (max-width: 767px) {
  .content-area { padding: 8px !important; }
  .iv-card { border-radius: 12px; margin-bottom: 8px; }
  .iv-card-body { padding: 10px 12px; }
  .iv-input { font-size: 14px; padding: 9px 11px; }
  .pay-chip { padding: 8px 12px; font-size: 12px; }
}

/* ── 14. Subscription page ────────────────────────────────────────── */
@media (max-width: 600px) {
  .sub-hero { padding: 24px 18px !important; border-radius: 16px !important; }
  .sub-days-ring { width: 100px !important; height: 100px !important; }
  .sub-days-number { font-size: 28px !important; }
  .sub-detail-grid { grid-template-columns: 1fr !important; }
}

/* ── 15. Reports / KPI cards ─────────────────────────────────────── */
@media (max-width: 600px) {
  .kpi-grid, .rpt-kpi-grid { grid-template-columns: 1fr 1fr !important; }
  .kpi-value, .rpt-kpi-val { font-size: 20px !important; }
}
@media (max-width: 360px) {
  .kpi-grid, .rpt-kpi-grid { grid-template-columns: 1fr !important; }
}

/* ── 16. Page header with action button ───────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
@media (max-width: 480px) {
  .page-header { margin-bottom: 12px; }
  .page-header .btn { font-size: 12px; padding: 7px 12px; }
}

/* ── 17. Flash messages ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .flash-container { padding: 8px 10px 0; }
  .flash { font-size: 12px; padding: 9px 12px; border-radius: 8px; }
}

/* ── 18. Auth page ────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .auth-card { flex-direction: column; min-height: unset; border-radius: 16px; }
  .auth-panel-left { flex: none; padding: 28px 24px; }
  .auth-panel-right { flex: none; padding: 28px 24px 32px; }
}
@media (max-width: 400px) {
  .auth-panel-left { padding: 20px 18px; }
  .auth-panel-right { padding: 20px 18px 28px; }
  .auth-brand-title { font-size: 20px !important; }
  .auth-form-title { font-size: 20px !important; }
}

/* ── 19. Ensure all cards respect viewport width ──────────────────── */
.card, .card-v2, .stat-card, .stat-card-v2,
.kpi-card, .sum-card, .inv-card, .iv-card {
  max-width: 100%;
  box-sizing: border-box;
}

/* ── 20. Search bars full-width on mobile ─────────────────────────── */
@media (max-width: 600px) {
  .search-bar, .inv-search { width: 100% !important; max-width: 100% !important; }
  .inv-toolbar { flex-direction: column; gap: 8px; }
}

/* ── 21. User form / product form grids ──────────────────────────── */
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr !important; }
  .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr !important; }
  .form-group.span-2, .form-group.span-3 { grid-column: span 1 !important; }
}

/* ── 22. Topbar: hide theme toggle label if any ──────────────────── */
@media (max-width: 400px) {
  .theme-toggle { padding: 4px; width: 28px; height: 28px; }
}

/* ── 23. Bottom safe area for iOS ────────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
}

/* ── 24. Prevent text-size inflation on iOS ──────────────────────── */
body {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ── 25. Touch-friendly tap targets ──────────────────────────────── */
@media (max-width: 960px) {
  .nav-item {
    padding: 11px 12px;
    font-size: 14px;
    gap: 10px;
  }
  .nav-icon { width: 20px; }
  .sidebar-footer { padding: 12px 14px; }
  .logout-btn { width: 34px; height: 34px; }
  .user-avatar { width: 34px; height: 34px; font-size: 13px; }
}

/* ── 26. Invoice view / print card ───────────────────────────────── */
@media (max-width: 600px) {
  .invoice-print-card { padding: 20px 14px !important; margin: 0 !important; border-radius: 12px !important; }
  .inv-header { flex-direction: column !important; gap: 12px; }
  .inv-header-right { text-align: left !important; }
  .inv-to-from { flex-direction: column !important; gap: 12px; }
  .inv-table-cols { min-width: 320px; }
}

/* ── 27. Table footer responsive ─────────────────────────────────── */
@media (max-width: 480px) {
  .table-footer { flex-direction: column; gap: 6px; text-align: center; padding: 8px 10px; }
}
