/* ── COMPONENTS ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card-title { font-size: 14px; font-weight: 700; color: var(--text); }
.card-body { padding: 20px; }
.card-sub { font-size: 12px; color: var(--text2); margin-left: auto; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-n { font-size: 28px; font-weight: 700; color: var(--text); font-family: 'DM Mono', monospace; line-height: 1; }
.stat-l { font-size: 12px; color: var(--text2); margin-top: 6px; font-weight: 500; }
.stat-card.accent { border-left: 3px solid var(--accent); }
.stat-card.green { border-left: 3px solid var(--green); }
.stat-card.amber { border-left: 3px solid #f59e0b; }
.stat-card.red { border-left: 3px solid var(--red); }

.btn { padding: 8px 16px; border-radius: var(--radius); border: none; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; transition: all .15s; display: inline-flex; align-items: center; gap: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border2); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-green { background: var(--green); color: white; }
.btn-green:hover:not(:disabled) { background: #166534; }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid #fca5a5; }
.btn-danger:hover:not(:disabled) { background: #fecaca; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-teal { background: var(--teal-bg); color: var(--teal); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-gray { background: var(--gray-bg); color: var(--text2); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-blue { background: var(--accent-light); color: var(--accent); }

/* ── TABLE ── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { background: var(--surface2); padding: 10px 12px; text-align: left; font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 9px 12px; vertical-align: middle; }
.row-green { background: #f0fdf4 !important; }
.row-teal { background: #f0fdfa !important; }
.row-orange { background: #fff7ed !important; }
.row-red { background: #fff1f2 !important; }
.row-gray { background: #f9fafb !important; color: var(--text3); }
.row-amber { background: #fffbeb !important; }

/* ── FILTERS ── */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filter-bar select, .filter-bar input { padding: 7px 12px; border: 1.5px solid var(--border2); border-radius: var(--radius); font-size: 13px; font-family: inherit; background: white; outline: none; }
.filter-bar select:focus, .filter-bar input:focus { border-color: var(--accent); }
.filter-count { font-size: 12px; color: var(--text2); margin-left: auto; }

/* ── DISPATCH CHECKBOXES ── */
.dispatch-check { display: flex; align-items: center; gap: 8px; }
.dispatch-check input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.dispatch-stamp { font-size: 11px; color: var(--text2); }

/* ── TABS (class view) ── */
.class-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.class-tab { padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 600; cursor: pointer; background: var(--surface); border: 1.5px solid var(--border2); color: var(--text2); transition: all .15s; }
.class-tab.active { background: var(--accent); border-color: var(--accent); color: white; }
.class-tab:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

.fuzzy-hint { background: var(--amber-bg); border: 1px solid #fcd34d; border-radius: var(--radius); padding: 10px 14px; font-size: 13px; margin-bottom: 12px; }

/* ── MOBILE RESPONSIVE — Components ── */
@media (max-width: 768px) {
  /* Cards */
  .card { border-radius: 8px; margin-bottom: 12px; }
  .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 6px; }
  .card-body { padding: 12px 14px; }
  .card-title { font-size: 13px; }
  .card-sub { margin-left: 0; font-size: 11px; }

  /* Stat grid — 2 columns */
  .stat-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; margin-bottom: 12px; }
  .stat-n { font-size: 22px; }
  .stat-l { font-size: 11px; }
  .stat-card { padding: 12px 14px; }

  /* Filter bars — stack */
  .filter-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .filter-bar select, .filter-bar input { width: 100%; font-size: 16px; /* prevent iOS zoom */ }
  .filter-bar .btn { width: 100%; justify-content: center; }
  .filter-count { text-align: right; margin-left: 0; }

  /* Tables — horizontal scroll with touch */
  .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 480px; font-size: 12px; }
  thead th { padding: 8px 8px; font-size: 10px; }
  tbody td { padding: 9px 8px; }

  /* Buttons — bigger touch targets */
  .btn { font-size: 13px; padding: 10px 14px; min-height: 42px; }
  .btn-sm { font-size: 12px; padding: 7px 10px; min-height: 34px; }

  /* Class tabs — horizontal scroll, no wrap */
  .class-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap !important; padding-bottom: 4px; scrollbar-width: none; }
  .class-tabs::-webkit-scrollbar { display: none; }
  .class-tab { white-space: nowrap; padding: 8px 14px; font-size: 12px; }

  /* Grids in inline styles — single column */
  .card-body [style*="display:grid"],
  .card-body [style*="display: grid"] { grid-template-columns: 1fr !important; }

  /* Per-class breakdown — hide Skoop/Tuition columns, keep Class/Ready/Despatched/Remaining */
  #dash-class-table thead th:nth-child(2),
  #dash-class-table thead th:nth-child(3),
  #dash-class-table thead th:nth-child(4),
  #dash-class-tbody td:nth-child(2),
  #dash-class-tbody td:nth-child(3),
  #dash-class-tbody td:nth-child(4) { display: none; }
  #dash-class-table { min-width: unset; width: 100%; }

  /* Orders table — hide Match Method column */
  #orders-tbody td:nth-child(8),
  #orders-tbody ~ thead th:nth-child(8) { display: none; }

  /* Match modal suggestions — bigger Use buttons */
  #fuzzy-hint-box .btn { min-height: 40px; padding: 8px 14px; }

  /* Despatch page filters */
  #page-despatch .filter-bar { flex-direction: column; }
  #page-despatch .form-group { width: 100%; }

  /* Dispatch checkboxes — larger tap area */
  .dispatch-check input[type=checkbox] { width: 20px; height: 20px; }

  /* Avoid tiny inline font sizes breaking mobile */
  .badge { font-size: 10px; padding: 2px 6px; }

  /* Search results — better spacing on mobile */
  .search-result-item { padding: 12px; font-size: 13px; }
}
