:root {
  --wine: #5b1a2e;
  --wine-2: #7a2440;
  --bg: #faf7f5;
  --card: #ffffff;
  --ink: #2a2024;
  --muted: #8a7d82;
  --line: #ece4e6;
  --ok: #2e7d5b;
  --danger: #b23a48;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: none;
  padding-bottom: calc(96px + var(--safe-bot));
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 18px 12px;
  background: var(--wine);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: .5px; margin: 0; }
.icon-btn {
  background: transparent; border: none; color: #fff;
  font-size: 22px; padding: 4px 8px; cursor: pointer;
}

.view { padding: 16px; max-width: 640px; margin: 0 auto; }

/* List */
.bottle-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.bottle-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.bottle-card:active { transform: scale(.995); }
.bc-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.bc-name { font-weight: 650; font-size: 16px; line-height: 1.25; }
.bc-vintage { color: var(--wine-2); font-weight: 700; font-size: 15px; white-space: nowrap; }
.bc-sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; }
.bc-meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.bc-meta b { color: var(--ink); font-weight: 600; }

.empty { text-align: center; padding: 64px 20px; color: var(--muted); }
.empty-glass { font-size: 54px; }
.empty p { margin: 6px 0; }

/* Form */
.edit-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.edit-title { font-weight: 700; }
.link-btn { background: none; border: none; color: var(--wine-2); font-size: 15px; cursor: pointer; padding: 6px 0; }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
input, textarea, select {
  font: inherit; padding: 12px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--wine-2); border-color: transparent; }
textarea { min-height: 76px; resize: vertical; }
.hint { font-size: 12px; color: var(--muted); }
.hint a { color: var(--wine-2); }
.rule { border: none; border-top: 1px solid var(--line); margin: 18px 0 4px; }

.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.data-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.btn-primary, .btn-secondary {
  font: inherit; font-weight: 650; padding: 13px 16px; border-radius: 12px; cursor: pointer; flex: 1;
}
.btn-primary { background: var(--wine); color: #fff; border: none; }
.btn-primary:disabled { opacity: .5; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
#edit-delete { flex: 0 0 auto; color: var(--danger); border-color: #f0d9dc; }

/* Extract status */
.extract-status {
  background: #fff5f2; border: 1px solid #f3ddd6; color: var(--wine-2);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px;
  display: flex; align-items: center; gap: 10px;
}
.extract-status.err { background: #fdecec; border-color: #f4c9c9; color: var(--danger); }
.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(122,36,64,.25);
  border-top-color: var(--wine-2); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* FAB */
.fab {
  position: fixed; right: 20px; bottom: calc(20px + var(--safe-bot)); z-index: 20;
  width: 64px; height: 64px; border-radius: 50%; border: none;
  background: var(--wine); color: #fff; box-shadow: 0 6px 18px rgba(91,26,46,.45);
  cursor: pointer;
}
.fab-plus { font-size: 34px; line-height: 1; display: block; margin-top: -2px; }
.fab:active { transform: scale(.94); }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bot)); z-index: 40;
  background: #2a2024; color: #fff; padding: 11px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.25); max-width: 88%;
}

/* Back-label prompt */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,12,16,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  background: var(--card); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; padding: 22px 20px calc(22px + var(--safe-bot));
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 -6px 24px rgba(0,0,0,.2);
}
.sheet-title { font-size: 17px; font-weight: 700; }
.sheet-text { margin: 0 0 6px; font-size: 14px; color: var(--muted); line-height: 1.45; }
.sheet-card .btn-primary, .sheet-card .btn-secondary { flex: none; width: 100%; }

.empty .tiny { font-size: 12.5px; line-height: 1.5; max-width: 34ch; margin: 18px auto 0; opacity: .85; }

/* Sheet connection result */
.hint.ok  { color: var(--ok); font-weight: 600; }
.hint.err { color: var(--danger); font-weight: 600; }
code { background: #f3edef; padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.normal { font-weight: 400; }
