:root {
  --wine: #5c1a2b;
  --wine-dark: #3d0f1c;
  --wine-light: #8a3a4d;
  --cream: #faf6f2;
  --gray: #6b6b6b;
  --border: #e2dcd6;
  --success: #2e7d32;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--cream);
  color: #2a2a2a;
  padding-bottom: 40px;
}

.app-header {
  background: linear-gradient(135deg, var(--wine), var(--wine-dark));
  color: white;
  padding: 20px 16px 16px;
  text-align: center;
}
.app-header .logo { font-size: 1.3rem; font-weight: 700; }
.app-header .subtitle { font-size: 0.8rem; opacity: 0.8; margin-top: 2px; }

.api-status {
  text-align: center;
  font-size: 0.72rem;
  padding: 5px 8px;
  color: white;
  background: #8a6d1a;
}
.api-status.live { background: #2e7d32; }
.api-status a { color: white; text-decoration: underline; }

.tabs {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 10;
  background: white;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 4px;
  font-size: 0.82rem;
  color: var(--gray);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab-btn.active {
  color: var(--wine);
  border-bottom-color: var(--wine);
  font-weight: 600;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.hint { color: var(--gray); font-size: 0.9rem; margin-top: 0; }

.capture-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px dashed var(--wine-light);
  border-radius: 14px;
  padding: 36px 16px;
  cursor: pointer;
  background: white;
  color: var(--wine);
  font-weight: 600;
}
.capture-box #captureIcon { font-size: 2.4rem; }

.label-preview {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 12px;
  margin-top: 14px;
  background: #eee;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 14px;
}
.btn.primary { background: var(--wine); color: white; width: 100%; }
.btn.secondary { background: white; color: var(--wine); border: 1px solid var(--wine); }

.recognize-status {
  margin-top: 14px;
  color: var(--gray);
  font-size: 0.9rem;
}

.recognize-result {
  margin-top: 16px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.recognize-result h3 { margin: 0 0 8px; font-size: 1rem; color: var(--wine); }
.field-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.field-row:last-of-type { border-bottom: none; }
.field-label { color: var(--gray); }

.note {
  font-size: 0.78rem;
  color: var(--gray);
  background: #fff8ec;
  border: 1px solid #f0e2c0;
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 20px;
  line-height: 1.4;
}
.note code { background: #f1e9d8; padding: 1px 4px; border-radius: 4px; }

.filters {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: grid;
  gap: 10px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.78rem; color: var(--gray); font-weight: 600; }
.field input, .field select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.95rem;
  font-family: inherit;
}

.result-count { margin: 14px 2px 6px; font-size: 0.82rem; color: var(--gray); }

.results { display: grid; gap: 10px; }

.wine-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.wine-card .wine-title { font-weight: 700; font-size: 1.02rem; color: var(--wine-dark); }
.wine-card .wine-producer { font-size: 0.88rem; color: var(--gray); margin-top: 2px; }
.wine-card .tags { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  background: #f1e6ea;
  color: var(--wine-dark);
  font-size: 0.74rem;
  padding: 3px 8px;
  border-radius: 999px;
}
.tag.vintage { background: #eef2ea; color: #33552b; }
.wine-card .card-actions { margin-top: 10px; display: flex; gap: 8px; align-items: center; }
.pdf-link {
  display: inline-block;
  background: var(--wine);
  color: white;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
}
.source-badge {
  font-size: 0.7rem;
  color: var(--gray);
}

.empty-state {
  text-align: center;
  color: var(--gray);
  font-size: 0.9rem;
  padding: 30px 10px;
}

.upload-form {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.app-footer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--gray);
  margin-top: 30px;
}
.app-footer a { color: var(--gray); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-box {
  background: white;
  border-radius: 14px;
  padding: 18px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.modal-header h3 { margin: 0; color: var(--wine); }
.modal-header .btn { margin: 0; padding: 6px 10px; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-bottom: 14px;
}
.stats-table th, .stats-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.stats-table th { color: var(--gray); font-weight: 600; font-size: 0.78rem; }
.stats-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.stats-table td.fail { color: #b03030; }

.stats-recent {
  font-size: 0.78rem;
  color: var(--gray);
}
.stats-recent-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}
.stats-recent-item .ok { color: var(--success); }
.stats-recent-item .fail { color: #b03030; }
