:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --surface-3: #e8e9ed;
  --border: #e3e5ea;
  --border-strong: #d1d5db;
  --text: #16181d;
  --text-dim: #6b7280;
  --text-faint: #9ca3af;

  --accent: #16a34a;
  --accent-dark: #0f7d39;
  --accent-soft: #e7f7ee;

  --good: #16a34a;
  --good-soft: #e7f7ee;
  --bad: #dc2626;
  --bad-soft: #fdeceb;
  --warn: #d97706;
  --warn-soft: #fef3e2;
  --info: #2563eb;
  --info-soft: #eaf1fe;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 2px 10px rgba(16, 24, 40, 0.07), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 12px 28px rgba(16, 24, 40, 0.12), 0 2px 6px rgba(16, 24, 40, 0.06);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

h1 { font-size: 24px; font-weight: 800; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 18px; font-weight: 700; margin: 0 0 14px; letter-spacing: -0.01em; }
p.subtitle { color: var(--text-dim); margin: 0 0 20px; font-size: 14px; line-height: 1.5; }

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Login screen --- */

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  max-width: 380px;
  width: 100%;
}

input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="email"], input[type="tel"], select, textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  margin-bottom: 12px;
  font-family: inherit;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  font-size: 15px;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s;
  font-family: inherit;
}
button:active { transform: scale(0.98); }

.btn-primary { background: var(--text); color: #fff; width: 100%; }
.btn-accent { background: var(--accent); color: #fff; width: 100%; box-shadow: 0 4px 14px rgba(22, 163, 74, 0.28); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border-strong); width: 100%; }
button:disabled { opacity: 0.4; cursor: default; }

.error-text { color: var(--bad); font-size: 14px; margin: -4px 0 12px; font-weight: 600; }

/* --- App shell --- */

.app-shell { min-height: 100dvh; display: flex; align-items: stretch; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 22px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--text); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; flex-shrink: 0;
}
.brand-name { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--text-dim); font-weight: 600; }

.nav-list { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-btn {
  background: none; border: none; color: var(--text-dim);
  padding: 11px 12px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 11px;
  text-align: left; width: 100%;
  transition: background 0.12s, color 0.12s;
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--text); color: #fff; }

.user-box { padding: 10px 12px; border-top: 1px solid var(--border); margin-top: 8px; }
.user-box .who { font-size: 13px; font-weight: 700; }
.user-box .role { font-size: 11px; color: var(--text-dim); }
.logout-btn {
  background: none; border: none; color: var(--text-dim);
  padding: 11px 12px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 11px; width: 100%;
}
.logout-btn:hover { background: var(--bad-soft); color: var(--bad); }

.main { flex: 1; min-width: 0; overflow-x: hidden; }
.body-inner { max-width: 1100px; margin: 0 auto; padding: 32px 36px 80px; }

.panel.hidden { display: none; }

.section-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

/* --- Forms --- */

.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; align-items: flex-end; }
.form-row > * { flex: 1; min-width: 150px; }
.form-row button { flex: 0 0 auto; width: auto; }
.field-label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: var(--text-dim); }
.field-label input, .field-label select { margin-bottom: 0; }

/* --- Cards / summary --- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 18px 20px;
}
.stat-card .label { font-size: 12px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .value { font-size: 26px; font-weight: 800; margin-top: 6px; letter-spacing: -0.02em; }
.stat-card .value.bad { color: var(--bad); }
.stat-card .sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.breakdown-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 28px; }
@media (max-width: 800px) { .breakdown-grid { grid-template-columns: 1fr; } }

.breakdown-list { display: flex; flex-direction: column; gap: 8px; }
.breakdown-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px;
}
.breakdown-row .name { font-weight: 600; }
.breakdown-row .amt { font-weight: 700; }
.breakdown-row .amt.zero { color: var(--text-faint); font-weight: 600; }

/* --- Tiles (Square-POS-style drill-down: Locations -> Vendors) --- */

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); margin-bottom: 16px; flex-wrap: wrap; }
.breadcrumb button { background: none; border: none; color: var(--accent); font-weight: 700; padding: 0; font-size: 13px; }
.breadcrumb button:active { transform: none; opacity: 0.7; }
.breadcrumb .sep { color: var(--text-faint); }
.breadcrumb .current { font-weight: 700; color: var(--text); }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.tile {
  border: 1.5px solid transparent;
  border-radius: 26px;
  box-shadow: var(--shadow-sm);
  padding: 22px 20px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
  aspect-ratio: 1.15;
  justify-content: space-between;
  transition: box-shadow 0.15s, transform 0.08s, border-color 0.15s;
  font-family: inherit;
  /* Square-style: a solid light wash fills the whole bubble, not just a border/icon accent. */
  background: rgba(37, 99, 235, 0.08);
  border-color: rgba(37, 99, 235, 0.18);
}
.tile:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.tile:active { transform: scale(0.97); }

.tile.has-balance { background: rgba(220, 38, 38, 0.09); border-color: rgba(220, 38, 38, 0.2); }
.tile.zero-balance { background: rgba(22, 163, 74, 0.09); border-color: rgba(22, 163, 74, 0.2); }

.tile-icon {
  width: 44px; height: 44px; border-radius: 14px;
  background: rgba(37, 99, 235, 0.16); color: #1d4ed8;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.tile.has-balance .tile-icon { background: rgba(220, 38, 38, 0.16); color: var(--bad); }
.tile.zero-balance .tile-icon { background: rgba(22, 163, 74, 0.16); color: var(--accent-dark); }

.tile-name { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.tile-amount { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.tile.has-balance .tile-amount { color: var(--bad); }
.tile.zero-balance .tile-amount { color: var(--accent-dark); }
.tile-sub { font-size: 12px; color: var(--text-dim); font-weight: 600; }

/* --- Tables --- */

table {
  width: 100%; border-collapse: separate; border-spacing: 0; margin-bottom: 24px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  overflow: hidden; box-shadow: var(--shadow-sm);
}
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
th { color: var(--text-dim); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; background: var(--surface-2); }
tbody tr { transition: background 0.1s; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }

.icon-btn { background: none; border: none; color: var(--text-dim); font-size: 13px; font-weight: 600; padding: 5px 9px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.badge { padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; display: inline-block; }
.badge.paid { background: var(--good-soft); color: var(--good); }
.badge.partial { background: var(--warn-soft); color: var(--warn); }
.badge.unpaid { background: var(--bad-soft); color: var(--bad); }
.badge.voided { background: var(--surface-2); color: var(--text-faint); text-decoration: line-through; }
.badge.overdue { background: var(--bad); color: #fff; }
.badge.on { background: var(--good-soft); color: var(--good); }
.badge.off { background: var(--bad-soft); color: var(--bad); }

/* --- Invoice detail --- */

.detail-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 24px; margin-bottom: 24px;
}
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 16px; }
.detail-grid .k { font-size: 11px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.detail-grid .v { font-size: 16px; font-weight: 700; margin-top: 3px; }

/* --- Photo attachments (invoices + payments) --- */

.attachment-strip { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.attachment-thumb {
  position: relative;
  width: 56px; height: 56px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  flex-shrink: 0;
}
.attachment-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attachment-thumb.pdf { display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; color: var(--text-dim); }
.attachment-remove {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 13px; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.attachment-add-tile {
  width: 56px; height: 56px; border-radius: 10px;
  border: 1.5px dashed var(--border-strong);
  background: none; color: var(--text-dim);
  font-size: 22px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.attachment-add-tile:hover { border-color: var(--accent); color: var(--accent); }
.attachment-thumb-sm { width: 32px; height: 32px; border-radius: 7px; }
.attachment-add-tile-sm { width: 32px; height: 32px; border-radius: 7px; font-size: 16px; }

/* --- Modal --- */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-card {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 28px; max-width: 480px; width: 100%; max-height: 90vh; overflow-y: auto;
}

/* --- Buy List --- */

.nav-section {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-faint); padding: 14px 12px 6px;
}
.nav-section:first-child { padding-top: 0; }

/* Each store gets its own color (set inline as --store: r, g, b) so a store reads the same everywhere. */
.store-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
  background: rgba(var(--store), 0.14); color: rgb(var(--store));
}
.store-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: rgb(var(--store)); }

.store-chips, .filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.store-chip, .filter-chip {
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 700;
  background: var(--surface); color: var(--text-dim); border: 1.5px solid var(--border);
}
.store-chip.selected {
  background: rgba(var(--store), 0.16); color: rgb(var(--store)); border-color: rgba(var(--store), 0.55);
}
.filter-chip.selected { background: var(--text); color: #fff; border-color: var(--text); }
.filter-chip .count { opacity: 0.6; margin-left: 4px; }
.filter-chips { margin-bottom: 18px; }

.add-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); padding: 18px; margin-bottom: 22px;
  display: flex; flex-direction: column; gap: 14px;
}
.add-input-wrap { position: relative; }
/* Big and roomy so Apple Pencil Scribble has space to write into. */
input.add-input { font-size: 22px; font-weight: 600; padding: 18px 18px; margin: 0; border-radius: var(--radius-md); min-height: 68px; }
.add-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.add-row .add-vendor { flex: 1; min-width: 160px; margin: 0; }
.add-row .add-btn { width: auto; padding: 12px 28px; font-size: 16px; }
.add-flash { font-size: 14px; font-weight: 600; color: var(--accent-dark); }

.suggest-list {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.suggest-item {
  display: flex; justify-content: space-between; gap: 12px; width: 100%;
  background: none; border-radius: 0; padding: 14px 16px; text-align: left; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover, .suggest-item.active { background: var(--surface-2); }
.suggest-item .meta { color: var(--text-dim); font-size: 13px; font-weight: 600; }

.stepper { display: inline-flex; align-items: stretch; border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); flex-shrink: 0; }
.stepper button { background: var(--surface-2); border-radius: 0; padding: 0; width: 44px; min-height: 44px; font-size: 20px; line-height: 1; color: var(--text); }
.stepper input { width: 52px; margin: 0; border: none; border-radius: 0; text-align: center; font-size: 17px; font-weight: 700; padding: 8px 2px; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.field-label .stepper { align-self: flex-start; }
#shop-vendor-grid .tile { aspect-ratio: auto; min-height: 150px; }

.group { margin-bottom: 22px; }
.group-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.group-title { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.group-title.warn { color: var(--warn); }
.group-header .icon-btn { color: var(--accent); font-weight: 700; }

.item-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow-sm); font-weight: 400;
}
.item-row:hover { border-color: var(--border-strong); }

/* Row + red remove strip on its right edge */
.item-wrap { display: flex; align-items: stretch; margin-bottom: 8px; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.item-wrap .item-row { margin-bottom: 0; box-shadow: none; border-right: none; border-radius: var(--radius-md) 0 0 var(--radius-md); }
.item-remove {
  flex: 0 0 48px; padding: 0; border-radius: 0 var(--radius-md) var(--radius-md) 0;
  background: var(--bad-soft); color: var(--bad); border: 1px solid rgba(220, 38, 38, 0.25);
  display: flex; align-items: center; justify-content: center;
}
.item-remove:hover { background: var(--bad); color: #fff; }
.item-remove .icon { width: 20px; height: 20px; stroke-width: 2.5; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60;
  display: flex; align-items: center; gap: 16px; max-width: calc(100% - 32px);
  background: var(--text); color: #fff; padding: 12px 16px; border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 600;
}
.toast button { background: none; color: #86efac; padding: 4px 6px; font-size: 14px; flex-shrink: 0; }
@media (max-width: 780px) { .toast { bottom: calc(80px + env(safe-area-inset-bottom)); } }
.item-qty { font-size: 20px; font-weight: 800; min-width: 38px; text-align: center; }
.item-main { flex: 1; min-width: 0; }
.item-name { font-size: 16px; font-weight: 700; }
.item-meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge.rollover { background: var(--warn-soft); color: var(--warn); }
.badge.extra { background: var(--info-soft); color: var(--info); }

.empty-state { text-align: center; color: var(--text-dim); padding: 36px 16px; font-size: 15px; }

/* Trip (shopping) cards: one per product, rows per store */
.trip-card {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
.trip-card.done { background: rgba(22, 163, 74, 0.07); border-color: rgba(22, 163, 74, 0.35); }
.trip-card.partial { background: rgba(217, 119, 6, 0.07); border-color: rgba(217, 119, 6, 0.35); }
.trip-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.trip-card-name { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.trip-card-need { font-size: 13px; color: var(--text-dim); font-weight: 600; margin-top: 2px; }
.trip-card-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.trip-card-actions .btn-secondary { width: auto; padding: 10px 14px; font-size: 14px; }
.cost-field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); font-weight: 700; }
.cost-field input { width: 96px; margin: 0; padding: 10px; font-size: 15px; font-weight: 700; }
.trip-store-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.trip-store-row .need { font-size: 13px; color: var(--text-dim); font-weight: 600; margin-left: 8px; }

.trip-bar {
  position: sticky; bottom: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 12px 14px; margin-top: 16px;
}
.trip-bar .progress { font-size: 14px; font-weight: 700; }
.trip-bar .progress .sub { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.trip-bar .btn-accent { width: auto; }
.trip-bar .icon-btn { color: var(--bad); }

.store-card {
  border-radius: var(--radius-lg); padding: 16px; margin-bottom: 14px;
  background: rgba(var(--store), 0.07); border: 1.5px solid rgba(var(--store), 0.3);
}
.store-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.store-card-name { font-size: 17px; font-weight: 800; color: rgb(var(--store)); }
.store-card .btn-accent { width: auto; padding: 10px 14px; font-size: 14px; }
.store-line { display: flex; gap: 12px; padding: 7px 0; border-top: 1px solid rgba(var(--store), 0.18); font-size: 14px; }
.store-line .q { font-weight: 800; min-width: 32px; }
.store-line .src { margin-left: auto; color: var(--text-dim); font-size: 12px; font-weight: 600; text-align: right; }

/* --- Korona: stock, cases, scanning, receipts --- */

.item-cases { font-size: 11px; font-weight: 700; color: var(--text-dim); margin-top: 2px; }
.add-row .add-unit { width: auto; margin: 0; flex: 0 0 auto; }

.stock-strip { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: 6px; font-size: 12px; }
.stock-strip:empty { display: none; }
.stock-label { color: var(--text-faint); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
.stock-chip { padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-dim); font-weight: 600; }
.stock-chip b { color: var(--text); }
.stock-chip.mine { outline: 1.5px solid var(--border-strong); }
.stock-chip.plenty { background: var(--good-soft); color: var(--good); }
.stock-chip.plenty b { color: var(--good); }
.stock-hint { color: var(--good); font-weight: 700; }

.link-btn { background: none; border: none; padding: 0; font-size: inherit; font-weight: 700; color: var(--accent); }
.link-btn:active { transform: none; opacity: 0.7; }
#trip-cancel { color: var(--bad); font-weight: 600; }
.trip-bar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.trip-bar-actions button { width: auto; display: inline-flex; align-items: center; gap: 6px; }

.modal-card.scan-card { max-width: 560px; }
.scan-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.scan-view { width: 100%; border-radius: var(--radius-md); overflow: hidden; background: #000; min-height: 200px; }
.scan-view video { width: 100% !important; display: block; }
.scan-view.paused { opacity: 0.35; max-height: 120px; }
.scan-manual { display: flex; gap: 8px; margin-top: 12px; }
.scan-manual input { margin: 0; }
.scan-manual button { width: auto; flex-shrink: 0; }
.scan-result-card {
  margin-top: 12px; padding: 14px; border-radius: var(--radius-md);
  border: 1.5px solid var(--border); background: var(--surface);
}
.scan-result-card.done { background: rgba(22, 163, 74, 0.06); border-color: rgba(22, 163, 74, 0.35); }
.scan-result-card.partial { background: rgba(217, 119, 6, 0.06); border-color: rgba(217, 119, 6, 0.35); }
.scan-result-card .form-row select { margin: 0; }
.form-row > .stepper, .scan-result-card .form-row .stepper { flex: 0 0 auto; min-width: 0; }

.receipt-line { font-size: 12px; font-weight: 600; margin-top: 10px; padding-top: 8px; border-top: 1px dashed rgba(var(--store), 0.3); color: var(--text-dim); }
.receipt-line.booked { color: var(--good); }
.receipt-line.failed { color: var(--bad); }
.receipt-line .error-text { display: inline; font-size: 12px; margin: 0; }

.add-input-row { display: flex; gap: 10px; align-items: stretch; }
.add-input-row .add-input-wrap { flex: 1; min-width: 0; }
.scan-big-btn {
  flex: 0 0 auto; width: 76px; padding: 0; border-radius: var(--radius-md);
  background: var(--text); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 12px;
}
.scan-big-btn .icon { width: 26px; height: 26px; }

.transfer-banner {
  width: 100%; text-align: left; margin-bottom: 16px; padding: 12px 16px;
  background: var(--info-soft); color: var(--info); border: 1px solid rgba(37, 99, 235, 0.25); border-radius: var(--radius-md);
}
.stock-hint[role='button'] { cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.take-link { font-size: 12px; margin-left: 8px; color: var(--info); }
.route-arrow { color: var(--text-dim); margin: 0 4px; }
.store-card-name .store-pill { font-size: 13px; }

.list-scan-row { border-top: 1px solid var(--border); padding: 10px 0; }
.list-scan-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.list-scan-facts { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.list-scan-top > div:first-child { flex: 1; min-width: 0; }
.list-scan-top .stepper button { width: 40px; }
.list-scan-top .stepper input { width: 46px; }
.list-scan-facts b { color: var(--text); }
select.list-scan-from { margin: 8px 0 0; padding: 8px 10px; font-size: 14px; }

.urgent-toggle { width: auto; flex: 0 0 auto; background: var(--surface); color: var(--text-dim); border: 1.5px solid var(--border); }
.urgent-toggle.on { background: var(--bad-soft); color: var(--bad); border-color: rgba(220, 38, 38, 0.45); }
.badge.urgent { background: var(--bad); color: #fff; }
.item-wrap.urgent .item-row { border-left: 4px solid var(--bad); }
.est-cost { font-weight: 700; color: var(--text); }
.row-note { font-size: 12px; color: var(--text-dim); font-style: italic; margin-top: 3px; }

.list-tools { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 18px; }
.list-tools .filter-chips { margin-bottom: 0; }
.sort-field { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--text-dim); }
.sort-field select { width: auto; margin: 0; padding: 8px 10px; font-size: 14px; }

.trip-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.trip-head-note { font-size: 14px; font-weight: 600; flex: 1; min-width: 180px; }
.trip-head-note .muted { color: var(--text-dim); font-weight: 500; font-size: 13px; }
.trip-head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.trip-head-actions .btn-secondary { width: auto; padding: 9px 12px; font-size: 14px; }
.btn-secondary.danger { color: var(--bad); border-color: rgba(220, 38, 38, 0.4); }
.more-btn { font-size: 20px !important; line-height: 1; padding: 6px 12px !important; }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-list .btn-secondary { text-align: left; }
.menu-move { display: flex; gap: 8px; }
.menu-move select { margin: 0; }
.menu-move .btn-secondary { width: auto; flex-shrink: 0; }
.trip-detail-note { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; margin: -8px 0 12px; }
.link-btn.plain { color: var(--text); font-weight: 600; text-align: left; }

.ip-row {
  display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow-sm);
}
.ip-main { flex: 1; min-width: 0; }
.ip-row button { width: auto; flex-shrink: 0; padding: 10px 14px; font-size: 14px; }
#shop-in-progress:not(:empty) { margin-bottom: 20px; }
textarea { resize: vertical; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; }
.segmented button { width: auto; background: none; padding: 8px 14px; font-size: 14px; color: var(--text-dim); border-radius: 8px; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.stock-filters { margin-bottom: 14px; }
.stock-filters .filter-chips { margin-bottom: 10px; }
.stock-filter-row { display: flex; gap: 8px; flex-wrap: wrap; }
.stock-filter-row > * { margin: 0; flex: 1; min-width: 140px; }
.stock-chip.neg { background: var(--bad-soft); color: var(--bad); }
.stock-chip.neg b { color: var(--bad); }
.short-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.short-card {
  text-align: left; border-radius: var(--radius-md); padding: 14px; font-weight: 400;
  background: rgba(var(--store), 0.07); border: 1.5px solid rgba(var(--store), 0.25);
}
.short-card.selected { border-color: rgb(var(--store)); box-shadow: 0 0 0 2px rgba(var(--store), 0.25); }
.short-card-name { font-weight: 800; color: rgb(var(--store)); }
.short-card-count { font-size: 26px; font-weight: 800; color: var(--bad); margin-top: 4px; }
.short-card-sub { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.short-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.short-actions .muted { flex: 1; }
.muted { color: var(--text-dim); font-size: 13px; }
.small-btn { width: auto !important; padding: 8px 12px !important; font-size: 13px !important; text-decoration: none; display: inline-block; }
a.btn-secondary { color: var(--text); border-radius: var(--radius-sm); font-weight: 700; }
.short-row {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 10px 14px; margin-bottom: 8px; box-shadow: var(--shadow-sm);
}
.short-row.is-checked { opacity: 0.55; }
.short-qty { font-size: 18px; font-weight: 800; color: var(--bad); min-width: 44px; text-align: center; }

.reorder-settings { font-size: 13px; font-weight: 600; color: var(--text-dim); gap: 8px; }
.reorder-settings input { width: 64px; margin: 0; padding: 6px 8px; font-size: 14px; }
.sales-speed { font-weight: 700; color: var(--text); }

.stat-card .sub .up { color: var(--good); font-weight: 700; }
.stat-card .sub .down { color: var(--bad); font-weight: 700; }
.flag-list { display: flex; flex-direction: column; gap: 8px; }
.flag {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 10px 14px; box-shadow: var(--shadow-sm);
}
.flag.high { border-left: 4px solid var(--bad); }
.flag.medium { border-left: 4px solid var(--warn); }
.flag-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--warn); }
.flag.high .flag-dot { background: var(--bad); }
.flag-text { font-size: 14px; font-weight: 600; }

.agent-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.agent-card:empty { display: none; }
.agent-title { font-weight: 800; font-size: 15px; }
.agent-controls { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-top: 10px; font-size: 13px; font-weight: 600; }
.agent-controls label { display: flex; align-items: center; gap: 6px; }
.agent-controls select { width: auto; margin: 0; padding: 6px 8px; font-size: 13px; }
.brief-text { white-space: pre-wrap; background: var(--surface-2); border-radius: var(--radius-md); padding: 14px; font-size: 14px; line-height: 1.5; }

.diff-short { color: var(--bad); }
.diff-over { color: var(--warn); }

.nav-badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 800; padding: 1px 7px; margin-left: auto; }
.request-banner { background: var(--warn-soft); color: var(--warn); border-color: rgba(217, 119, 6, 0.3); }
.request-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--warn);
  border-radius: var(--radius-md); padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
}
.request-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.request-controls select { width: auto; margin: 0; padding: 8px 10px; font-size: 14px; }
.run-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 14px; margin-bottom: 8px; box-shadow: var(--shadow-sm); }
.run-card summary { cursor: pointer; list-style: none; display: flex; }
.run-card summary::-webkit-details-marker { display: none; }

.inactive-row td { opacity: 0.55; }

@media print {
  body * { visibility: hidden; }
  .modal-overlay, .modal-overlay * { visibility: visible; }
  .modal-overlay { position: absolute; inset: 0; background: none; display: block; padding: 0; }
  .modal-card { box-shadow: none; max-height: none; max-width: none; }
  .no-print { display: none !important; }
}

/* --- Mobile top bar + bottom tab bar (hidden on desktop, shown <=780px) --- */

.mobile-topbar { display: none; }
.mobile-tabbar { display: none; }

/* --- Responsive: swap sidebar for a top bar + bottom tab bar on narrow viewports --- */

@media (max-width: 780px) {
  .app-shell { flex-direction: column; }
  .sidebar { display: none; }

  .mobile-topbar {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
  }
  .mobile-topbar .brand-mark { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
  .mobile-topbar-name { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; }

  .main { padding-bottom: 74px; }
  .body-inner { padding: 18px 14px 40px; }

  .mobile-tabbar {
    display: flex; align-items: stretch; justify-content: space-around;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .mobile-tabbar .nav-btn {
    flex-direction: column; gap: 3px; font-size: 10px; padding: 6px 4px;
    width: auto; flex: 1; min-width: 0; text-align: center; align-items: center;
    border-radius: 10px;
  }
  .mobile-tabbar .nav-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .mobile-tabbar .nav-btn.active { background: var(--surface-2); color: var(--text); }
  .mobile-tabbar .nav-btn:not(.active) { color: var(--text-dim); }

  /* Tighter stat/tile grids: 2 columns instead of 1 */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 20px; }
  .stat-card { padding: 14px 14px; }
  .stat-card .value { font-size: 20px; }

  .tile-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 20px; }
  .tile { aspect-ratio: 0.95; padding: 16px 14px; border-radius: 20px; gap: 8px; }
  .tile-icon { width: 36px; height: 36px; border-radius: 11px; }
  .tile-name { font-size: 14px; }
  .tile-amount { font-size: 19px; }

  .detail-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .detail-panel { padding: 16px; }

  /* Tables -> stacked cards */
  table.responsive-table, table.responsive-table thead, table.responsive-table tbody,
  table.responsive-table th, table.responsive-table td, table.responsive-table tr {
    display: block;
  }
  table.responsive-table { border: none; box-shadow: none; background: none; }
  table.responsive-table thead { display: none; }
  table.responsive-table tbody tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm); margin-bottom: 10px; padding: 4px 0;
  }
  table.responsive-table tbody tr:last-child { margin-bottom: 0; }
  table.responsive-table td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 9px 14px; border-bottom: 1px solid var(--border); text-align: right;
  }
  table.responsive-table td:last-child { border-bottom: none; }
  table.responsive-table td::before {
    content: attr(data-label);
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
    color: var(--text-dim); text-align: left; flex-shrink: 0;
  }
  table.responsive-table td:empty::before { content: none; }
  table.responsive-table td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
  table.responsive-table td[data-label=""]::before { content: none; }

  /* Buy List on phones */
  .add-card { padding: 14px; }
  .add-row .add-vendor { order: 3; flex-basis: 100%; }
  .add-row .add-btn { flex: 1; }
  .trip-card-head { flex-direction: column; }
  .trip-card-actions { width: 100%; justify-content: space-between; }
  .trip-bar { bottom: calc(66px + env(safe-area-inset-bottom)); }
  .trip-bar { flex-wrap: wrap; }
  .trip-bar-actions { flex: 1; justify-content: flex-end; }
  .trip-bar-actions button { padding: 12px 14px; }
}
