/* ── Variables ───────────────────────────────────────────────────────────────── */
:root {
  --bg:          #060c1a;
  --bg-2:        #0a1020;
  --sidebar:     #0d1528;
  --surface:     #111827;
  --surface-2:   #1a2235;
  --surface-3:   #1f2b40;
  --border:      #1e2d45;
  --border-2:    #263550;
  --text:        #e8eeff;
  --text-muted:  #8896b4;
  --text-dim:    #4a5a78;
  --primary:     #6366f1;
  --primary-h:   #4f52d4;
  --primary-dim: #1a1c6e;
  --success:     #10b981;
  --success-dim: #032a20;
  --warning:     #f59e0b;
  --warning-dim: #1c1407;
  --error:       #ef4444;
  --error-dim:   #2a0808;
  --info:        #3b82f6;
  --info-dim:    #0a1f45;
  --sidebar-w:   230px;
  --bottom-nav-h: 60px;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,0.45);
  --touch-min:   44px;
}

/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-tap-highlight-color: transparent; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overscroll-behavior: none;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; }

/* ── App layout ──────────────────────────────────────────────────────────────── */
#app { min-height: 100vh; }

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  cursor: pointer;
  transition: opacity .15s;
}
.sidebar-brand:hover { opacity: .8; }
.brand-mark {
  width: 30px; height: 30px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff; flex-shrink: 0;
  letter-spacing: -0.5px;
}
.brand-name { font-weight: 700; font-size: 1rem; color: var(--text); }

.nav-section { padding: 14px 8px 8px; flex: 1; }
.nav-section-label {
  font-size: 0.63rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 10px;
  margin-bottom: 4px;
}
.nav-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
  min-height: 44px;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-dim); color: #a5b4fc; }
.nav-link svg { flex-shrink: 0; opacity: 0.75; }
.nav-link.active svg { opacity: 1; }
.nav-badge {
  margin-left: auto;
  background: var(--warning);
  color: #000;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.store-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.store-chip-icon {
  width: 24px; height: 24px;
  background: var(--primary-dim);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: #a5b4fc; flex-shrink: 0;
}
.store-chip-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-avatar {
  width: 30px; height: 30px;
  background: var(--surface-3);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 0.8rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.7rem; color: var(--text-dim); }
.sidebar-legal {
  margin-top: 10px;
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-dim); justify-content: center;
}
.sidebar-legal a { color: var(--text-dim); text-decoration: none; }
.sidebar-legal a:hover { color: var(--text-muted); }
.sidebar-legal span { opacity: .35; }
.btn-link {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); padding: 6px;
  border-radius: 6px; min-height: 32px; min-width: 32px;
  display: flex; align-items: center; justify-content: center;
}
.btn-link:hover { color: var(--error); background: var(--error-dim); }

/* ── Page area ───────────────────────────────────────────────────────────────── */
.page-area {
  background: var(--bg);
  overflow-y: auto;
  min-height: 100vh;
}

.page {
  max-width: 1050px;
  margin: 0 auto;
  padding: 28px 28px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title { font-size: 1.4rem; font-weight: 700; color: var(--text); line-height: 1.3; }
.page-subtitle { font-size: 0.875rem; color: var(--text-muted); margin-top: 3px; }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px;
  border: none; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: opacity 0.12s, background 0.12s, transform 0.1s;
  font-family: inherit; line-height: 1;
  min-height: var(--touch-min);
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn svg { flex-shrink: 0; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-outline { background: transparent; border: 1px solid var(--border-2); color: var(--text-muted); }
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--text); }
.btn-ghost  { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--error-dim); color: var(--error); border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover:not(:disabled) { background: var(--error); color: #fff; }
.btn-success { background: var(--success-dim); color: #34d399; border: 1px solid rgba(16,185,129,0.2); }
.btn-success:hover:not(:disabled) { background: var(--success); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 0.82rem; min-height: 36px; }
.btn-xs { padding: 5px 10px; font-size: 0.75rem; min-height: 30px; }
.btn-icon { padding: 10px; }

/* ── FAB (Floating Action Button) ────────────────────────────────────────────── */
.fab {
  display: none;
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + max(20px, env(safe-area-inset-bottom)) + 6px);
  right: 20px;
  width: 58px; height: 58px;
  background: var(--primary);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(99,102,241,0.6);
  color: #fff;
  align-items: center; justify-content: center;
  z-index: 90;
  transition: transform 0.15s, box-shadow 0.15s;
}
.fab:hover { transform: scale(1.07); box-shadow: 0 8px 28px rgba(99,102,241,0.75); }
.fab:active { transform: scale(0.93); }
.fab svg { width: 26px; height: 26px; }

/* ── Bottom navigation (mobile) ──────────────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--sidebar);
  border-top: 1px solid var(--border);
  z-index: 100;
  align-items: stretch;
}
.bottom-nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  padding: 5px 4px 4px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.6rem;
  font-weight: 600;
  border: none; background: none;
  position: relative;
  transition: color 0.12s;
  -webkit-tap-highlight-color: transparent;
  min-height: var(--touch-min);
  letter-spacing: 0.01em;
}
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item svg { width: 20px; height: 20px; }
.bottom-nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: var(--warning); color: #000;
  font-size: 0.55rem; font-weight: 700;
  padding: 0 4px; height: 14px; line-height: 14px;
  border-radius: 999px; min-width: 14px; text-align: center;
}

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card { margin-top: 14px; }
.card-title {
  font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-dim); margin-bottom: 16px;
}

/* ── Stat cards (dashboard) ──────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: default;
  transition: border-color 0.15s, background 0.15s;
}
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { border-color: var(--primary); background: var(--surface-2); }
.stat-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-sub   { font-size: 0.75rem; color: var(--text-dim); }

/* ── Section heading ─────────────────────────────────────────────────────────── */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.section-title { font-size: 0.9rem; font-weight: 700; color: var(--text); }

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  text-align: left; padding: 10px 14px;
  font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td.bold, .td-bold { color: var(--text); font-weight: 600; }
td.right, .text-right { text-align: right; }
.td-editable {
  cursor: pointer;
  position: relative;
}
.td-editable:hover {
  background: rgba(79, 142, 247, 0.08) !important;
  color: var(--text);
}
.td-editable:hover::after {
  content: ' ✎';
  font-size: 0.7em;
  opacity: 0.5;
  margin-left: 3px;
}
td code { font-family: "SFMono-Regular", Menlo, monospace; font-size: 0.8em; color: #7dd3fc;
  background: var(--bg-2); padding: 1px 5px; border-radius: 4px; }

/* ── Mobile stack table ── each row becomes a card ──────────────────────────── */
/* Applied to tables via .mobile-card-table class */

/* ── Invoice row cards ───────────────────────────────────────────────────────── */
.invoice-list { display: flex; flex-direction: column; gap: 10px; }
.invoice-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex; align-items: center; gap: 14px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  min-height: 64px;
}
.invoice-card:hover { border-color: var(--primary); background: var(--surface-2); }
.invoice-card:active { transform: scale(0.99); }
.invoice-card-main { flex: 1; min-width: 0; }
.invoice-card-title { font-weight: 600; color: var(--text); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.invoice-card-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }
.invoice-card-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.7rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  white-space: nowrap; letter-spacing: 0.02em;
}
.badge-green   { background: var(--success-dim); color: #34d399; }
.badge-amber   { background: var(--warning-dim); color: #fbbf24; }
.badge-red     { background: var(--error-dim);   color: #f87171; }
.badge-blue    { background: var(--info-dim);    color: #60a5fa; }
.badge-gray    { background: var(--surface-2);   color: var(--text-muted); }
.badge-purple  { background: var(--primary-dim); color: #a5b4fc; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
label, .field-label {
  font-size: 0.78rem; font-weight: 600; color: var(--text-muted);
}
.field-hint { font-size: 0.72rem; color: var(--text-dim); margin-top: -3px; }
input[type="text"], input[type="number"], input[type="email"], input[type="password"],
input[type="file"], select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
  min-height: var(--touch-min);
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
input[type="file"] { cursor: pointer; padding: 10px 12px; }
input[type="file"]::file-selector-button {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 5px;
  color: var(--text-muted); padding: 5px 12px; cursor: pointer; font-size: 0.82rem; margin-right: 10px;
}
input.font-mono { font-family: "SFMono-Regular", Menlo, monospace; font-size: 0.9em; }
.field-row { display: flex; gap: 8px; align-items: flex-end; }
.field-row .field { flex: 1; margin-bottom: 0; }
.field-row .btn { flex-shrink: 0; }

/* ── Upload source buttons ───────────────────────────────────────────────────── */
.upload-source-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
.upload-source-btn {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 24px 12px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem; font-weight: 600;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  font-family: inherit;
  min-height: 88px;
}
.upload-source-btn:hover { border-color: var(--primary); color: var(--text); background: var(--primary-dim); }
.upload-source-btn:active { transform: scale(0.97); }
.upload-source-btn svg { width: 26px; height: 26px; opacity: 0.7; }
.upload-source-btn:hover svg { opacity: 1; }

/* ── Login page ──────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: var(--bg);
  background-image: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99,102,241,0.1) 0%, transparent 60%);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 40px 16px 48px;
  overflow-y: auto;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 36px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow);
  margin: auto 0;
}
.login-brand {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 28px;
  text-decoration: none;
  cursor: pointer;
  transition: opacity .15s;
}
.login-brand:hover { opacity: .8; }
.login-brand .brand-mark { width: 34px; height: 34px; font-size: 15px; }
.login-brand .brand-name { font-size: 1.15rem; font-weight: 700; }
.login-title { font-size: 1.2rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.login-sub   { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 26px; }
.login-note  { font-size: 0.78rem; color: var(--text-dim); margin-top: 16px; text-align: center; }
.label-hint  { font-size: 0.75rem; color: var(--text-dim); font-weight: 400; }

/* Legal footer shown below auth cards (login, register, etc.) */
.auth-legal-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px;
}
.auth-legal-footer a { color: var(--text-dim); text-decoration: none; transition: color .15s; }
.auth-legal-footer a:hover { color: var(--text-muted); }
.auth-legal-dot { opacity: .4; }

/* Trial badge shown on the registration page */
.trial-badge {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(139,92,246,0.08));
  border: 1px solid rgba(99,102,241,0.3);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.84rem; font-weight: 600; color: var(--text);
  margin-bottom: 24px;
}
.trial-badge-icon { font-size: 1.1rem; flex-shrink: 0; }

.store-picker { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.store-option {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  min-height: 60px;
}
.store-option:hover { border-color: var(--primary); background: var(--surface-2); }
.store-option.selected { border-color: var(--primary); background: var(--primary-dim); }
.store-option-icon {
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--surface-3); display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-muted); flex-shrink: 0;
}
.store-option.selected .store-option-icon { background: var(--primary-dim); color: #a5b4fc; }
.store-option-name { font-weight: 700; color: var(--text); font-size: 0.9rem; }
.store-option-meta { font-size: 0.75rem; color: var(--text-muted); }

/* ── Timeline (invoice processing steps) ─────────────────────────────────────── */
.timeline { display: flex; gap: 0; margin: 20px 0; }
.timeline-step {
  display: flex; flex-direction: column; align-items: center; flex: 1; position: relative;
}
.timeline-step:not(:last-child)::after {
  content: '';
  position: absolute; top: 12px; left: 50%; right: -50%;
  height: 2px; background: var(--border); z-index: 0;
}
.timeline-step.done:not(:last-child)::after { background: var(--success); }
.timeline-dot {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-3); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; z-index: 1; margin-bottom: 6px;
}
.timeline-step.done   .timeline-dot { background: var(--success); border-color: var(--success); color: #fff; }
.timeline-step.active .timeline-dot { background: var(--info-dim); border-color: var(--info); color: var(--info); }
.timeline-step.failed .timeline-dot { background: var(--error-dim); border-color: var(--error); color: var(--error); }
.timeline-label { font-size: 0.7rem; color: var(--text-muted); text-align: center; white-space: nowrap; }
.timeline-step.done   .timeline-label { color: var(--success); }
.timeline-step.active .timeline-label { color: var(--info); }
.timeline-step.failed .timeline-label { color: var(--error); }

/* ── Pending item cards ──────────────────────────────────────────────────────── */
.pending-group { margin-bottom: 16px; }
.pending-group-header {
  font-size: 0.9rem; font-weight: 700; color: var(--text);
  margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.pending-group-meta { font-size: 0.78rem; color: var(--text-muted); font-weight: 400; margin-left: 6px; }
.pending-items-list { display: flex; flex-direction: column; gap: 10px; }
.pending-item-row {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.pending-item-row.warning-row {
  border-color: rgba(245,158,11,0.5);
  background: rgba(28,20,7,0.5);
}
.pending-item-name { font-weight: 700; color: var(--text); font-size: 0.95rem; margin-bottom: 4px; }
.pending-item-name.name-invalid { color: var(--warning); font-style: italic; }
.pending-item-warning {
  font-size: 0.78rem; color: #fcd34d; margin: 4px 0 10px;
  display: flex; align-items: center; gap: 6px;
}
.pending-item-keys {
  font-size: 0.75rem; color: var(--text-muted); margin: 6px 0 12px;
  display: flex; gap: 12px; flex-wrap: wrap;
}
.pending-item-keys code { color: var(--text); background: var(--bg-2); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 0.82em; }
.pending-item-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* Resolved item row */
.resolved-item-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px;
  background: var(--success-dim);
  border: 1px solid rgba(16,185,129,0.2);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}
.resolved-item-name { font-size: 0.9rem; color: #34d399; flex: 1; font-weight: 600; }
.resolved-item-upc  { font-family: monospace; font-size: 0.82rem; color: #34d399; }

/* Discarded item rows */
.discarded-item-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  opacity: 0.6;
}
.discarded-item-name { font-size: 0.875rem; color: var(--text-muted); flex: 1; text-decoration: line-through; }
.discarded-section {
  margin-top: 16px; padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.discarded-section-title {
  font-size: 0.68rem; font-weight: 700; color: var(--text-muted);
  letter-spacing: 0.07em; text-transform: uppercase; margin-bottom: 8px;
}

/* Scan / Discard / Clear-UPC buttons in pending rows */
.btn-scan, .btn-discard, .btn-clear-upc {
  padding: 8px 14px; min-height: 40px; gap: 6px;
  background: var(--surface-3); border: 1.5px solid var(--border-2); color: var(--text-muted);
  border-radius: var(--radius-sm); cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; font-size: 0.82rem; font-weight: 600;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  white-space: nowrap;
}
.btn-scan:hover     { border-color: var(--primary); color: var(--primary); }
.btn-discard:hover  { border-color: var(--error);   color: #f87171; }
.btn-clear-upc:hover { border-color: var(--warning); color: #fbbf24; }
.btn-scan svg, .btn-discard svg, .btn-clear-upc svg { width: 15px; height: 15px; }

/* ── Info grid ───────────────────────────────────────────────────────────────── */
.info-grid { display: flex; flex-direction: column; gap: 8px; }
.info-row {
  display: flex; align-items: baseline; gap: 12px;
  font-size: 0.875rem; min-width: 0;
}
.info-key {
  min-width: 140px; color: var(--text-muted); font-size: 0.8rem;
  flex-shrink: 0;
}
.info-val {
  color: var(--text); font-weight: 500;
  flex: 1; min-width: 0;
  /* Long values (filenames, IDs, URLs) must wrap instead of forcing
     horizontal overflow on narrow screens. */
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 560px) {
  /* Stack key + value on narrow screens so long filenames / object-storage
     IDs don't push the row past the card edge. */
  .info-row { flex-direction: column; gap: 2px; align-items: stretch; }
  .info-key { min-width: 0; }
}

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  border-left: 3px solid;
  margin-top: 10px;
  line-height: 1.5;
}
.alert-ok   { background: var(--success-dim); border-color: var(--success); color: #6ee7b7; }
.alert-warn { background: var(--warning-dim); border-color: var(--warning); color: #fcd34d; }
.alert-err  { background: var(--error-dim);   border-color: var(--error);   color: #fca5a5; }
.alert-info { background: var(--info-dim);    border-color: var(--info);    color: #93c5fd; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-backdrop.is-open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
}
.modal-backdrop.is-open .modal { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 1rem; padding: 6px 10px;
  border-radius: var(--radius-sm); min-height: var(--touch-min); min-width: var(--touch-min);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--surface-3); color: var(--text); }
.modal-body { padding: 22px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ── Centered confirm dialog ─────────────────────────────────────────────────── */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s;
  padding: 20px;
}
.confirm-overlay.is-open { opacity: 1; pointer-events: all; }
.confirm-dialog {
  background: var(--surface);
  border: 1px solid var(--border-2, var(--border));
  border-radius: 16px;
  width: 100%; max-width: 380px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55);
  transform: scale(0.93) translateY(10px);
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1), opacity 0.18s;
  opacity: 0;
}
.confirm-overlay.is-open .confirm-dialog { transform: scale(1) translateY(0); opacity: 1; }
.confirm-dialog-icon {
  display: flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary-dim, rgba(99,102,241,0.15));
  margin: 26px auto 0;
  font-size: 1.5rem;
}
.confirm-dialog-body { padding: 16px 24px 8px; text-align: center; }
.confirm-dialog-title { font-size: 1.05rem; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.confirm-dialog-msg { font-size: 0.875rem; color: var(--text-muted); line-height: 1.5; }
.confirm-dialog-actions {
  display: flex; gap: 10px; padding: 20px 24px 24px;
  flex-direction: column;
}
.confirm-dialog-actions .btn { width: 100%; justify-content: center; min-height: 48px; }

/* ── Camera scanner overlay ──────────────────────────────────────────────────── */
.scan-overlay {
  background: #000;
  width: 100%; height: 100%;
  max-width: 480px;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
}
.modal-backdrop.is-open .scan-overlay { transform: translateY(0); }
.scan-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  background: rgba(0,0,0,0.85);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: relative; z-index: 2;
}
.scan-title { color: #fff; font-size: 1rem; font-weight: 700; }
.scan-header .modal-close { color: rgba(255,255,255,0.8); }
.scan-video-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #111;
  min-height: 260px;
}
#scan-video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.scan-viewfinder {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.scan-corner {
  position: absolute;
  width: 34px; height: 34px;
  border-color: #6366f1;
  border-style: solid;
}
.scan-corner.tl { top: 20%; left: 10%; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.scan-corner.tr { top: 20%; right: 10%; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.scan-corner.bl { bottom: 20%; left: 10%; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.scan-corner.br { bottom: 20%; right: 10%; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }
.scan-line {
  position: absolute;
  left: 12%; right: 12%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #6366f1, transparent);
  top: 50%;
  animation: scan-sweep 2s ease-in-out infinite;
}
@keyframes scan-sweep {
  0%   { transform: translateY(-90px); opacity: 0.5; }
  50%  { opacity: 1; }
  100% { transform: translateY(90px); opacity: 0.5; }
}
.scan-status {
  padding: 12px 20px;
  background: rgba(0,0,0,0.85);
  color: rgba(255,255,255,0.75);
  font-size: 0.82rem;
  text-align: center;
}
.scan-manual {
  display: flex; gap: 8px; align-items: center;
  padding: 14px 16px;
  background: #111;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.scan-manual input {
  flex: 1; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
  color: #fff; border-radius: var(--radius-sm); padding: 11px 14px;
  font-size: 1rem; min-height: var(--touch-min);
}
.scan-manual input::placeholder { color: rgba(255,255,255,0.35); }
.scan-manual input:focus { outline: none; border-color: var(--primary); }

/* ── Divider ─────────────────────────────────────────────────────────────────── */
hr.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Empty / loading states ──────────────────────────────────────────────────── */
.empty-state {
  padding: 52px 24px;
  text-align: center;
  color: var(--text-dim);
}
.empty-state-icon { font-size: 2.8rem; margin-bottom: 14px; }
.empty-state-title { font-size: 1rem; font-weight: 700; color: var(--text-muted); margin-bottom: 8px; }
.empty-state-sub   { font-size: 0.875rem; color: var(--text-dim); }

.skeleton { background: var(--surface-2); border-radius: 6px; animation: pulse 1.4s ease-in-out infinite; }
.skeleton-line { height: 14px; margin-bottom: 8px; }
.skeleton-line:last-child { width: 60%; }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:0.4 } }
.loading-block { display: flex; flex-direction: column; gap: 12px; padding: 24px 0; }
.loading-row { display: flex; gap: 12px; }
.sk-w20  { width: 20%; }
.sk-w30  { width: 30%; }
.sk-w40  { width: 40%; }
.sk-w60  { width: 60%; }
.sk-w80  { width: 80%; }
.sk-w100 { width: 100%; }
.sk-h12 { height: 12px; border-radius: 4px; }
.sk-h18 { height: 18px; border-radius: 6px; }
.sk-h36 { height: 36px; border-radius: 10px; }

/* ── Billing / plan cards ────────────────────────────────────────────────────── */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color 0.15s;
}
.plan-card:hover { border-color: var(--border-2); }
.plan-name { font-weight: 800; font-size: 1rem; color: var(--text); }
.plan-price { font-size: 1.8rem; font-weight: 800; color: var(--text); line-height: 1; }
.plan-price sup { font-size: 0.9rem; vertical-align: top; margin-top: 5px; margin-right: 1px; }
.plan-price span { font-size: 0.85rem; color: var(--text-muted); font-weight: 400; }
.plan-limit { font-size: 0.82rem; color: var(--text-muted); font-weight: 500; }
.plan-overage { font-size: 0.75rem; color: var(--text-dim); margin-top: -2px; }
.plan-desc { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; flex: 1; }
.plan-current-badge { display: inline-block; font-size: 0.7rem; font-weight: 700; background: var(--primary-dim); color: #a5b4fc; padding: 3px 10px; border-radius: 999px; }
.plan-popular-badge {
  position: absolute; top: -1px; right: 14px;
  font-size: 0.63rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  background: var(--primary); color: #fff;
  padding: 3px 10px; border-radius: 0 0 8px 8px;
}
.plan-card.current { border-color: var(--primary); background: var(--surface-2); }

/* ── Info boxes (billing metric grid) ─────────────────────────────────────────── */
.info-box {
  background: var(--surface-2, var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.info-box-label { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; font-weight: 700; }
.info-box-value { font-size: 1.1rem; font-weight: 800; color: var(--text); }

/* ── Usage bar ───────────────────────────────────────────────────────────────── */
.usage-bar-wrap { margin: 10px 0; }
.usage-bar-label { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text-muted); margin-bottom: 6px; }
.usage-bar-track { height: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: 999px; transition: width 0.5s; background: var(--primary); }
.usage-bar-fill.warn { background: var(--warning); }
.usage-bar-fill.over { background: var(--error); }

/* ── Settings / Integrations page ───────────────────────────────────────────── */
.settings-tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.settings-tab {
  padding: 10px 18px;
  font-size: 0.875rem; font-weight: 600; color: var(--text-muted);
  cursor: pointer; border: none; background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px; font-family: inherit;
  transition: color 0.12s;
  min-height: var(--touch-min);
}
.settings-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.settings-tab:hover:not(.active) { color: var(--text); }

.integration-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex; gap: 20px; align-items: flex-start;
  margin-bottom: 16px;
  transition: border-color 0.15s;
}
.integration-card.connected { border-color: rgba(16,185,129,0.3); }
.integration-icon {
  width: 50px; height: 50px; flex-shrink: 0;
  border-radius: 12px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.integration-body { flex: 1; min-width: 0; }
.integration-name { font-weight: 700; font-size: 1rem; color: var(--text); margin-bottom: 5px; }
.integration-desc { font-size: 0.84rem; color: var(--text-muted); line-height: 1.55; margin-bottom: 14px; }
.integration-status { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.integration-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.spreadsheet-select {
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.spreadsheet-select-label { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 8px; }
.spreadsheet-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.spreadsheet-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 0.85rem; color: var(--text-muted);
  transition: border-color 0.12s, color 0.12s;
  min-height: var(--touch-min);
}
.spreadsheet-item:hover { border-color: var(--primary); color: var(--text); }
.spreadsheet-item.active { border-color: var(--success); color: var(--success); background: var(--success-dim); }
.spreadsheet-item-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spreadsheet-item-date { font-size: 0.72rem; color: var(--text-dim); flex-shrink: 0; }

.setup-steps {
  margin-top: 12px; padding: 16px;
  background: var(--bg-2); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.setup-step {
  display: flex; gap: 12px; align-items: flex-start;
  font-size: 0.82rem; color: var(--text-muted); padding: 6px 0;
}
.setup-step-num {
  width: 22px; height: 22px; flex-shrink: 0;
  background: var(--surface-3); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; color: var(--text-dim);
}
.setup-step code { background: var(--surface-3); padding: 1px 6px; border-radius: 4px; font-family: monospace; color: #7dd3fc; font-size: 0.9em; }

.integration-unconfigured {
  display: flex; gap: 12px; align-items: flex-start;
  margin-top: 12px; padding: 14px 16px;
  background: var(--bg-2); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.integration-unconfigured-icon { font-size: 1.3rem; flex-shrink: 0; padding-top: 1px; }
.integration-unconfigured-title { font-size: 0.875rem; font-weight: 700; color: var(--text-muted); margin-bottom: 5px; }
.integration-unconfigured-desc { font-size: 0.82rem; color: var(--text-dim); line-height: 1.5; margin-bottom: 5px; }
.integration-unconfigured-hint { font-size: 0.78rem; color: var(--text-dim); font-style: italic; }

/* ── Misc utilities ──────────────────────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); }
.text-dim    { color: var(--text-dim); }
.text-right  { text-align: right; }
.text-sm     { font-size: 0.82rem; }
.text-xs     { font-size: 0.75rem; }
.font-mono   { font-family: "SFMono-Regular", Menlo, monospace; }
.fw-600      { font-weight: 600; }
.gap-6       { gap: 6px; }
.gap-8       { gap: 8px; }
.mt-4        { margin-top: 4px; }
.mt-8        { margin-top: 8px; }
.mt-12       { margin-top: 12px; }
.mt-20       { margin-top: 20px; }
.flex        { display: flex; }
.items-center { align-items: center; }

/* ── Mobile topbar ───────────────────────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  min-height: 54px;
}
.hamburger {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 8px;
  border-radius: var(--radius-sm);
  min-height: var(--touch-min); min-width: var(--touch-min);
  display: flex; align-items: center; justify-content: center;
}
.hamburger:hover { background: var(--surface-2); color: var(--text); }
.topbar-brand-link {
  font-size: 1rem; font-weight: 700; color: var(--text);
  text-decoration: none; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; flex: 1; min-width: 0;
  cursor: pointer; transition: opacity .15s;
}
.topbar-brand-link:hover { opacity: .75; }

/* ── Recent invoices mobile cards (dashboard table → cards on mobile) ────────── */
.recent-invoice-card {
  display: none; /* shown only on mobile via media query */
}

/* ── Filter bar ──────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto;
  margin-bottom: 16px; padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-btn {
  white-space: nowrap; flex-shrink: 0;
  border-radius: 999px !important;
  padding: 7px 16px !important;
  font-size: 0.82rem !important;
  border: 1.5px solid var(--border) !important;
}
.filter-btn.active-filter {
  border-color: var(--primary) !important;
  background: var(--primary-dim) !important;
  color: #a5b4fc !important;
}

/* ─────────────────────────────────────────────────────────────────────────────── */
/* ── RESPONSIVE: ≤ 720px — Mobile First ──────────────────────────────────────── */
/* ─────────────────────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  html { font-size: 15px; }

  /* ── Layout ── */
  .app-layout { grid-template-columns: 1fr; }

  /* Sidebar becomes drawer */
  .sidebar {
    position: fixed; left: -105%; top: 0; height: 100vh;
    width: calc(var(--sidebar-w) + 20px); z-index: 200;
    transition: left 0.24s cubic-bezier(0.32,0.72,0,1);
    box-shadow: 4px 0 40px rgba(0,0,0,0.6);
  }
  .sidebar.open { left: 0; }

  /* Sidebar overlay when open */
  .sidebar.open::before {
    content: '';
    position: fixed;
    inset: 0;
    left: calc(var(--sidebar-w) + 20px);
    background: transparent;
  }

  /* Show mobile elements */
  .mobile-topbar { display: flex; }
  .bottom-nav    { display: flex; }
  .fab           { display: flex; }

  /* Content padding for bottom nav */
  .page-area { padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 80px); }
  .page { padding: 16px 16px; }

  /* ── Page header ── */
  .page-title { font-size: 1.25rem; }

  /* Hide desktop upload button in header (FAB handles it) */
  .page-actions .btn-primary { display: none; }

  /* ── Stat grid: 3 cols but smaller on mobile ── */
  .stat-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 18px;
  }
  .stat-card { padding: 14px 12px; gap: 4px; }
  .stat-label { font-size: 0.65rem; }
  .stat-value { font-size: 1.5rem; }
  .stat-sub   { font-size: 0.68rem; }

  /* ── Dashboard recent invoices: hide table, show cards ── */
  .dashboard-table-wrap { display: none; }
  .dashboard-mobile-list { display: flex; flex-direction: column; gap: 8px; }

  /* ── Invoice cards ── */
  .invoice-card { padding: 14px 14px; }
  .invoice-card-title { font-size: 0.88rem; }
  .invoice-card-meta  { font-size: 0.74rem; }
  .invoice-card-right { gap: 6px; }

  /* ── Plan grid: 1 column ── */
  .plan-grid { grid-template-columns: 1fr; }

  /* ── Invoice detail table → stacked cards ── */
  .mobile-card-table { border: none; }
  .mobile-card-table thead { display: none; }
  .mobile-card-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
  }
  .mobile-card-table tbody tr:hover td { background: transparent; }
  .mobile-card-table tbody td {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    border-right: none;
    color: var(--text);
    font-size: 0.85rem;
    text-align: left !important;
  }
  .mobile-card-table tbody td::before {
    content: attr(data-label);
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    font-weight: 700;
    margin-bottom: 3px;
    display: block;
  }
  /* Product name: spans full width */
  .mobile-card-table tbody td[data-label="Product"] {
    grid-column: 1 / -1;
    background: var(--surface-3);
    font-weight: 700;
    font-size: 0.9rem;
  }
  /* Action cell: spans full width */
  .mobile-card-table tbody td[data-label=""] {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
    border-bottom: none;
    padding: 8px 12px;
    background: var(--surface);
  }
  .mobile-card-table tbody td[data-label=""]::before { display: none; }
  .mobile-card-table tbody td:last-child { border-bottom: none; }

  /* ── Billing info boxes ── */
  .billing-info-grid { grid-template-columns: 1fr 1fr !important; }

  /* ── Invoice detail meta grid ── */
  .detail-meta-grid { grid-template-columns: 1fr !important; }

  /* ── Pending items ── */
  .pending-item-actions { gap: 8px; }
  .btn-scan, .btn-discard, .btn-clear-upc {
    padding: 10px 12px;
    min-height: 42px;
    font-size: 0.82rem;
  }
  .pending-item-row { padding: 14px 14px; }

  /* ── Integration card: stack ── */
  .integration-card { flex-direction: column; gap: 16px; }
  .integration-actions { flex-direction: column; }
  .integration-actions .btn { width: 100%; justify-content: center; min-height: 48px; }

  /* ── Login card ── */
  .login-page { padding: 24px 16px 40px; align-items: center; }
  .login-card { padding: 28px 22px; border-radius: var(--radius); }
  .login-title { font-size: 1.15rem; }
  .login-sub   { font-size: 0.85rem; margin-bottom: 22px; }

  /* ── Forms ── */
  .field-row { flex-direction: column; }
  .field-row .btn { width: 100%; justify-content: center; }

  /* ── Modal: full bottom sheet ── */
  .modal { border-radius: var(--radius) var(--radius) 0 0; }
  .scan-overlay { max-width: 100%; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; justify-content: center; min-height: 48px; }

  /* ── Upload buttons ── */
  .upload-source-btns { gap: 10px; }
  .upload-source-btn { padding: 22px 10px; font-size: 0.85rem; min-height: 96px; }

  /* ── Section head ── */
  .section-head { flex-wrap: wrap; gap: 8px; }

  /* ── Tables fallback: horizontal scroll ── */
  table { font-size: 0.78rem; }
  thead th, tbody td { padding: 9px 10px; }

  /* ── Settings tabs: scrollable ── */
  .settings-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .settings-tab { white-space: nowrap; }
}

/* ── 480px and below ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .stat-card { padding: 12px 8px; }
  .stat-label { font-size: 0.6rem; }
  .stat-value { font-size: 1.35rem; }

  /* Bottom nav labels */
  .bottom-nav-item { font-size: 0.57rem; }
  .bottom-nav-item svg { width: 19px; height: 19px; }

  .fab { width: 54px; height: 54px; right: 14px; }
  .fab svg { width: 22px; height: 22px; }

  .page { padding: 14px 12px; }
  .page-title { font-size: 1.15rem; }

  .invoice-card { padding: 12px 12px; }
}

/* ── 360px and below ─────────────────────────────────────────────────────────── */
@media (max-width: 360px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .stat-value { font-size: 1.2rem; }
  .mobile-card-table tbody tr { grid-template-columns: 1fr; }
  .mobile-card-table tbody td[data-label="Product"] { grid-column: 1; }
  .mobile-card-table tbody td[data-label=""] { grid-column: 1; }
}

/* ── Desktop: hide mobile-only elements ──────────────────────────────────────── */
@media (min-width: 721px) {
  .mobile-topbar, .hamburger { display: none; }
  .bottom-nav { display: none; }
  .fab { display: none; }
  .dashboard-mobile-list { display: none !important; }
  .dashboard-table-wrap { display: block; }
}

/* ════════════════════════════════════════════════════════════════════════════
 * Sales CRM (Phase 1)
 * ════════════════════════════════════════════════════════════════════════════ */

.page-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

/* Filter chips */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border: 1px solid var(--border, #2a2f3a);
  background: transparent;
  color: var(--text, #d8dce6);
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { background: rgba(255,255,255,0.04); }
.chip-active {
  background: var(--accent, #4f7cff);
  border-color: var(--accent, #4f7cff);
  color: #fff;
}
.filter-row { font-size: 0.85rem; }
.filter-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-right: 4px;
  align-self: center;
}

/* Tabs */
.tab-strip {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border, #2a2f3a);
  margin-bottom: 14px;
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent, #4f7cff);
  border-bottom-color: var(--accent, #4f7cff);
}
.tab-badge {
  display: inline-block;
  background: var(--accent, #4f7cff);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.7rem;
  margin-left: 4px;
}

/* Key/value rows for detail panels */
.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 0.9rem;
}
.kv-row:last-child { border-bottom: none; }
.kv-label {
  color: var(--text-muted);
  font-size: 0.82rem;
  flex-shrink: 0;
  min-width: 110px;
}
.kv-value {
  color: var(--text);
  text-align: right;
  word-break: break-word;
}
.kv-value a { color: var(--accent, #4f7cff); text-decoration: none; }
.kv-value a:hover { text-decoration: underline; }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Table cells */
.cell-strong { font-weight: 600; color: var(--text); }
.cell-sub    { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.row-clickable { cursor: pointer; }
.row-clickable:hover { background: rgba(255,255,255,0.03); }

/* Sales table → cards on mobile */
.sales-cards { display: none; }
@media (max-width: 720px) {
  .sales-table { display: none; }
  .sales-cards { display: block; }
  .sales-card-row {
    padding: 12px;
    border-bottom: 1px solid var(--border, #2a2f3a);
    cursor: pointer;
  }
  .sales-card-row:last-child { border-bottom: none; }
  .sales-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
  }
  .sales-card-body { font-size: 0.85rem; color: var(--text); }
}

/* Notes */
.note-row {
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.note-row:last-child { border-bottom: none; }
.note-meta { font-size: 0.78rem; color: var(--text-muted); }
.note-body { font-size: 0.92rem; color: var(--text); line-height: 1.5; }

/* Aliases (some places use shorter empty-* class names) */
.empty-title { font-size: 1rem; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }
.empty-sub   { font-size: 0.875rem; color: var(--text-dim, var(--text-muted)); }

/* Small input variant */
.input-sm { padding: 6px 10px; font-size: 0.85rem; }

/* Margin utility used in alerts */
.mt-8 { margin-top: 8px; }

/* Card title (used in detail panels) */
.card .card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

/* ── CRM Phase 2 ───────────────────────────────────────────────────────────── */

/* Sub-nav link (Sales > Clients/Tasks) */
.nav-sub { padding-left: 28px; font-size: 0.82rem; }

/* 4-column stat grid for sales dashboard */
.stat-grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 720px) {
  .stat-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* Pipeline stepper */
.pipeline-card { padding: 16px 18px; }
.pipeline-row {
  display: flex; align-items: center;
  flex-wrap: wrap; gap: 6px;
  overflow-x: auto;
}
.pipe-step {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px; padding: 6px 12px;
  cursor: pointer; font-size: 0.78rem; font-weight: 600;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
  font-family: inherit;
}
.pipe-step:hover { background: var(--primary-dim); color: var(--text); border-color: var(--primary); }
.pipe-step .pipe-dot {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-3); font-size: 0.68rem; font-weight: 700;
}
.pipe-done   { background: var(--success-dim); color: #34d399; border-color: rgba(52,211,153,0.3); }
.pipe-done .pipe-dot   { background: var(--success); color: #fff; }
.pipe-current { background: var(--primary-dim); color: #a5b4fc; border-color: var(--primary); }
.pipe-current .pipe-dot { background: var(--primary); color: #fff; }
.pipe-arrow { color: var(--text-dim); font-size: 1.1rem; flex-shrink: 0; }
.pipeline-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* CRM activity timeline (renamed from .timeline to avoid colliding with the
   horizontal invoice-processing .timeline defined earlier in this file). */
.crm-timeline { display: flex; flex-direction: column; gap: 14px; }
.tl-row {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.tl-row:last-child { border-bottom: none; }
.tl-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  background: var(--surface-2); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.tl-body { flex: 1; min-width: 0; }
.tl-line { font-size: 0.88rem; color: var(--text); }
.tl-summary {
  font-size: 0.85rem; color: var(--text-muted);
  margin-top: 4px; padding: 8px 10px;
  background: var(--surface-2); border-radius: 6px;
  white-space: pre-wrap;
}
.tl-time { font-size: 0.72rem; color: var(--text-dim); margin-top: 4px; }

/* Tasks */
.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color 0.12s, background 0.12s;
}
.task-row:hover { border-color: var(--primary); }
.task-row.task-overdue { border-left: 3px solid var(--error); background: rgba(239,68,68,0.04); }
.task-row.task-done    { opacity: 0.6; }
.task-row.task-done .task-title { text-decoration: line-through; }
.task-main { flex: 1; min-width: 0; }
.task-title { font-weight: 600; color: var(--text); font-size: 0.9rem; }
.task-meta  { font-size: 0.77rem; color: var(--text-muted); margin-top: 4px; }
.task-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }

/* Chip row for follow-up presets */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Trial expiration banner ──────────────────────────────────────────── */
.trial-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  font-size: 0.92rem;
  font-weight: 500;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  flex-wrap: wrap;
}
.trial-banner.banner-warn   { background: #fff4d6; color: #6b4b00; }
.trial-banner.banner-danger { background: #ffe1e1; color: #8a1c1c; }
.trial-banner-text { flex: 1; min-width: 200px; }
.trial-banner-cta {
  background: #1e1e2e;
  color: #fff !important;
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
}
.trial-banner-cta:hover { background: #6c63ff; }
@media (max-width: 560px) {
  .trial-banner { padding: 10px 14px; font-size: 0.86rem; }
}

/* ── Pending UPCs page: detected-UPC suggestion row ─────────────────────── */
.suggested-upc-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: rgba(79, 142, 247, 0.08);
  border: 1px solid rgba(79, 142, 247, 0.35);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
}
.suggested-upc-label {
  font-size: 12px;
  color: var(--text-muted, #9ca3af);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.suggested-upc-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text, #f3f4f6);
  letter-spacing: 0.02em;
}
.suggested-upc-row .btn { margin-left: auto; }

/* ── Legacy (unused) styles kept to avoid CSS-load 404s ─────────────────── */
.upc-detected {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  margin-bottom: 6px;
  background: var(--surface-2, rgba(255, 165, 0, 0.06));
  border-left: 3px solid var(--warning, #f59e0b);
  border-radius: 4px;
}
.upc-detected-empty {
  background: transparent;
  border-left-color: var(--border, #2a3142);
}
.upc-detected-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.upc-detected-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}
.upc-value-empty {
  color: var(--text-muted);
  font-style: italic;
}
.upc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.upc-actions .btn {
  flex: 0 1 auto;
}
.upc-clickable {
  cursor: pointer;
  border-bottom: 1px dashed var(--border, #2a3142);
}
.upc-flash-success {
  background: rgba(52, 211, 153, 0.18);
  transition: background 0.6s ease;
}

/* On narrow screens stack the action buttons full-width so they're tappable */
@media (max-width: 640px) {
  .upc-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .upc-actions .btn {
    width: 100%;
    text-align: center;
  }
}

/* ── Inline toast (used by UPC actions and clipboard helpers) ───────────── */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  color: #fff;
  background: var(--surface-3, #1f2533);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 90vw;
}
.toast-show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success, #16a34a); }
.toast-error   { background: var(--error,   #dc2626); }
.toast-info    { background: var(--surface-3, #1f2533); }
