* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e6e8f0;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-soft: #eef2ff;
  --primary-grad: linear-gradient(135deg, #6366f1, #8b5cf6);
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 4px 6px rgba(16, 24, 40, .05), 0 12px 28px rgba(16, 24, 40, .10);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); }

/* ===== SVG Icon system ===== */
.icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-block; vertical-align: middle; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }

/* ===== App shell ===== */
.app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: 252px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #0f172a 0%, #171331 55%, #1e1b4b 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px 14px;
  gap: 4px;
  border-right: 1px solid rgba(255,255,255,.04);
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  text-decoration: none;
  padding: 4px 10px 18px;
  letter-spacing: .02em;
}
.sidebar .brand .logo {
  width: 36px; height: 36px;
  border-radius: 11px;
  background: var(--primary-grad);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(99, 102, 241, .5);
  color: #fff;
}
.sidebar .brand .logo .icon { width: 20px; height: 20px; color: #fff; }
.side-links { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-group { margin-bottom: 6px; }
.nav-group-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #64748b;
  padding: 12px 10px 6px;
  font-weight: 700;
}
.side-links a {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #cbd5e1;
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.side-links a .icon { color: #94a3b8; transition: color .15s ease; }
.side-links a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.side-links a:hover .icon { color: #e0e7ff; }
.side-links a.active {
  background: var(--primary-grad);
  color: #fff;
  box-shadow: 0 6px 18px rgba(99, 102, 241, .45);
}
.side-links a.active .icon { color: #fff; }
.side-foot { padding-top: 8px; border-top: 1px solid rgba(255,255,255,.08); margin-top: 8px; }
.side-foot a {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #94a3b8;
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}
.side-foot a .icon { color: #94a3b8; }
.side-foot a:hover { color: #fecaca; background: rgba(239, 68, 68, .1); }
.side-foot a:hover .icon { color: #fca5a5; }

.content {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 26px 36px 48px;
}

/* ===== Generic main (login/setup) ===== */
main { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
main.center-card { max-width: 420px; margin: 8vh auto; }

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0 18px;
  margin: 0 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar-title { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.crumb-root { color: var(--muted); font-weight: 600; }
.crumb-sep { color: #cbd5e1; }
.crumb-here { font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.admin-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-soft);
  color: #4338ca;
  border: 1px solid #c7d2fe;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.admin-chip .icon { width: 14px; height: 14px; }
.wa-mini {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.wa-mini .icon { width: 12px; height: 12px; }
.wa-mini-connected { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.wa-mini-connecting { background: #fef9c3; color: #a16207; border-color: #fde68a; }
.wa-mini-pairing { background: #ede9fe; color: #6d28d9; border-color: #ddd6fe; }
.wa-mini-disconnected { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }

/* ===== Hamburger ===== */
.hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.hamburger:hover { background: #f1f5f9; }
.hamburger .icon { width: 20px; height: 20px; }
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  z-index: 199;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.sidebar-overlay.open { display: block; }

/* ===== Cards ===== */
.card, .sub-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.sub-card { box-shadow: none; background: #fafbfe; }
h1, h2 { font-size: 18px; margin-bottom: 14px; font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--text); font-weight: 700; }

/* ===== Form ===== */
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: #334155; }
input, select, textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid #d5dbe7;
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #fff;
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
  font-family: inherit;
}
input:hover, select:hover, textarea:hover { border-color: #b9c2d2; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .16);
}
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--primary); margin-right: 8px; cursor: pointer; }
label.check { font-weight: 500; display: flex; align-items: center; gap: 2px; cursor: pointer; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 12px; margin: 4px 0 10px; }
.check-grid label.check { font-weight: 400; font-size: 13.5px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid #d5dbe7;
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform .05s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn .icon { width: 15px; height: 15px; }
.btn:hover { background: #f1f5f9; border-color: #b9c2d2; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary-grad); border: none; color: #fff; box-shadow: 0 4px 14px rgba(99, 102, 241, .35); }
.btn.primary .icon { color: #fff; }
.btn.primary:hover { box-shadow: 0 6px 20px rgba(99, 102, 241, .5); background: var(--primary-grad); }
.btn.danger { background: #ef4444; border-color: #ef4444; color: #fff; }
.btn.danger .icon { color: #fff; }
.btn.danger:hover { background: #dc2626; }
.btn.small { padding: 6px 12px; font-size: 12px; border-radius: 9px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .65; cursor: not-allowed; }
.btn.loading { pointer-events: none; }
.btn.loading::before {
  content: '';
  width: 13px; height: 13px;
  border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: spin .7s linear infinite;
}
.btn.loading.danger::before { border-color: rgba(255,255,255,.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; max-height: 72vh; overflow-y: auto; border-radius: 12px; border: 1px solid var(--border); }
.table-wrap thead th { position: sticky; top: 0; z-index: 1; }
.table-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
  background: #f8fafc;
}
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #f6f7ff; }
tbody tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

/* ===== Forms inside table cells ===== */
td .row-filter { gap: 4px; }
td .row-filter input,
td .row-filter select { width: auto; min-width: 0; flex: 1 1 auto; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #e2e8f0;
  color: #334155;
}
.badge .icon { width: 12px; height: 12px; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-awaiting_payment { background: #fef9c3; color: #a16207; }
.badge-paid { background: #dbeafe; color: #1d4ed8; }
.badge-processing { background: #ede9fe; color: #6d28d9; }
.badge-failed, .badge-cancelled, .badge-expired { background: #fee2e2; color: #b91c1c; }
.badge-agen { background: #ede9fe; color: #6d28d9; }

/* ===== Stats ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow .2s ease, transform .2s ease;
}
.stat:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.stat .ico {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat .ico .icon { width: 20px; height: 20px; }
.stat:nth-child(1) .ico { background: #ede9fe; color: #6d28d9; }
.stat:nth-child(2) .ico { background: #dcfce7; color: #15803d; }
.stat:nth-child(3) .ico { background: #dbeafe; color: #1d4ed8; }
.stat:nth-child(4) .ico { background: #fef9c3; color: #a16207; }
.stat:nth-child(5) .ico { background: #fee2e2; color: #b91c1c; }
.stat:nth-child(6) .ico { background: #e0f2fe; color: #0369a1; }
.stat:nth-child(7) .ico { background: #fce7f3; color: #be185d; }
.stat .txt span { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.stat .txt b { font-size: 21px; letter-spacing: -.01em; }

/* ===== Report stat cards ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin: 18px 0 4px; }
.stat-card {
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.stat-value { font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.stat-good .stat-value { color: #16a34a; }
.stat-bad .stat-value { color: #dc2626; }

/* ===== Utility ===== */
.actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.actions-col { display: flex; gap: 6px; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-filter { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; align-items: center; }
.row-filter input { flex: 1; min-width: 180px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.error { color: var(--danger); margin-bottom: 10px; font-size: 14px; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 11px; }
.alert.success { background: #dcfce7; color: #15803d; padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.alert.danger { background: #fee2e2; color: #b91c1c; padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ===== Filter chips ===== */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  background: #fff;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary-grad); color: #fff; border-color: transparent; box-shadow: 0 3px 10px rgba(99,102,241,.3); }

/* ===== WhatsApp page ===== */
#qr-box img { max-width: 260px; border-radius: 12px; border: 1px solid var(--border); background: #fff; }
#qr-box .qr-empty {
  display: flex; align-items: center; justify-content: center;
  min-height: 200px; border: 2px dashed #d1d9e6; border-radius: 12px;
  color: var(--muted); font-size: 13px; text-align: center; padding: 12px;
}
#pairing-result { margin-top: 10px; font-weight: 600; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.status-pill .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.status-pill.connected .dot { background: var(--success); box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.2); }
.status-pill.connecting .dot { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2); animation: pulse 1.4s infinite; }
.status-pill.disconnected .dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2); }
.status-pill.pairing .dot { background: #8b5cf6; box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.2); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ===== Log ===== */
.log-box {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 12px;
  max-height: 62vh;
  overflow-y: auto;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.log-box::-webkit-scrollbar { width: 8px; }
.log-box::-webkit-scrollbar-thumb { background: #334155; border-radius: 8px; }
.log-line { padding: 3px 0; border-bottom: 1px solid #1e293b; white-space: pre-wrap; word-break: break-word; }
.log-time { color: #64748b; margin-right: 8px; }
.log-error { color: #fca5a5; }
.log-warn { color: #fcd34d; }

/* ===== Diagnostics ===== */
.diag-box { display: none; margin-top: 16px; }
.diag-box.open { display: block; }
.diag-msg { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 13px; font-weight: 500; }
.diag-msg.ok { background: #dcfce7; color: #15803d; }
.diag-msg.err { background: #fee2e2; color: #b91c1c; }
.diag-meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.diag-meta code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; }

/* ===== Login / Setup ===== */
.center-card .card { padding: 32px 30px; box-shadow: var(--shadow-lg); }
.center-card h1 { text-align: center; }
.center-card .brand-logo {
  width: 52px; height: 52px; margin: 0 auto 14px;
  border-radius: 14px;
  background: var(--primary-grad);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
  color: #fff;
}
.center-card .brand-logo .icon { width: 24px; height: 24px; color: #fff; }
.center-card form { margin-top: 6px; }
.center-card .btn { width: 100%; margin-top: 16px; }

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: 20px 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 32px;
}
.app-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }
.app-footer a:hover { text-decoration: underline; }

/* ===== Toast ===== */
.toast-box {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  background: #1e293b;
  color: #f1f5f9;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.3);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .25s ease, transform .25s ease;
  border-left: 4px solid var(--primary);
  word-break: break-word;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: #22c55e; }
.toast-error { border-left-color: #ef4444; }
.toast-warn { border-left-color: #f59e0b; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  border: 2px dashed #d1d9e6;
  border-radius: 14px;
  color: var(--muted);
}
.empty-state p { margin-bottom: 4px; }
.empty-state .muted { font-size: 12px; }

/* ===== Steps list (agent how-to) ===== */
ol.steps { padding-left: 20px; margin: 8px 0; }
ol.steps li { margin-bottom: 6px; font-size: 13px; line-height: 1.6; color: #475569; }
ol.steps li strong { color: var(--text); }

/* ===== AI price section ===== */
.ai-section h2 { display: flex; align-items: center; gap: 8px; }
.ai-section h2 .icon { color: var(--primary); }

/* ===== Status API Key Groq (multi-key) ===== */
.key-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-normal { background: #16a34a; }
.dot-near { background: #f59e0b; }
.dot-limited { background: #dc2626; }
.dot-unknown { background: #94a3b8; }

/* ===== Responsive: Tablet ===== */
@media (max-width: 1024px) {
  .content { padding: 22px 20px 48px; }
  .sidebar { width: 230px; }
}

/* ===== Responsive: Mobile (drawer + stacked layout) ===== */
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    position: fixed; top: 0; left: 0;
    width: 280px; max-width: 84vw; height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    padding: 18px 14px;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: inline-flex; }
  .content { padding: 14px 14px 48px; min-width: 0; overflow-x: hidden; }

  .topbar { margin: 0 0 18px; padding: 8px 0 14px; }
  .crumb-root, .crumb-sep { display: none; }
  .crumb-here { font-size: 15px; }
  .admin-chip { font-size: 11px; padding: 5px 10px; }
  .wa-mini { font-size: 11px; padding: 5px 10px; }

  .card, .sub-card { padding: 18px; border-radius: 14px; margin-bottom: 16px; }
  h1, h2 { font-size: 16px; margin-bottom: 12px; }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
  .stat { padding: 14px; gap: 10px; border-radius: 14px; }
  .stat .ico { width: 36px; height: 36px; border-radius: 11px; }
  .stat .ico .icon { width: 18px; height: 18px; }
  .stat .txt span { font-size: 11px; }
  .stat .txt b { font-size: 17px; }

  .grid-2 { grid-template-columns: 1fr; }

  .row-between { flex-direction: column; align-items: flex-start; gap: 10px; }
  .row-filter { flex-direction: column; gap: 8px; align-items: stretch; }
  .row-filter input { min-width: 0; width: 100%; }
  .row-filter select { width: 100%; }
  .row-filter .btn { width: 100%; }

  input, select, textarea { font-size: 16px; padding: 10px 12px; }
  label { font-size: 12px; margin: 12px 0 5px; }

  .actions { gap: 8px; }
  .actions .btn { flex: 1; }
  .actions-col { gap: 6px; flex-wrap: wrap; }
  .actions-col .btn { flex: 1; }

  .toast-box { top: 8px; right: 8px; left: 8px; max-width: none; }
  .toast { font-size: 12px; padding: 10px 14px; border-radius: 10px; }

  .log-box { font-size: 11px; padding: 10px; max-height: 55vh; }

  main.center-card { margin: 4vh auto; }
  .center-card .card { padding: 24px 20px; }

  .ai-section .row-filter { flex-direction: column; }
  .ai-section .row-filter > div { min-width: 0; width: 100%; }

  .receipt-preview img { max-width: 280px !important; }

  .chip { font-size: 11px; padding: 5px 10px; }
  .empty-state { padding: 28px 16px; }
  .diag-box { overflow-x: auto; }

  .table-wrap { max-height: none; }
  .table-wrap th, .table-wrap td { white-space: nowrap; }
}

/* ===== Responsive: Small phone — tables become cards ===== */
@media (max-width: 640px) {
  .card-table { overflow: visible; max-height: none; border: none; }
  .card-table table,
  .card-table thead,
  .card-table tbody,
  .card-table tr,
  .card-table td { display: block; width: 100%; }
  .card-table thead { display: none; }
  .card-table tr {
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 12px;
    padding: 6px 14px;
    background: #fff;
    box-shadow: var(--shadow);
  }
  .card-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #f1f5f9;
    padding: 9px 0;
    white-space: normal;
    text-align: right;
  }
  .card-table td:last-child { border-bottom: none; }
  .card-table td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    text-align: left;
    flex-shrink: 0;
  }
  .card-table td[data-no-label]::before { display: none; }
  .card-table td .muted { display: block; }
  .card-table td form { width: 100%; }
  .card-table td input, .card-table td select { max-width: 60%; font-size: 14px; }
  .card-table td:has(form) { flex-direction: column; align-items: stretch; text-align: left; }
  .card-table td:has(form)::before { margin-bottom: 2px; }
  .card-table td:has(form) form { width: 100%; }
  .card-table td:has(form) form.row-filter { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .card-table td:has(form) form.row-filter input,
  .card-table td:has(form) form.row-filter select { max-width: none; flex: 1 1 130px; width: auto; }
  .card-table .actions-col { justify-content: flex-end; }
}

/* ===== Responsive: Very small phone ===== */
@media (max-width: 400px) {
  .content { padding: 12px 10px 40px; }
  .card, .sub-card { padding: 14px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 12px; gap: 8px; }
  .stat .ico { width: 32px; height: 32px; }
  .stat .ico .icon { width: 16px; height: 16px; }
  .stat .txt b { font-size: 15px; }
  .stat .txt span { font-size: 10px; }

  .admin-chip { font-size: 0; padding: 5px 8px; }
  .admin-chip .icon { width: 16px; height: 16px; }
  .wa-mini { font-size: 0; padding: 5px 8px; }
  .wa-mini b { font-size: 0; }
  .wa-mini .dot { width: 8px; height: 8px; }
}
/* ===== Chip checkbox (toolbar "Sesuaikan harga") ===== */
.chip-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 999px;
  background: #f8fafc;
  font-size: 12px;
  color: var(--muted, #64748b);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.chip-check input { accent-color: var(--primary, #6366f1); margin: 0; }
.chip-check:has(input:checked) {
  border-color: var(--primary, #6366f1);
  background: rgba(99, 102, 241, 0.08);
  color: var(--primary, #6366f1);
}
