:root {
  --bg: #0b0b0d;
  --surface: #16161a;
  --surface-alt: #1e1e24;
  --surface-raised: #232329;
  --text: #f2ede3;
  --muted: #a79f92;
  --border: #2c2c32;
  --brand-red: #c4211b;
  --brand-red-bright: #e2261c;
  --brand-gold: #a9a23a;
  --brand-gold-soft: #c7bd6e;
  --good: #4caf6d;
  --warn: #d9a441;
  --radius: 14px;
  --radius-sm: 10px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overscroll-behavior-y: contain;
}

button {
  font-family: inherit;
}

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

.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  padding-top: calc(24px + var(--safe-t));
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.auth-card h1 {
  font-size: 1.25rem;
  margin: 0 0 16px;
}

/* ---- Branding pieces ---- */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  background: var(--brand-red-bright);
  border: 2px solid #efe6d6;
  border-radius: 3px;
  color: var(--brand-gold);
  font-family: "Brush Script MT", "Segoe Script", cursive;
  font-style: italic;
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1;
  transform: rotate(-3deg);
  flex-shrink: 0;
}

.badge-sm {
  padding: 4px 7px;
  font-size: 0.95rem;
}

.wordmark {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 1.2rem;
  line-height: 1.05;
  color: var(--text);
}

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

#app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  padding-top: calc(10px + var(--safe-t));
  background: #050505;
  border-bottom: 1px solid var(--border);
}

.top-bar-title {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
}

.brand-fallback {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.top-bar-logo {
  height: 30px;
  flex: 1;
  object-fit: contain;
  object-position: left center;
}

.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}

.icon-btn-light {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

#views {
  flex: 1;
  padding: 14px 14px calc(var(--nav-h) + 90px);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.view[hidden] {
  display: none;
}

.section-title {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 1.1rem;
  margin: 22px 0 10px;
  color: var(--text);
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 14px;
  line-height: 1.4;
}

/* ---- Forms / inputs ---- */

label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 12px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
}

input::placeholder {
  color: var(--muted);
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  position: sticky;
  top: calc(var(--safe-t) + 61px);
  z-index: 10;
  background: var(--bg);
  padding: 8px 0;
}

.search-row input {
  flex: 1;
  margin-top: 0;
}

.search-row .icon-btn {
  flex-shrink: 0;
}

/* ---- Buttons ---- */

.btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 46px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--brand-red-bright);
  color: #fff;
}

.btn-gold {
  background: var(--brand-gold);
  color: #0b0b0d;
}

.btn-line {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  flex: 1;
}

.export-actions {
  display: flex;
  gap: 10px;
}

/* ---- Item lists / cards ---- */

.item-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.item-card-main {
  flex: 1;
  min-width: 0;
}

.item-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-card-meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.item-card-meta .stock-pill {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface-raised);
  color: var(--brand-gold-soft);
  font-size: 0.78rem;
  font-weight: 600;
}

.item-card-meta .stock-pill.out {
  background: rgba(196, 33, 27, 0.25);
  color: #ff9c96;
}

.empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 16px 4px;
  text-align: center;
}

/* Stepper (+/-) */

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.stepper button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.stepper button:active {
  background: var(--surface-raised);
}

.stepper .stepper-value {
  min-width: 24px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.add-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--brand-gold);
  color: #0b0b0d;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Carrello ---- */

.cart-summary {
  background: var(--surface-raised);
  border: 1px solid var(--brand-gold);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  overflow: hidden;
}

.cart-summary-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

.cart-summary-total {
  margin-left: auto;
  color: var(--brand-gold-soft);
  font-variant-numeric: tabular-nums;
}

.chev {
  color: var(--muted);
}

.cart-summary .item-list {
  padding: 0 10px;
}

.sticky-actions {
  padding: 10px;
}

.add-product {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.add-product summary {
  cursor: pointer;
  padding: 6px 2px;
}

.add-product form {
  margin-top: 12px;
}

.error {
  color: var(--brand-red-bright);
  min-height: 1.2em;
  font-size: 0.9rem;
  margin: 10px 0 0;
}

.status {
  text-align: center;
  color: var(--muted);
  min-height: 1.2em;
  font-size: 0.85rem;
  padding: 4px 0;
}

/* ---- Bottom nav ---- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: #050505;
  border-top: 1px solid var(--border);
}

.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.7rem;
  padding: 6px 10px;
  cursor: pointer;
  position: relative;
}

.nav-btn.is-active {
  color: var(--brand-gold-soft);
}

.nav-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.nav-badge {
  position: absolute;
  top: 0;
  right: 2px;
  background: var(--brand-red-bright);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.nav-fab {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 3px solid #050505;
  background: var(--brand-red-bright);
  color: #fff;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-top: -26px;
  box-shadow: 0 4px 14px rgba(226, 38, 28, 0.5);
}

.nav-fab:active {
  transform: scale(0.95);
}

/* ---- Scanner overlay ---- */

.scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  flex-direction: column;
}

.scanner-overlay[hidden] {
  display: none;
}

.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  padding-top: calc(12px + var(--safe-t));
  gap: 10px;
}

.scanner-mode {
  display: flex;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 3px;
}

.mode-btn {
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.7);
  padding: 8px 16px;
  border-radius: 18px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.mode-btn.is-active {
  background: var(--brand-gold);
  color: #0b0b0d;
}

.scanner-viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
}

#scanner-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-frame {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 38%;
  height: 24%;
  border: 3px solid var(--brand-gold);
  border-radius: 12px;
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.scanner-hint {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 0.85rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  margin: 0;
  padding: 0 20px;
}

.torch-btn {
  position: absolute;
  bottom: 18px;
  right: 18px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  font-size: 1.2rem;
  cursor: pointer;
}

.scan-toast {
  position: absolute;
  top: calc(80px + var(--safe-t));
  left: 16px;
  right: 16px;
  z-index: 5;
  background: var(--good);
  color: #06170c;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.scan-toast.is-error {
  background: var(--brand-red-bright);
  color: #fff;
}

.scan-result {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-b));
}

.scan-result-info {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

.scan-result-info strong {
  font-size: 1.05rem;
}

.scan-result-info span {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.scan-result-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.scan-result-actions .btn {
  flex: 1;
}

.scan-link-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.scan-link-search {
  margin-top: 0;
}

.scan-link-list {
  max-height: 38vh;
  overflow-y: auto;
  gap: 6px;
}

.scan-link-list:empty {
  display: none;
}

.item-card-compact {
  padding: 8px 10px;
}

.item-card-compact .btn {
  flex: none;
  padding: 8px 14px;
  min-height: 36px;
}

@media (min-width: 640px) {
  #views {
    padding-left: 20px;
    padding-right: 20px;
  }
}
