:root {
  --bg: #f7f2ec;
  --card: #ffffff;
  --ink: #2a1a1f;
  --muted: #7a6a6e;
  --line: #e7ddd3;
  --wine: #7b1e3a;
  --wine-soft: #f3e3e7;
  --gold: #b8860b;
  --ok: #2e7d4f;
  --warn: #b26a00;
  --late: #a33;
  --rouge: #7b1e3a;
  --blanc: #e6c86e;
  --rose: #e79aa8;
  --bulles: #c9b98f;
  --liquoreux: #c98a2b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1416; --card: #261c1f; --ink: #f3e9e4; --muted: #b3a2a6;
    --line: #3a2b30; --wine: #d65a7c; --wine-soft: #3a2027;
    --ok: #5cbf86; --warn: #e0a040; --late: #e06b6b;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1416; --card: #261c1f; --ink: #f3e9e4; --muted: #b3a2a6;
  --line: #3a2b30; --wine: #d65a7c; --wine-soft: #3a2027;
  --ok: #5cbf86; --warn: #e0a040; --late: #e06b6b;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: Inter, system-ui, sans-serif; font-size: 15px;
}
header {
  background: linear-gradient(135deg, #4a0f22, #7b1e3a 60%, #9c2f4f);
  color: #fff; padding: 28px 16px 72px;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
header .wrap { padding: 0; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
h1 { font-family: "Cormorant Garamond", serif; font-size: 42px; margin: 0; letter-spacing: .5px; }
header p { margin: 4px 0 0; opacity: .8; }
.home-link { color: inherit; text-decoration: none; }
.account { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.pill {
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25);
  padding: 6px 11px; border-radius: 999px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.account button {
  background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.45);
  border-radius: 999px; padding: 6px 12px; font: inherit; cursor: pointer;
}
.account button:hover { background: rgba(255,255,255,.12); }

.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-top: -48px;
}
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; box-shadow: 0 6px 20px rgba(60,20,30,.08);
}
.stat b { display: block; font-size: 28px; font-family: "Cormorant Garamond", serif; color: var(--wine); }
.stat span { color: var(--muted); font-size: 13px; }
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 20px 0 14px;
}
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
.toolbar select { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--wine); outline-offset: -1px; }
.search { flex: 1 1 220px; width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 7px 12px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--wine); color: #fff; border-color: var(--wine); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); }
.btn {
  background: var(--wine); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--wine); border: 1px solid var(--wine); }
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .6; cursor: wait; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; padding-bottom: 40px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; display: flex; gap: 14px; position: relative;
}
.card.empty { opacity: .55; }
.bottle { flex: 0 0 34px; }
.info { flex: 1; min-width: 0; }
.name { font-family: "Cormorant Garamond", serif; font-size: 22px; font-weight: 700; line-height: 1.1; padding-right: 52px; overflow-wrap: anywhere; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px; }
.b-ok { background: rgba(46,125,79,.14); color: var(--ok); }
.b-peak { background: rgba(184,134,11,.16); color: var(--gold); }
.b-wait { background: rgba(178,106,0,.14); color: var(--warn); }
.b-late { background: rgba(170,51,51,.14); color: var(--late); }
.b-none { background: var(--wine-soft); color: var(--muted); }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.qty button { background: none; border: 0; color: var(--ink); width: 34px; height: 34px; font-size: 18px; cursor: pointer; }
.qty button:hover { background: var(--wine-soft); }
.qty span { min-width: 28px; text-align: center; font-weight: 600; }
.stars { color: var(--gold); letter-spacing: 1px; font-size: 15px; }
.stars .off { color: var(--line); }
.notes { font-size: 13px; color: var(--muted); margin-top: 8px; font-style: italic; overflow-wrap: anywhere; }
.actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 2px; }
.icon { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 4px 6px; border-radius: 6px; font-size: 14px; }
.icon:hover { background: var(--wine-soft); color: var(--wine); }
.nothing { text-align: center; color: var(--muted); padding: 50px 0; grid-column: 1/-1; }

dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow: auto;
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(30,10,15,.55); }
form.f { padding: 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
form.f h2 { grid-column: 1/-1; margin: 0 0 4px; font-family: "Cormorant Garamond", serif; font-size: 28px; }
form.f label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
form.f .full { grid-column: 1/-1; }
form.f p { margin: 0; }
.window { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.window legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.rate-in { display: flex; gap: 4px; font-size: 26px; cursor: pointer; color: var(--line); user-select: none; }
.rate-in .on { color: var(--gold); }
.f-actions { grid-column: 1/-1; display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.err { color: var(--late); font-size: 13px; }
.link { background: none; border: 0; color: var(--wine); font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: 34px; }
  form.f { grid-template-columns: 1fr; }
  .window { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  #statusChips { margin-left: 0 !important; }
}
