/* =============================================================
   styles.css — Celiac Tracker
   =============================================================
   CSS custom properties (variables) at the top mean we only
   define colors once. Dark mode is automatic — the browser
   detects the system preference via prefers-color-scheme.
============================================================= */

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

/* Light mode color tokens */
:root {
  --green:      #3B6D11;
  --green-bg:   #EAF3DE;
  --green-dark: #27500A;
  --green-pill: #7ec94a;
  --amber:      #BA7517;
  --amber-bg:   #FFF3CD;
  --red:        #A32D2D;
  --surface:    #f8f8f6;
  --card:       #ffffff;
  --border:     rgba(0,0,0,0.09);
  --border-med: rgba(0,0,0,0.16);
  --text:       #1a1a18;
  --muted:      #6b6b67;
  --radius-md:  8px;
  --radius-lg:  12px;
}

/* Dark mode — browser switches automatically */
@media (prefers-color-scheme: dark) {
  :root {
    --green:      #7ec94a;
    --green-bg:   #1a2e0d;
    --green-dark: #a8e070;
    --green-pill: #5aab2e;
    --amber:      #f0b940;
    --amber-bg:   #2e2100;
    --red:        #e07070;
    --surface:    #1a1a18;
    --card:       #242422;
    --border:     rgba(255,255,255,0.09);
    --border-med: rgba(255,255,255,0.18);
    --text:       #f0f0ec;
    --muted:      #9a9a94;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  /* Safe area = space for iPhone home bar */
  padding-bottom: env(safe-area-inset-bottom);
}

.app { max-width: 680px; margin: 0 auto; padding: 1rem 1rem 5rem; }

/* Header */
.header { margin-bottom: 1.25rem; padding-top: 0.5rem; }
.header h1 { font-size: 20px; font-weight: 600; }
.header p  { font-size: 13px; color: var(--muted); margin-top: 3px; }

/* Tabs — fixed to bottom on mobile, inline on desktop */
.tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--card);
  border-top: 0.5px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}
@media (min-width: 600px) {
  .tabs {
    position: static;
    border-top: none;
    border: 0.5px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 1.25rem;
    padding-bottom: 0;
  }
}
.tab {
  flex: 1;
  padding: 10px 6px 8px;
  font-size: 13px;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}
.tab.active { color: var(--green); font-weight: 600; }

/* Cards */
.card {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.125rem;
  margin-bottom: 1rem;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Upload zone */
.upload-zone {
  border: 1.5px dashed var(--border-med);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s;
}
.upload-zone:hover { border-color: var(--green); }
.upload-icon { font-size: 36px; margin-bottom: 8px; }
.upload-zone p { font-size: 14px; color: var(--muted); }
.upload-hint { font-size: 12px; margin-top: 4px; }
#fileInput { display: none; }

/* Preview area */
.preview-area { margin-top: 1rem; }
#previewImg {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
}

/* Inputs */
input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  background: var(--card);
  color: var(--text);
  outline: none;
  margin-bottom: 8px;
}
input[type="text"]:focus { border-color: var(--green); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-med);
  background: var(--card);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--text); color: var(--card); border-color: var(--text); }
.btn-primary:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Spinner */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  padding: 6px 0;
}

/* Item rows */
.item-row { padding: 11px 0; border-bottom: 0.5px solid var(--border); }
.item-row:last-child { border-bottom: none; }
.item-top {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto auto;
  align-items: start;
  gap: 10px;
}

/* Editable name */
.item-name-display {
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  border-bottom: 1px dashed transparent;
}
.item-name-display:hover { border-bottom-color: var(--border-med); }
.item-name-input {
  font-size: 14px;
  width: 100%;
  padding: 2px 6px;
  border: 0.5px solid var(--green);
  border-radius: 4px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  outline: none;
}

/* Editable price */
.price-col { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.item-price-display {
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  white-space: nowrap;
}
.item-price-display:hover { border-bottom-color: var(--border-med); }
.item-price-input {
  font-size: 14px;
  width: 70px;
  padding: 2px 6px;
  text-align: right;
  border: 0.5px solid var(--green);
  border-radius: 4px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  outline: none;
}

/* Claimable amount */
.claimable { font-size: 12px; font-weight: 600; color: var(--green); white-space: nowrap; }
.claimable.zero { color: var(--muted); font-weight: 400; }

/* Barcode hint shown under item name */
.barcode-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* GF toggle pill */
.gf-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 6px;
  border-radius: 20px;
  border: 1.5px solid var(--border-med);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  font-family: inherit;
  white-space: nowrap;
  user-select: none;
}
.gf-toggle.is-gf { background: var(--green-bg); border-color: var(--green-pill); color: var(--green); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-med); flex-shrink: 0; }
.gf-toggle.is-gf .dot { background: var(--green); }

/* Receipt total */
.receipt-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 0.5px solid var(--border);
}
.total-label  { font-size: 13px; color: var(--muted); }
.total-amount { font-size: 22px; font-weight: 600; color: var(--green); }

/* Summary metrics */
.metric-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 1rem; }
.metric { background: var(--card); border: 0.5px solid var(--border); border-radius: var(--radius-md); padding: 0.875rem; }
.metric-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.metric-value { font-size: 22px; font-weight: 600; }
.metric-value.green { color: var(--green); }

/* Receipts list */
.receipt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
  gap: 8px;
  font-size: 13px;
}
.receipt-row:last-child { border-bottom: none; }
.r-store  { font-weight: 500; }
.r-meta   { font-size: 12px; color: var(--muted); margin-top: 2px; }
.r-amount { font-weight: 600; color: var(--green); flex-shrink: 0; }
.del-btn  { font-size: 11px; color: var(--muted); background: none; border: none; cursor: pointer; font-family: inherit; }
.del-btn:hover { color: var(--red); }

/* Alert */
.alert {
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-size: 13px;
  margin-bottom: 1rem;
  line-height: 1.6;
  background: var(--green-bg);
  color: var(--green-dark);
}

.empty { text-align: center; padding: 2rem 1rem; font-size: 14px; color: var(--muted); }
.edit-hint { font-size: 11px; color: var(--muted); margin-bottom: 10px; }

/* ── Milestone 5 additions ── */

/* Verification status shown under each item name */
.item-status {
  font-size: 11px;
  margin-top: 3px;
  display: block;
}
.item-status.verified {
  color: #3B6D11;
}
.item-status.unverified {
  color: #BA7517;
}

/* Equivalent product form shown when toggling new GF item */
.equiv-form {
  margin-top: 10px;
  padding: 10px;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-med);
}
.equiv-form input {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  background: var(--card);
  color: var(--text);
  outline: none;
}
.equiv-form input:focus {
  border-color: var(--green);
}

/* Equivalent note shown under verified GF items */
.equiv-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

/* ── GF badge from Open Food Facts ── */
.gf-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 4px;
  cursor: default;
}

/* ── Weight display ── */
.item-weight {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}