/*
 * Ericose ERP — Mobile & Tablet Responsive CSS
 * Breakpoints:
 *   1024px — iPad landscape / small laptop
 *    768px — iPad portrait
 *    480px — large phone
 *    390px — iPhone
 */

/* ═══════════════════════════════════════════════════════════
   TABLET LANDSCAPE  ≤ 1024px
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {

  /* Main content padding */
  .erp-main { padding: 0 16px 40px; }

  /* Page header stacks on narrow screens */
  .page-header { padding: 16px 0 14px; gap: 10px; }
  .page-header h1, .page-header-title { font-size: 18px !important; }

  /* Stats grids — 3 columns max */
  .stats-row,
  [style*="grid-template-columns: repeat(5"] {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  /* Stat cards smaller */
  .stat-card { padding: 12px 14px; }
  .stat-val   { font-size: 20px !important; }

  /* Tables — horizontal scroll */
  .table-wrap, .po-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }
  .po-table { min-width: 700px; }

  /* Supplier grid — 2 columns */
  .sup-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ── Two-column modals → single column ── */
  .po-modal-body,
  [style*="grid-template-columns: 300px"],
  [style*="grid-template-columns: 280px"],
  [style*="grid-template-columns: 270px"],
  [style*="grid-template-columns: 320px 1fr"],
  [style*="grid-template-columns: 300px 1fr"],
  [style*="grid-template-columns: 280px 1fr"],
  [style*="grid-template-columns: 270px 1fr"] {
    grid-template-columns: 1fr !important;
    grid-template-rows: auto !important;
    overflow-y: auto !important;
  }

  /* Modal boxes — wider on tablet */
  .po-modal-wrap,
  .modal-box,
  [style*="max-width: 960px"],
  [style*="max-width: 940px"],
  [style*="max-width: 900px"] {
    max-width: 98vw !important;
    max-height: 95vh !important;
  }

  /* Left panels inside modals — remove right border, add bottom border */
  .po-left,
  [style*="border-right: 1px solid #f1f5f9"] {
    border-right: none !important;
    border-bottom: 1px solid #f1f5f9 !important;
    max-height: 320px;
    overflow-y: auto;
  }

  /* Form rows — stack to single column */
  .form-row { grid-template-columns: 1fr !important; gap: 10px; }

  /* Toolbar buttons — wrap */
  .toolbar { flex-wrap: wrap; gap: 6px; }
  .ftab    { font-size: 12px; height: 32px; padding: 0 12px; }
}


/* ═══════════════════════════════════════════════════════════
   TABLET PORTRAIT  ≤ 768px
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  .erp-main { padding: 0 12px 32px; }

  /* Stats — 2 columns */
  .stats-row,
  [style*="grid-template-columns: repeat(5"],
  [style*="grid-template-columns: repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Supplier grid — 1 column */
  .sup-grid { grid-template-columns: 1fr !important; }

  /* Page header — stack vertically */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-header .btn,
  .page-header .btn-primary,
  .page-header button { width: 100%; justify-content: center; }

  /* PO / Bills / Exchange modals — full screen */
  .po-modal-wrap,
  .modal-box,
  [style*="border-radius: 16px"][style*="max-width"] {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
  }

  /* Left panel height limit */
  .po-left,
  [style*="border-right: 1px solid #f1f5f9"] {
    max-height: 280px;
  }

  /* Cards and detail panels */
  .card { padding: 14px 16px; }
  .detail-panel { border-radius: 10px; }

  /* PO table — smaller text */
  .po-table th,
  .po-table td { font-size: 12px; padding: 9px 10px; }

  /* Filters / status tabs */
  .ftab { font-size: 11px; height: 30px; padding: 0 10px; }

  /* Search box */
  .search-box { max-width: 100%; }

  /* Invoice print */
  .hdr { grid-template-columns: 1fr auto !important; }
}


/* ═══════════════════════════════════════════════════════════
   LARGE PHONE  ≤ 480px
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {

  .erp-main { padding: 0 10px 28px; }

  /* Stats — single column */
  .stats-row,
  [style*="grid-template-columns: repeat"] {
    grid-template-columns: 1fr 1fr !important;
  }

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

  /* Topbar compact */
  .topbar-title  { font-size: 14px !important; }
  .topbar-branch { display: none; }

  /* Page header */
  .page-header-title { font-size: 16px !important; }

  /* Modal — true full screen */
  .po-modal-wrap,
  .modal-box {
    height: 100vh !important;
    max-height: 100vh !important;
  }

  /* PO item rows — compact */
  .po-row {
    grid-template-columns: 1fr 60px 90px 28px !important;
  }

  /* Pill badges smaller */
  .pill { font-size: 10px; padding: 2px 8px; }

  /* Table font size */
  table th, table td { font-size: 11px !important; padding: 8px 8px !important; }

  /* Sidebar — slimmer */
  .sidebar { width: 260px !important; min-width: 260px !important; }
}


/* ═══════════════════════════════════════════════════════════
   IPAD-SPECIFIC OVERRIDES (768px–1024px, touch device)
   ═══════════════════════════════════════════════════════════ */
@media (min-width: 768px) and (max-width: 1024px) {

  /* Larger tap targets */
  .btn, .btn-primary, .btn-secondary,
  .nav-item, .ftab, .action-btn {
    min-height: 40px;
  }

  /* More spacing in nav items */
  .nav-item { padding: 11px 14px !important; }

  /* Sidebar stays visible — just slightly narrower */
  .sidebar { width: 220px !important; min-width: 220px !important; }

  /* Product rows in modals — better spacing */
  .po-row, .bill-row {
    padding: 12px 0 !important;
  }

  /* Input heights for touch */
  .form-input, .form-select, .live-input {
    height: 44px !important;
    font-size: 15px !important;
  }

  /* Modal footer buttons larger */
  .submit-btn, #b-submit-btn, #po-submit-btn {
    height: 48px !important;
    font-size: 15px !important;
  }

  /* Exchange modal right panel scroll */
  #new-modal .po-right,
  [style*="flex-direction: column;overflow: hidden"] {
    overflow-y: auto !important;
  }
}


/* ═══════════════════════════════════════════════════════════
   PRINT — keep A5 portrait clean
   ═══════════════════════════════════════════════════════════ */
@media print {
  .sidebar, .topbar, .toolbar,
  .no-print, .btn, button { display: none !important; }
  .erp-shell { display: block !important; }
  .erp-main  { padding: 0 !important; overflow: visible !important; }
}
