:root {
  --primary: #1a6dff;
  --primary-hover: #0b5cd5;
  --primary-soft: #eef4ff;
  --success: #0d9f6e;
  --success-soft: #e6f9f1;
  --warning: #ca8a04;
  --warning-soft: #fef9e7;
  --error: #dc2626;
  --error-soft: #fef2f2;
  --grey: #64748b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.05);
  --shadow: 0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 16px rgba(15,23,42,0.08);
  --shadow-lg: 0 12px 40px rgba(15,23,42,0.12);
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Consolas', monospace;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ========== Auth Screen ========== */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(26,109,255,0.08), transparent),
    radial-gradient(ellipse 60% 50% at 80% 100%, rgba(13,159,110,0.06), transparent),
    var(--bg);
}

.auth-card {
  position: relative;
  background: var(--card);
  border-radius: 16px;
  padding: 48px 40px 40px;
  box-shadow: var(--shadow-lg);
  width: 420px;
  max-width: 92vw;
  text-align: center;
  border: 1px solid var(--border);
  animation: authIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes authIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-logo {
  color: var(--primary);
  margin-bottom: 20px;
}

.auth-card h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.auth-card p {
  color: var(--text-secondary);
  margin-bottom: 28px;
  font-size: 15px;
}

.auth-card .input-group {
  display: flex;
  gap: 8px;
}

.input-icon-wrap {
  position: relative;
  flex: 1;
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.input-icon-wrap input {
  padding-left: 36px !important;
}

/* ========== App Layout ========== */
#app { display: none; }

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

header .header-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 60px;
  gap: 32px;
}

/* ========== Logo ========== */
header .logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  text-decoration: none;
  letter-spacing: -0.3px;
  transition: color var(--transition);
}

header .logo:hover {
  color: var(--primary);
}

.logo-icon {
  color: var(--primary);
  flex-shrink: 0;
}

/* ========== Navigation ========== */
nav {
  display: flex;
  gap: 2px;
  flex: 1;
}

nav a {
  text-decoration: none;
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

nav a svg {
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity var(--transition);
}

nav a:hover {
  background: var(--bg);
  color: var(--text);
}

nav a:hover svg { opacity: 0.8; }

nav a.active {
  background: var(--primary);
  color: #fff;
}

nav a.active svg { opacity: 1; }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
}

.btn-logout:hover {
  background: var(--error-soft);
  border-color: var(--error);
  color: var(--error);
}

/* ========== Main Content ========== */
main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px;
}

section { display: none; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.section-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

/* ========== Stats Bar ========== */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border);
  transition: background var(--transition);
}

.stat-card:first-child::before { background: var(--primary); }
.stat-card:nth-child(2)::before { background: var(--success); }
.stat-card:nth-child(3)::before { background: var(--warning); }
.stat-card:nth-child(4)::before { background: var(--error); }

.stat-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--border-hover);
}

.stat-card .stat-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -1px;
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  font-weight: 500;
}

/* ========== Filters ========== */
.filters {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text-secondary);
  font-weight: 500;
  transition: all var(--transition);
}

.filter-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ========== Tables ========== */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background var(--transition);
}

tbody tr:hover { background: #f8fafc; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--primary-soft); }

/* ========== Badges ========== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.1px;
}

.badge-new { background: #f1f5f9; color: #475569; }
.badge-processed { background: var(--primary-soft); color: #1e40af; }
.badge-sent { background: var(--success-soft); color: #065f46; }
.badge-error { background: var(--error-soft); color: #991b1b; }
.badge-processing { background: var(--warning-soft); color: #92400e; }
.badge-confidence-high { background: var(--success-soft); color: #065f46; }
.badge-confidence-medium { background: var(--warning-soft); color: #92400e; }
.badge-confidence-low { background: var(--error-soft); color: #991b1b; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(26,109,255,0.3);
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 2px 8px rgba(26,109,255,0.35);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #0b8a5e; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-outline {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover {
  background: var(--bg);
  border-color: var(--border-hover);
}

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* Inline delete icon button for table rows */
.btn-icon-danger {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted, #94a3b8);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  padding: 0;
}
.btn-icon-danger:hover {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
  transform: scale(1.05);
}
.btn-icon-danger:active { transform: scale(0.95); }

/* Generic (non-destructive) inline icon button — used for edit actions */
.btn-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted, #94a3b8);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  padding: 0;
}
.btn-icon:hover {
  background: var(--primary, #3b82f6);
  color: #fff;
  border-color: var(--primary, #3b82f6);
  transform: scale(1.05);
}
.btn-icon:active { transform: scale(0.95); }

/* Pack-size badge — tiny inline label next to a mapping variant name */
.pack-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  background: #eef2ff;
  color: #4338ca;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  vertical-align: middle;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

/* ========== Forms ========== */
input[type="text"], input[type="password"], input[type="url"], select, textarea {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: all var(--transition);
  background: var(--card);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,109,255,0.1);
}

input::placeholder { color: var(--text-tertiary); }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group { margin-bottom: 18px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

/* ========== Cards ========== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-header h2 { font-size: 18px; }

/* ========== Invoice Detail ========== */
.invoice-header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.invoice-field .field-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.invoice-field .field-value {
  font-size: 16px;
  font-weight: 600;
  margin-top: 5px;
  color: var(--text);
}

.invoice-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

/* ========== OCR Text ========== */
details { margin-top: 20px; }

details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 10px 0;
  font-size: 14px;
  display: flex;
  align-items: center;
  transition: color var(--transition);
}

details summary:hover { color: var(--text); }

details[open] summary { margin-bottom: 12px; }

.ocr-text {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
  line-height: 1.7;
  color: var(--text-secondary);
}

/* ========== Upload / Drop Zone ========== */
/* ========== Upload page (carousel style) ========== */

.upload-card { padding: 24px; }

.upload-top-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}
.upload-btn-pick {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: 24px;
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.upload-btn-pick:hover { background: #2563eb; }
.upload-btn-clear {
  background: #fecdd3;
  color: #be123c;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: 24px;
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: 0.5px;
  border: none;
}
.upload-btn-clear:hover { background: #fda4af; }

/* Carousel: arrows on sides, drop zone in center */
.upload-carousel {
  display: flex;
  align-items: center;
  gap: 12px;
}
.upload-arrow {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--primary);
  opacity: 0.5;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
  border-radius: 50%;
}
.upload-arrow:hover { opacity: 1; background: var(--primary-soft); }

.drop-zone {
  flex: 1;
  min-height: 240px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  background: #fafbfd;
  overflow: hidden;
  position: relative;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.drop-zone .drop-text {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.drop-zone .drop-hint {
  font-size: 13px;
  color: var(--text-tertiary);
}

/* Preview inside drop zone */
.upload-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 16px;
}
.upload-preview img {
  max-height: 200px;
  max-width: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.upload-preview-info {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
.upload-filename {
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-all;
}
.upload-status {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.upload-status-uploading {
  background: #fef3c7;
  color: #92400e;
  animation: pulse-status 1.5s ease-in-out infinite;
}
@keyframes pulse-status {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.upload-status-done { background: #d1fae5; color: #065f46; }
.upload-status-error { background: #fee2e2; color: #991b1b; }
.upload-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.upload-link:hover { text-decoration: underline; }

/* Counter */
.upload-counter {
  text-align: center;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* Bottom button */
.upload-bottom-buttons {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}
.upload-btn-open-all {
  background: var(--text-muted, #94a3b8);
  color: #fff;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: 24px;
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.upload-btn-open-all:hover { background: #64748b; }

/* Progress bar */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 16px;
  display: none;
}

.progress-bar .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  border-radius: 3px;
  transition: width 0.3s;
  width: 0%;
}

.upload-result {
  margin-top: 20px;
  display: none;
}

/* ========== Camera Tab ========== */
.btn-camera-capture {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  padding: 28px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary, #2563eb), var(--primary-dark, #1d4ed8));
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
  min-height: 96px;
}
.btn-camera-capture:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
}
.btn-camera-capture:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}
.btn-camera-capture:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-camera-capture svg {
  flex-shrink: 0;
}

.camera-counter {
  text-align: center;
  color: var(--text-muted, #64748b);
  font-size: 14px;
  margin-top: 16px;
  min-height: 20px;
}

.camera-history {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.camera-queue {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.camera-queue-item {
  position: relative;
  width: 100px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--primary, #2563eb);
  background: #f8fafc;
}
.camera-queue-item img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  display: block;
}
.camera-queue-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
  font-size: 10px;
  color: var(--text-muted, #64748b);
}
.camera-queue-info .btn {
  padding: 0 5px;
  font-size: 11px;
  line-height: 18px;
  min-width: auto;
}
.camera-buttons {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.camera-buttons .btn-camera-capture {
  flex: 1;
}
.btn-camera-send {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 140px;
  font-size: 16px;
  white-space: nowrap;
}

.camera-history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  background: var(--bg, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  transition: border-color 0.15s ease;
}
.camera-history-item:hover {
  border-color: var(--border-hover, #cbd5e1);
}

.camera-history-item img {
  width: 56px;
  height: 74px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: #e2e8f0;
}

.camera-history-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.camera-history-name {
  font-size: 13px;
  color: var(--text-muted, #64748b);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.camera-status {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  align-self: flex-start;
}
.camera-status-loading {
  background: #dbeafe;
  color: #1e40af;
}
.camera-status-ok {
  background: #dcfce7;
  color: #166534;
}
.camera-status-ok:hover {
  background: #bbf7d0;
}
.camera-status-error {
  background: #fef2f2;
  color: #991b1b;
}

/* ========== Toggle Switch ========== */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 12px;
  transition: var(--transition);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ========== Notifications / Toasts ========== */
#notifications {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  box-shadow: var(--shadow-md);
  font-size: 14px;
  max-width: 380px;
  animation: toastIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--error); }
.toast-info { border-left: 4px solid var(--primary); }

@keyframes toastIn {
  from { transform: translateX(100%) scale(0.95); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}

/* ========== Inline Edit ========== */
.inline-form td { padding: 6px 8px; }
.inline-form input { padding: 6px 10px; font-size: 13px; }

/* ========== Pagination ========== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
}

.pagination .btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: var(--radius);
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-secondary);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.25;
}

/* ========== Back Link ========== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 16px;
  font-weight: 500;
  transition: color var(--transition);
}

.back-link:hover { color: var(--primary); }

/* ========== Search ========== */
.search-bar {
  margin-bottom: 16px;
}

.search-bar .input-icon-wrap {
  max-width: 400px;
}

/* ========== Radio Group ========== */
.radio-group { display: flex; flex-direction: column; gap: 10px; }

.radio-label {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
}

.radio-label:hover { border-color: var(--border-hover); }

.radio-label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary);
}

.radio-label input[type="radio"] { margin-top: 4px; accent-color: var(--primary); }
.radio-desc { font-size: 13px; color: var(--grey); margin-top: 4px; line-height: 1.5; }
.field-hint { font-size: 12px; color: var(--grey); margin-top: 6px; }

/* ========== Responsive ========== */
@media (max-width: 768px) {
  header .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 0;
    gap: 8px;
  }

  nav {
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    width: 100%;
    order: 3;
  }

  nav::-webkit-scrollbar { display: none; }

  nav a svg { display: none; }

  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; }
  .invoice-header { grid-template-columns: 1fr 1fr; }
  .section-header { flex-direction: column; gap: 12px; }

  /* Camera — mobile */
  #view-camera .card {
    padding: 12px;
  }
  #view-camera .section-header {
    text-align: center;
  }
  .camera-buttons {
    flex-direction: column;
    gap: 10px;
  }
  .btn-camera-capture {
    padding: 24px 16px;
    font-size: 18px;
    border-radius: 14px;
  }
  .btn-camera-capture svg {
    width: 28px;
    height: 28px;
  }
  .btn-camera-send {
    padding: 16px;
    font-size: 18px;
    border-radius: 14px;
    min-width: auto;
  }
  .camera-queue {
    gap: 8px;
  }
  .camera-queue-item {
    width: 80px;
  }
  .camera-queue-item img {
    height: 64px;
  }
  .camera-history-item {
    padding: 8px;
    gap: 10px;
  }
  .camera-history-item img {
    width: 44px;
    height: 58px;
  }
  .camera-history-name {
    font-size: 11px;
  }

  /* Tables — horizontal scroll on mobile */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ========== Accessibility utilities ========== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ========== Loading States ==========
 * Three complementary techniques, not a lazy spinner:
 *  1. Top progress bar — always visible during any API call
 *  2. Skeleton rows — tables feel like they have shape, not emptiness
 *  3. Pulsing button — action buttons show their pending state inline
 */

/* 1. Top progress bar (NProgress-inspired, but custom) */
.top-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.top-progress.is-active {
  opacity: 1;
}
.top-progress::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--primary, #1a6dff) 50%,
    transparent 100%);
  animation: top-progress-slide 1.2s ease-in-out infinite;
}
@keyframes top-progress-slide {
  0%   { left: -40%; }
  100% { left: 100%; }
}

/* 2. Skeleton rows — monochrome shimmer that respects the row layout */
.skeleton-row td {
  padding: 14px 12px;
}
.skeleton-bar {
  display: inline-block;
  height: 12px;
  background: linear-gradient(90deg,
    #f1f5f9 0%,
    #e2e8f0 50%,
    #f1f5f9 100%);
  background-size: 200% 100%;
  border-radius: 3px;
  animation: skeleton-pulse 1.4s ease-in-out infinite;
  vertical-align: middle;
}
.skeleton-bar.w-full { width: 100%; }
.skeleton-bar.w-80   { width: 80%; }
.skeleton-bar.w-60   { width: 60%; }
.skeleton-bar.w-40   { width: 40%; }
.skeleton-bar.w-24   { width: 24px; }
@keyframes skeleton-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* 3. Pulsing button — for action buttons mid-request */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  color: #fff;
  animation: btn-spin 0.7s linear infinite;
}
.btn-outline.is-loading::after {
  color: var(--primary, #1a6dff);
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* ========== Confirm Modal ========== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}
.modal-text {
  font-size: 14px;
  color: var(--text-muted, #64748b);
  margin-bottom: 24px;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ========== Selection ========== */
::selection {
  background: rgba(26,109,255,0.15);
  color: var(--text);
}

/* Nomenclature picker (invoice detail autocomplete) */
.nom-picker {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}
.nom-picker-input {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
}
.nom-picker-input:focus {
  outline: none;
  border-color: var(--primary, #1a6dff);
}
.nom-picker-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 28px;
  right: 0;
  z-index: 100;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.nom-picker-option {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
}
.nom-picker-option:last-child { border-bottom: none; }
.nom-picker-option:hover { background: #f1f5f9; }
.nom-picker-option .nom-unit {
  color: #64748b;
  font-size: 11px;
  margin-left: 6px;
}
.nom-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 13px;
  flex-shrink: 0;
}
.nom-badge-ok {
  background: #dcfce7;
  color: #166534;
}
.nom-badge-missing {
  background: #fee2e2;
  color: #b91c1c;
}

/* Tabs inside nomenclature section */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  padding-bottom: 0;
}
.tab-btn {
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--primary, #3b82f6); }
.tab-btn.active {
  color: var(--primary, #3b82f6);
  border-bottom-color: var(--primary, #3b82f6);
}

/* Supplier-by-supplier layout */
.supplier-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  min-height: 400px;
}
.supplier-sidebar {
  background: var(--bg, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  overflow: hidden;
  max-height: 600px;
  overflow-y: auto;
}
.supplier-sidebar-header {
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted, #64748b);
  background: #fff;
  border-bottom: 1px solid var(--border, #e2e8f0);
  position: sticky;
  top: 0;
}
.supplier-item {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border, #e2e8f0);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.supplier-item:hover { background: #fff; }
.supplier-item.active {
  background: var(--primary, #3b82f6);
  color: #fff;
}
.supplier-item.active .supplier-count {
  background: rgba(255,255,255,0.25);
  color: #fff;
}
.supplier-count {
  background: var(--border, #e2e8f0);
  color: var(--text, #1e293b);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.supplier-content {
  min-width: 0;
}
.supplier-content-header {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text, #1e293b);
}

/* ========== Mapping Chips & Expanded Rows ========== */
.mapping-chip {
  display: inline-block;
  padding: 2px 8px;
  margin: 2px;
  background: var(--bg, #f1f5f9);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  font-size: 12px;
  color: var(--text, #334155);
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mapping-chip-more {
  background: var(--primary, #2563eb);
  color: white;
  border-color: var(--primary, #2563eb);
  cursor: pointer;
}
.mapping-expanded-row td {
  background: var(--bg-elevated, #f8fafc);
  border-top: none;
  padding-top: 4px;
  padding-bottom: 4px;
  font-size: 13px;
}
.expand-arrow {
  color: var(--text-muted, #94a3b8);
  font-size: 11px;
}
