/* =========================================================
   THE CELLAR BOOK — leather-bound wine list, restaurant-style
   Palette: deep espresso leather, gold foil stamping, parchment.
   Typography is entirely serif (Cormorant Garamond + EB Garamond)
   to hold the "printed menu" illusion — a deliberate departure
   from typical sans-serif UI chrome.
   ========================================================= */

:root {
  /* ---- Color tokens ---- */
  --leather-900: #241209;   /* outer cover / page background */
  --leather-800: #331b0e;   /* panel / header band */
  --leather-700: #452712;   /* card & input surface */
  --stitch: #8a5a2b;        /* saddle-stitch thread tone */
  --parchment: #ecdfc2;     /* menu paper / primary text */
  --parchment-dim: #b9a67e; /* secondary text on leather */
  --gold: #c9a24b;          /* foil-stamp gold */
  --gold-bright: #e3c374;
  --wine: #5c1922;          /* bordeaux accent, price/divider */
  --wine-bright: #7a222d;
  --green-ok: #7a8f5c;

  --font-display: "Cormorant Garamond", "Georgia", serif;
  --font-body: "EB Garamond", "Georgia", serif;

  --radius: 3px;
  --shadow-card: 0 3px 14px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(0,0,0,0) 0%, rgba(0,0,0,0.35) 100%),
    var(--leather-900);
  color: var(--parchment);
  font-family: var(--font-body);
  min-height: 100vh;
  letter-spacing: 0.01em;
}

/* ---------- Bound-book shell ---------- */

.app-shell {
  max-width: 1080px;
  margin: 28px auto;
  padding: 40px 48px 80px 64px;
  position: relative;
  background: linear-gradient(180deg, var(--leather-800), var(--leather-900) 60%);
  border: 1px solid #1a0d05;
  border-radius: 8px;
  box-shadow:
    0 20px 60px rgba(0,0,0,0.55),
    inset 0 0 0 1px rgba(201,162,75,0.08);
}

/* Saddle-stitched border, set slightly inside the cover edge */
.app-shell::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px dashed rgba(201, 162, 75, 0.35);
  border-radius: 4px;
  pointer-events: none;
}

/* The "spine" — a raised vertical band along the left edge, like a bound book */
.app-shell::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 26px;
  background: linear-gradient(90deg, #180b04, var(--leather-800));
  border-right: 1px solid rgba(201,162,75,0.15);
  border-radius: 8px 0 0 8px;
  pointer-events: none;
}

/* Ribbon bookmark tab, top right, the signature detail */
.ribbon-tab {
  position: absolute;
  top: -6px;
  right: 56px;
  width: 22px;
  height: 74px;
  background: linear-gradient(180deg, var(--wine-bright), var(--wine));
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* ---------- Header (gold foil stamp) ---------- */

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 22px;
  border-bottom: 1px solid rgba(201,162,75,0.3);
}

.app-title {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin: 0;
  color: var(--gold-bright);
  text-shadow:
    0 1px 0 rgba(0,0,0,0.6),
    0 -1px 0 rgba(255,230,180,0.15);
}

.app-title span {
  font-style: italic;
  color: var(--parchment);
}

.app-subtitle {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-style: italic;
  color: var(--parchment-dim);
  margin-top: 6px;
}

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

/* ---------- Buttons (menu-card style, not app-style) ---------- */

.btn {
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 9px 20px;
  border-radius: var(--radius);
  border: 1px solid rgba(201,162,75,0.4);
  background: transparent;
  color: var(--parchment);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { background: rgba(201,162,75,0.1); border-color: var(--gold); }

.btn-primary {
  background: var(--wine);
  border-color: var(--wine-bright);
  color: var(--parchment);
}
.btn-primary:hover { background: var(--wine-bright); }

.btn-gold {
  border-color: var(--gold);
  color: var(--gold-bright);
}
.btn-gold:hover { background: rgba(201, 162, 39, 0.12); }

.btn-small { padding: 5px 12px; font-size: 0.82rem; }

.btn-danger { color: #d3a2a2; border-color: #6a3232; }
.btn-danger:hover { background: rgba(211, 162, 162, 0.08); }

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.search-input {
  flex: 1 1 260px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(201,162,75,0.35);
  background: rgba(0,0,0,0.2);
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 1rem;
  font-style: italic;
}
.search-input::placeholder { color: var(--parchment-dim); font-style: italic; }
.search-input:focus { outline: none; border-color: var(--gold); }

.sort-select {
  padding: 9px 10px;
  border-radius: var(--radius);
  border: 1px solid rgba(201,162,75,0.35);
  background: rgba(0,0,0,0.2);
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 0.92rem;
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.chip {
  padding: 5px 16px;
  border-radius: 999px;
  border: 1px solid rgba(201,162,75,0.3);
  background: transparent;
  color: var(--parchment-dim);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-style: italic;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.chip.active {
  background: var(--wine);
  border-color: var(--wine-bright);
  color: var(--parchment);
  font-style: normal;
}

.bottle-count {
  color: var(--parchment-dim);
  font-size: 0.85rem;
  font-style: italic;
  margin-bottom: 10px;
}

/* ---------- Wine-list entries (menu lines, not cards) ---------- */

.type-section { margin-bottom: 8px; }

.type-section-heading {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  border-bottom: 1px solid rgba(201,162,75,0.25);
  padding-bottom: 6px;
  margin: 22px 0 6px;
}
.type-section:first-child .type-section-heading { margin-top: 0; }

.bottle-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 13px 2px;
  border-bottom: 1px dotted rgba(201,162,75,0.22);
}
.bottle-row:hover { background: rgba(201,162,75,0.05); }

.bottle-row-main {
  flex: 1;
  min-width: 0;
}

.bottle-name-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.bottle-name {
  font-family: var(--font-display);
  font-size: 1.28rem;
  font-weight: 600;
  color: var(--parchment);
  margin: 0;
  white-space: nowrap;
}

.bottle-leader {
  flex: 1;
  border-bottom: 1px dotted rgba(201,162,75,0.35);
  min-width: 20px;
  transform: translateY(-4px);
}

.bottle-vintage {
  font-family: var(--font-body);
  font-size: 1.05rem;
  color: var(--gold-bright);
  white-space: nowrap;
}

.bottle-meta {
  font-size: 0.86rem;
  font-style: italic;
  color: var(--parchment-dim);
  margin-top: 3px;
}

.bottle-qty {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
}
.qty-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green-ok);
}
.qty-dot.empty { background: rgba(201,162,75,0.25); }

.bottle-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--parchment-dim);
  font-style: italic;
  font-size: 1.1rem;
}
.empty-state .btn { margin-top: 16px; font-style: normal; }

/* ---------- Modal (a single leaf from the book) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 6, 3, 0.75);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}

.modal {
  background: linear-gradient(180deg, var(--leather-800), var(--leather-900));
  border: 1px solid rgba(201,162,75,0.3);
  border-radius: 6px;
  max-width: 580px;
  width: 100%;
  padding: 30px 32px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.modal h2 {
  font-family: var(--font-display);
  color: var(--gold-bright);
  margin-top: 0;
  font-size: 1.7rem;
  letter-spacing: 0.02em;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }

label {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-style: italic;
  letter-spacing: 0.02em;
  color: var(--parchment-dim);
  display: block;
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border-radius: 3px;
  border: 1px solid rgba(201,162,75,0.3);
  background: rgba(0,0,0,0.25);
  color: var(--parchment);
  font-family: var(--font-body);
  font-size: 1rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

/* ---------- Similar bottle hints ---------- */

.similar-hint-list { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.similar-hint-item {
  font-size: 0.85rem;
  font-style: italic;
  color: var(--parchment-dim);
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(201,162,75,0.25);
  border-radius: 3px;
  padding: 6px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.similar-hint-item button { font-size: 0.78rem; padding: 4px 10px; font-style: normal; }

/* ---------- Analytics ("The Ledger") ---------- */

.modal-wide { max-width: 780px; }

.ledger-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin: 18px 0 24px;
}

.ledger-stat {
  border: 1px solid rgba(201,162,75,0.3);
  border-radius: 4px;
  padding: 12px 14px;
  background: rgba(0,0,0,0.15);
}

.ledger-stat-value {
  font-family: var(--font-display);
  font-size: 1.7rem;
  color: var(--gold-bright);
  line-height: 1.1;
}

.ledger-stat-label {
  font-size: 0.78rem;
  font-style: italic;
  color: var(--parchment-dim);
  margin-top: 4px;
}

.ledger-breakdowns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}
@media (max-width: 640px) {
  .ledger-breakdowns { grid-template-columns: 1fr; }
}

.ledger-group-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  border-bottom: 1px solid rgba(201,162,75,0.25);
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.ledger-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 0.88rem;
}

.ledger-bar-label {
  flex: 0 0 100px;
  color: var(--parchment);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ledger-bar-track {
  flex: 1;
  background: rgba(0,0,0,0.25);
  border-radius: 2px;
  height: 8px;
  overflow: hidden;
}

.ledger-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--wine), var(--gold));
  border-radius: 2px;
}

.ledger-bar-count {
  flex: 0 0 auto;
  color: var(--parchment-dim);
  font-size: 0.8rem;
}

.ledger-empty {
  color: var(--parchment-dim);
  font-style: italic;
  font-size: 0.85rem;
}

/* ---------- Bottle lookup (grapeminds API) ---------- */

#lookupResults {
  margin-top: 8px;
}
#lookupResults .similar-hint-list { margin-top: 0; }

/* ---------- Focus visibility ---------- */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .app-shell { padding: 28px 20px 60px 34px; margin: 12px; }
  .app-shell::after { width: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .app-title { font-size: 2rem; }
  .bottle-row { flex-wrap: wrap; }
  .bottle-leader { display: none; }
  .ribbon-tab { right: 24px; }
}

/* ---------- View tabs (Cellar / Restaurant Log) ---------- */

.view-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(201,162,75,0.25);
}

.tab-btn {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.03em;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--parchment-dim);
  padding: 8px 4px 10px;
  margin-right: 24px;
  cursor: pointer;
}
.tab-btn.active {
  color: var(--gold-bright);
  border-bottom-color: var(--gold);
}

.header-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

/* ---------- Tags ---------- */

.tag-checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.tag-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-style: normal;
  color: var(--parchment);
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  margin-bottom: 0;
}
.tag-check input { width: auto; }

.bottle-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}
.bottle-tag-pill {
  font-size: 0.7rem;
  font-style: italic;
  color: var(--gold-bright);
  border: 1px solid rgba(201,162,75,0.35);
  border-radius: 999px;
  padding: 1px 9px;
}

/* ---------- Pairing result ---------- */

.pairing-result { margin-top: 16px; border-top: 1px solid rgba(201,162,75,0.25); padding-top: 16px; }

.pairing-pick {
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(201,162,75,0.3);
  border-radius: 4px;
  padding: 14px;
  margin-bottom: 10px;
}
.pairing-pick .bottle-name { font-size: 1.1rem; white-space: normal; }
.pairing-reason {
  font-size: 0.9rem;
  color: var(--parchment-dim);
  margin-top: 6px;
  font-style: italic;
}

/* ---------- Cellar map ---------- */

#mapGrid {
  display: grid;
  gap: 6px;
  margin: 16px 0;
}

.map-cell {
  border: 1px solid rgba(201,162,75,0.3);
  border-radius: 3px;
  background: rgba(0,0,0,0.2);
  padding: 6px 4px;
  min-height: 58px;
  font-size: 0.72rem;
  color: var(--parchment-dim);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.map-cell:hover { border-color: var(--gold); background: rgba(201,162,75,0.08); }
.map-cell.occupied {
  background: rgba(92,25,34,0.35);
  color: var(--parchment);
}
.map-cell-slot { font-size: 0.65rem; color: var(--parchment-dim); }
.map-cell-name { font-family: var(--font-display); font-size: 0.82rem; line-height: 1.15; }

.map-legend {
  font-size: 0.78rem;
  color: var(--parchment-dim);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
}

.layout-editor-rack {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.layout-editor-rack input[type="text"] { width: 140px; }
.layout-editor-rack input[type="number"] { width: 80px; }

/* ---------- Toast (undo delete) ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--leather-800);
  border: 1px solid rgba(201,162,75,0.4);
  border-radius: 6px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 100;
  font-size: 0.9rem;
  color: var(--parchment);
}
