/* spesa-app-2.css | Versione 2 | 2026-04-25 */

@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600&display=swap');

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --bg:       #0c0e14;
  --bg2:      #13161f;
  --bg3:      #1a1d2a;
  --surface:  #1e2232;
  --border:   #2a2f42;
  --accent:   #00e5a0;
  --accent2:  #00b8ff;
  --danger:   #ff6b6b;
  --warning:  #ffd93d;
  --purple:   #c084fc;
  --text:     #e8eaf0;
  --text2:    #8890a8;
  --text3:    #4a5068;
  --mono:     'Space Mono', monospace;
  --body:     'DM Sans', sans-serif;
  --r:        16px;
  --r-sm:     8px;
  --shadow:   0 4px 24px rgba(0,0,0,0.5);
}

/* ── Reset ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ─────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

/* ── Header ────────────────────────────────────────────── */
header {
  padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.02em;
}

.logo-icon { font-size: 1.3rem; }

/* ── Offline Banner ────────────────────────────────────── */
#offline-banner {
  display: none;
  background: #1c0f0f;
  border-bottom: 1px solid rgba(255,107,107,0.25);
  padding: 9px 20px;
  font-size: 0.78rem;
  color: var(--danger);
  font-family: var(--mono);
  text-align: center;
  letter-spacing: 0.04em;
}
#offline-banner.visible { display: block; }

/* ── Tabs ──────────────────────────────────────────────── */
nav.tabs {
  display: flex;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 4px;
}

.tab-btn {
  flex: 1;
  padding: 12px 4px;
  background: none;
  border: none;
  color: var(--text3);
  font-family: var(--body);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  position: relative;
  transition: color 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  -webkit-tap-highlight-color: transparent;
}

.tab-icon { font-size: 1.25rem; }
.tab-btn.active { color: var(--accent); }
.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0; left: 15%; right: 15%;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

/* ── Tab Content ───────────────────────────────────────── */
.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: block; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px;
  margin: 12px 14px;
}

.card-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.card-label::before {
  content: '';
  width: 5px; height: 5px;
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
}

/* ── Form Elements ─────────────────────────────────────── */
.form-group { margin-bottom: 12px; }

.form-group label {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 11px 13px;
  color: var(--text);
  font-family: var(--body);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,229,160,0.08);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  padding: 11px 18px;
  border: none;
  border-radius: var(--r-sm);
  font-family: var(--body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.96); }

.btn-primary  { background: var(--accent); color: #0c0e14; flex: 1; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-ghost    { background: none; color: var(--text2); font-size: 0.8rem; padding: 8px 12px; }
.btn-ai       { background: linear-gradient(135deg,#1a1040,#2a1660); color: var(--purple); border: 1px solid rgba(192,132,252,0.25); flex: 1; }
.btn-full     { width: 100%; }

/* ── Scanner: Start Screen ─────────────────────────────── */
#scanner-start { padding: 24px 14px; }

.big-scan-btn {
  width: 100%;
  min-height: 148px;
  background: var(--bg2);
  border: 1.5px dashed var(--border);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 12px;
  -webkit-tap-highlight-color: transparent;
}

.big-scan-btn:active {
  border-color: var(--accent);
  background: rgba(0,229,160,0.04);
}

.big-scan-btn.ai-btn {
  border-color: rgba(192,132,252,0.2);
  background: linear-gradient(135deg,#130e22,#13161f);
}

.big-scan-btn .bsb-icon  { font-size: 2.8rem; }
.big-scan-btn .bsb-title { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.big-scan-btn .bsb-sub   { font-size: 0.72rem; color: var(--text3); font-family: var(--mono); }

/* ── Scanner: Camera View ──────────────────────────────── */
#qr-reader-wrap { display: none; }

#qr-reader {
  width: 100%;
  background: #000;
  position: relative;
  overflow: hidden;
}

#qr-reader video { width: 100% !important; height: auto !important; display: block; }
#qr-reader img { display: none !important; }

.scan-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}

.scan-frame {
  width: 200px; height: 140px;
  position: relative;
}

.scan-frame::before,
.scan-frame::after {
  content: '';
  position: absolute;
  width: 36px; height: 36px;
  border-color: var(--accent);
  border-style: solid;
}

.scan-frame::before { top:0; left:0; border-width: 3px 0 0 3px; }
.scan-frame::after  { bottom:0; right:0; border-width: 0 3px 3px 0; }

.scan-line {
  position: absolute;
  left: 5%; right: 5%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scanMove 2s ease-in-out infinite;
}

@keyframes scanMove {
  0%,100% { top: 8%; opacity: 0.4; }
  50%      { top: 88%; opacity: 1; }
}

.scan-bar {
  padding: 12px 14px;
  display: flex; gap: 10px; align-items: center;
}

/* ── Product Info Box ──────────────────────────────────── */
#product-info-box {
  display: none;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 13px 15px;
  margin-bottom: 13px;
}

#product-info-box.show { display: block; }

.pib-name  { font-size: 0.95rem; font-weight: 600; margin-bottom: 3px; }
.pib-brand { font-size: 0.78rem; color: var(--text2); font-family: var(--mono); }

#price-compare {
  display: none;
  margin-top: 9px;
  padding: 7px 11px;
  background: rgba(0,229,160,0.07);
  border: 1px solid rgba(0,229,160,0.18);
  border-radius: var(--r-sm);
  font-size: 0.78rem;
  color: var(--accent);
  font-family: var(--mono);
}

#price-compare.up {
  background: rgba(255,107,107,0.07);
  border-color: rgba(255,107,107,0.18);
  color: var(--danger);
}

/* ── AI image preview ──────────────────────────────────── */
#ai-img-preview {
  display: none;
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: var(--r-sm);
  background: var(--bg3);
  margin-bottom: 12px;
}
#ai-img-preview.show { display: block; }

/* ── Lista Tab ─────────────────────────────────────────── */
#lista-tab { padding: 14px; }

.share-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 15px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.share-box-left { display: flex; flex-direction: column; gap: 3px; }
.share-lbl { font-size: 0.68rem; color: var(--text3); font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.08em; }
.share-code { font-family: var(--mono); font-size: 1.2rem; font-weight: 700; color: var(--accent); letter-spacing: 0.12em; }

.list-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 13px 14px;
  margin-bottom: 7px;
  display: flex; align-items: center; gap: 11px;
  transition: opacity 0.2s;
}

.list-item.checked { opacity: 0.38; }

.item-chk {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  transition: all 0.15s;
}

.list-item.checked .item-chk { background: var(--accent); border-color: var(--accent); color: #0c0e14; }
.item-nm  { flex: 1; font-size: 0.9rem; font-weight: 500; }
.item-qty { font-size: 0.75rem; color: var(--text3); font-family: var(--mono); }
.item-del { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 0.95rem; padding: 3px 5px; }

/* ── Storico Tab ────────────────────────────────────────── */
#storico-tab { padding: 0; }

.stats-row {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 7px;
  padding: 12px 14px 4px;
}

.stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 11px;
  text-align: center;
}

.stat-val { font-family: var(--mono); font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.stat-lbl { font-size: 0.62rem; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }

.search-row { padding: 8px 14px; }
.search-row input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  color: var(--text);
  font-family: var(--body);
  font-size: 0.88rem;
  outline: none;
}
.search-row input:focus { border-color: var(--accent); }

#storico-items { padding: 6px 14px 80px; }

.scan-row {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  margin-bottom: 7px;
  display: flex; align-items: center; gap: 12px;
  position: relative; overflow: hidden;
}

.scan-row::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent);
}

.scan-thumb {
  width: 42px; height: 42px;
  border-radius: var(--r-sm);
  background: var(--bg3);
  object-fit: cover;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
}

.scan-info { flex: 1; min-width: 0; }
.scan-nm { font-size: 0.88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-meta { font-size: 0.72rem; color: var(--text2); font-family: var(--mono); display: flex; gap: 7px; margin-top: 2px; }
.scan-price { font-family: var(--mono); font-size: 0.98rem; font-weight: 700; color: var(--accent); white-space: nowrap; }

/* ── Sync Badge ─────────────────────────────────────────── */
#sync-badge {
  display: none;
  background: var(--warning);
  color: #1a1200;
  border-radius: 10px;
  padding: 3px 8px;
  font-size: 0.62rem;
  font-family: var(--mono);
  font-weight: 700;
}
#sync-badge.show { display: inline-block; }

/* ── Toast ──────────────────────────────────────────────── */
#toast-wrap {
  position: fixed; bottom: 18px; left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex; flex-direction: column; gap: 7px;
  align-items: center; pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 9px 18px;
  font-size: 0.83rem;
  font-weight: 500;
  white-space: nowrap;
  max-width: 290px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: tIn 0.25s ease, tOut 0.25s ease 2.75s forwards;
}

.toast.ok    { border-color: rgba(0,229,160,0.35); color: var(--accent); }
.toast.err   { border-color: rgba(255,107,107,0.35); color: var(--danger); }
.toast.info  { border-color: rgba(0,184,255,0.35); color: var(--accent2); }

@keyframes tIn  { from { opacity:0; transform:translateY(12px) scale(0.92); } to { opacity:1; transform:none; } }
@keyframes tOut { from { opacity:1; } to { opacity:0; } }

/* ── Modali ─────────────────────────────────────────────── */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  display: none;
  align-items: flex-end; justify-content: center;
}
.modal-bg.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r) var(--r) 0 0;
  padding: 22px 18px 30px;
  width: 100%; max-width: 480px;
  animation: mUp 0.28s ease;
}

@keyframes mUp { from { transform: translateY(100%); } to { transform: none; } }

.modal-title {
  font-family: var(--mono); font-size: 0.85rem; font-weight: 700;
  color: var(--accent); margin-bottom: 14px;
  text-transform: uppercase; letter-spacing: 0.08em;
}

/* ── Empty State ─────────────────────────────────────────── */
.empty {
  text-align: center; padding: 44px 20px;
  color: var(--text3);
}
.empty-ico { font-size: 3rem; margin-bottom: 12px; }
.empty p { font-size: 0.87rem; line-height: 1.6; }

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Spinner ────────────────────────────────────────────── */
.spin {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(0,229,160,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spinR 0.65s linear infinite;
}
@keyframes spinR { to { transform: rotate(360deg); } }
