/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --accent: #007AFF;
  --accent-light: #E8F1FF;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #1C1C1E;
  --text-secondary: #6C6C70;
  --separator: #E5E5EA;
  --destructive: #FF3B30;
  --success: #34C759;
  --radius-card: 12px;
  --radius-btn: 10px;
  --radius-input: 10px;
  --header-height: 56px;
  --sidebar-width: 280px;
  --max-width: 480px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
}

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.page-wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

.page-content {
  padding: 16px;
  padding-top: calc(var(--header-height) + 16px);
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-width);
  height: var(--header-height);
  background: var(--card);
  border-bottom: 1px solid var(--separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  z-index: 100;
}

.header-btn {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-btn);
  padding: 0 8px;
  -webkit-tap-highlight-color: transparent;
}

.header-btn:active { background: var(--accent-light); }

.header-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.hamburger-icon {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 22px;
}

.hamburger-icon span {
  display: block;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  transition: all 0.2s;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
}

.sidebar-overlay.active { display: block; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--card);
  z-index: 300;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}

.sidebar.active { transform: translateX(0); }

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--separator);
}

.sidebar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.sidebar-close {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 24px;
  border-radius: 50%;
}

.sidebar-nav {
  list-style: none;
  padding: 8px 0;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  color: var(--text);
  font-size: 17px;
  font-weight: 400;
  min-height: 44px;
  transition: background 0.15s;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
  background: var(--accent-light);
  color: var(--accent);
}

.sidebar-nav li a .nav-icon {
  width: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--separator);
}

.sidebar-footer a {
  display: block;
  color: var(--text-secondary);
  font-size: 15px;
  padding: 8px 0;
}

/* ── Flash Messages ───────────────────────────────────────────────────────── */
.flash-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-card);
  font-size: 14px;
  font-weight: 500;
}

.flash.success { background: #D1F5DC; color: #1A6B31; }
.flash.error { background: #FFE5E3; color: #8B1A14; }
.flash.info { background: var(--accent-light); color: #004C99; }

/* ── Search & Sort ────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 16px 0 40px;
  background: var(--card);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236C6C70' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}

.search-input:focus { border-color: var(--accent); }

.sort-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-label {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  font-weight: 500;
}

.sort-select {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  background: var(--card);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  font-size: 14px;
  color: var(--text);
  outline: none;
  appearance: auto;
}

/* ── Wine Cards ───────────────────────────────────────────────────────────── */
.wine-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wine-card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.15s;
}

.wine-card:active { box-shadow: var(--shadow-md); }

.wine-card-body { flex: 1; min-width: 0; }

.wine-card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wine-card-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.wine-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.wine-card-ratings {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.rating-main {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.rating-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.tasting-count {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Wine Detail ──────────────────────────────────────────────────────────── */
.detail-card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.detail-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

.detail-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-row {
  display: flex;
  gap: 8px;
}

.detail-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  min-width: 90px;
  padding-top: 1px;
}

.detail-value {
  font-size: 15px;
  color: var(--text);
  flex: 1;
}

.detail-ratings {
  display: flex;
  gap: 20px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--separator);
}

.detail-rating-block {
  text-align: center;
}

.detail-rating-num {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.detail-rating-lbl {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

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

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

/* ── Tasting Cards ────────────────────────────────────────────────────────── */
.tasting-card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.tasting-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.tasting-taster {
  font-weight: 600;
  font-size: 16px;
}

.tasting-rating {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.tasting-date {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.tasting-notes {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 10px;
}

.tasting-card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.tasting-wine-title {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-btn);
  font-size: 16px;
  font-weight: 600;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { opacity: 0.8; transform: scale(0.98); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary {
  background: var(--separator);
  color: var(--text);
}
.btn-destructive { background: var(--destructive); color: #fff; }
.btn-ghost {
  background: none;
  color: var(--accent);
  padding: 0 8px;
  min-height: 36px;
}
.btn-sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 14px;
  border-radius: 8px;
}
.btn-sm-destructive {
  min-height: 36px;
  padding: 0 14px;
  font-size: 14px;
  border-radius: 8px;
  background: none;
  color: var(--destructive);
  border: 1px solid var(--destructive);
}
.btn-sm-destructive:active { background: #FFE5E3; }

.btn-full { width: 100%; }

.btn-group {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
  overflow: hidden;
}

.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus { border-color: var(--accent); background: #fff; }

textarea.form-input {
  height: auto;
  min-height: 100px;
  padding: 12px 14px;
  resize: vertical;
  line-height: 1.5;
}

/* ── Segmented Control (Taster) ───────────────────────────────────────────── */
.segmented {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  padding: 3px;
  gap: 3px;
}

.segmented input[type="radio"] { display: none; }

.segmented label {
  flex: 1;
  text-align: center;
  padding: 10px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.segmented input[type="radio"]:checked + label {
  background: var(--card);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* ── Star Rating ──────────────────────────────────────────────────────────── */
.star-rating {
  display: flex;
  gap: 2px;
  justify-content: center;
}

.star-btn {
  background: none;
  border: none;
  padding: 4px 2px;
  cursor: pointer;
  color: var(--separator);
  transition: color 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  line-height: 0;
}

.star-btn.filled {
  color: #FFB800;
}

.star-btn.filled svg polygon {
  fill: currentColor;
}

.star-btn:active { transform: scale(0.88); }

/* ── Varietal Tags ────────────────────────────────────────────────────────── */
.varietal-input-wrapper {
  position: relative;
}

.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.varietal-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
}

.varietal-tag-remove {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  opacity: 0.7;
}

.varietal-tag-remove:hover { opacity: 1; }

.varietal-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--separator);
  border-radius: var(--radius-input);
  box-shadow: var(--shadow-md);
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 4px;
}

.varietal-suggestion {
  padding: 12px 14px;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.1s;
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--separator);
  color: var(--text);
}

.varietal-suggestion:last-child { border-bottom: none; }
.varietal-suggestion:hover { background: var(--bg); }
.varietal-suggestion.create { color: var(--accent); font-weight: 500; }

/* ── Scan Button ──────────────────────────────────────────────────────────── */
.scan-btn {
  width: 100%;
  min-height: 52px;
  background: var(--accent-light);
  color: var(--accent);
  border: 1.5px dashed var(--accent);
  border-radius: var(--radius-card);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
}

.scan-btn:active { background: var(--accent); color: #fff; }

.scan-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 500;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.scan-modal.active { display: flex; }

.scan-video-wrapper {
  width: 100%;
  max-width: 400px;
  position: relative;
}

.scan-video {
  width: 100%;
  border-radius: 12px;
}

.scan-overlay-text {
  color: #fff;
  text-align: center;
  margin-bottom: 20px;
  font-size: 16px;
}

.scan-close-btn {
  margin-top: 20px;
  padding: 12px 32px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-btn);
  font-size: 16px;
  font-weight: 600;
}

.scan-unavailable {
  display: none;
  padding: 12px 16px;
  background: #FFF3CD;
  color: #7D5300;
  border-radius: var(--radius-input);
  font-size: 14px;
  margin-bottom: 16px;
}

.upc-notice {
  padding: 12px 16px;
  border-radius: var(--radius-input);
  font-size: 14px;
  margin-bottom: 12px;
  display: none;
}

.upc-notice.info { background: var(--accent-light); color: #004C99; }
.upc-notice.warning { background: #FFF3CD; color: #7D5300; }

/* ── Tastings Filters ─────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.filter-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filter-group {
  flex: 1;
  min-width: 0;
}

.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.filter-input {
  width: 100%;
  max-width: 100%;
  height: 38px;
  padding: 0 10px;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  outline: none;
}

.filter-input:focus { border-color: var(--accent); }

.taster-tabs {
  display: flex;
  gap: 6px;
}

.taster-tab {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  border: 1.5px solid var(--separator);
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  min-height: 36px;
}

.taster-tab.active,
.taster-tab:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary);
}

.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-text { font-size: 16px; font-weight: 500; margin-bottom: 4px; color: var(--text); }
.empty-state-sub { font-size: 14px; }

.result-count {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 8px 0 4px;
  margin-bottom: 4px;
}

.load-more-btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin-top: 8px;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}
.load-more-btn:active { opacity: 0.7; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo h1 {
  font-size: 36px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
}

.login-logo p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Settings ─────────────────────────────────────────────────────────────── */
.settings-section {
  margin-bottom: 28px;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  padding-left: 4px;
}

/* ── Placeholder pages ────────────────────────────────────────────────────── */
.placeholder-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
}

.placeholder-page h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-top: 16px;
  margin-bottom: 8px;
}

.placeholder-page p { font-size: 15px; }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.text-muted { color: var(--text-secondary); font-size: 14px; }
.divider { height: 1px; background: var(--separator); margin: 16px 0; }

/* ── HTMX loading indicator ───────────────────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }

/* ── Add Tasting button (fixed bottom) ────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 24px;
  right: 50%;
  transform: translateX(calc(50% - 16px));
  max-width: calc(var(--max-width) - 32px);
  width: calc(100% - 32px);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-btn);
  min-height: 52px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,122,255,0.35);
  z-index: 90;
}

@media (min-width: 480px) {
  .fab {
    right: calc(50% - 240px + 16px);
    transform: none;
    width: calc(var(--max-width) - 32px);
  }
}

/* ── UPC duplicate prompt ─────────────────────────────────────────────────── */
.upc-duplicate-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 400;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

.upc-duplicate-modal.active { display: flex; }

.upc-duplicate-sheet {
  background: var(--card);
  border-radius: 20px;
  padding: 24px 20px;
  width: 100%;
  max-width: var(--max-width);
}

.upc-duplicate-title {
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.upc-duplicate-sub {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 20px;
}

.upc-duplicate-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
