:root {
  --ink: #181614;
  --muted: #6f6962;
  --paper: #f4f1ec;
  --card: #ffffff;
  --line: #ded8cf;
  --line-strong: #c8beb0;
  --gold: #b8874a;
  --gold-deep: #8d642f;
  --wine: #401b23;
  --danger: #a52b38;
  --success: #1f6a4d;
  --shadow: 0 16px 44px rgba(37, 29, 21, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 86% 0%, rgba(184, 135, 74, 0.13), transparent 27rem),
    var(--paper);
}

button, input, select { font: inherit; }

button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(18, 16, 14, 0.96);
  backdrop-filter: blur(12px);
}

.topbar-inner {
  width: min(1280px, calc(100% - 40px));
  min-height: 82px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  color: white;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 47px;
  height: 54px;
  display: block;
  flex: 0 0 auto;
}

.brand-logo img {
  width: 47px;
  height: 54px;
  object-fit: contain;
  display: block;
  filter: brightness(0) invert(1);
}

.brand span { display: grid; gap: 3px; }
.brand strong { font-family: Georgia, serif; font-size: 1.15rem; font-weight: 500; }
.brand small { color: #bbb3a8; font-size: 0.76rem; }

.page-shell {
  width: min(1280px, calc(100% - 40px));
  margin: 0 auto;
  padding: 52px 0 80px;
}

.intro {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 36px;
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold-deep);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1, h2 { font-family: Georgia, "Times New Roman", serif; }
h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.35rem); line-height: 1.02; font-weight: 500; }
h2 { margin: 0; font-size: 1.42rem; font-weight: 500; }
.muted { color: var(--muted); line-height: 1.55; }
.intro .muted { max-width: 720px; margin: 12px 0 0; }

.panel {
  overflow: hidden;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.wines-panel { overflow: visible; }

.panel-heading {
  min-height: 82px;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(100deg, #fff, #fbf8f4);
}

.panel-heading > div { display: flex; align-items: center; gap: 13px; }
.panel-heading p { margin: 0; color: var(--muted); font-size: 0.82rem; }
.step { color: var(--gold-deep); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; }

.form-grid {
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
}

.compact-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.field-short { max-width: 160px; }

.field { position: relative; min-width: 0; }
.field label {
  display: block;
  margin-bottom: 7px;
  color: #504a44;
  font-size: 0.78rem;
  font-weight: 700;
}

input, select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: white;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 135, 74, 0.15);
}

input.invalid, select.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(165, 43, 56, 0.1); }

.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.input-action .button { min-height: 44px; }
.field-note { display: block; margin-top: 6px; color: var(--muted); font-size: 0.72rem; line-height: 1.35; }
.notice-success { color: var(--success); }

.button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 750;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button-primary { background: var(--wine); color: white; }
.button-primary:hover { background: #53232d; }
.button-secondary { border-color: var(--line-strong); background: white; color: var(--ink); }
.button-ghost { border-color: rgba(255,255,255,.25); background: transparent; color: white; }
.button-ghost-dark { border-color: var(--line-strong); background: transparent; color: var(--muted); }
.button-full { width: 100%; }
.button:disabled { opacity: 0.58; cursor: wait; transform: none; }

.wine-table-wrap { padding: 0 24px 24px; }
.wine-table-header, .wine-row {
  display: grid;
  grid-template-columns: 68px minmax(135px, 1fr) minmax(160px, 1.35fr) 86px 100px 128px 110px 38px;
  gap: 8px;
  align-items: center;
}
.wine-table-header {
  min-height: 42px;
  color: var(--muted);
  font-size: 0.71rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.045em;
}
.wine-table-header span:nth-last-child(-n+3) { text-align: right; }
.wine-row {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.wine-row .field label { margin: 0; }
.wine-row input, .wine-row select { height: 40px; padding: 0 9px; }
.money-input { position: relative; }
.money-input span { position: absolute; top: 50%; left: 9px; transform: translateY(-50%); color: var(--muted); font-size: 0.82rem; }
.money-input input { padding-left: 26px; text-align: right; }
.line-total { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.remove-wine {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #8c8176;
  font-size: 1.5rem;
  line-height: 1;
}
.remove-wine:hover { background: #f7e9eb; color: var(--danger); }

.summary-card {
  margin: 26px 0 18px;
  padding: 23px 26px;
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  gap: 20px;
  border-radius: 16px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
}
.summary-card > div { display: grid; gap: 7px; }
.summary-label { color: #bdb5ab; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.08em; }
.summary-card strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.summary-total { text-align: right; }
.summary-total strong { color: #e4c08b; font-family: Georgia, serif; font-size: 2rem; font-weight: 500; }

.form-actions { display: flex; justify-content: flex-end; gap: 12px; padding-top: 10px; }
.button-generate { min-width: 230px; min-height: 50px; }
.spinner { display: none; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.35); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
.loading .spinner { display: block; }
.loading .button-text { opacity: .75; }
@keyframes spin { to { transform: rotate(360deg); } }

.alert { margin: 16px 0; padding: 13px 15px; border-radius: 9px; font-size: 0.9rem; }
.alert-error { border: 1px solid #e6b9bf; background: #fff0f2; color: #7e1f2b; }
.alert-success { border: 1px solid #b8d8ca; background: #eef9f4; color: #175c41; }
.hidden { display: none !important; }

.login-page { display: grid; place-items: center; padding: 28px; background: radial-gradient(circle at 50% 0%, #55483d 0, #1b1815 44%, #100f0d 100%); }
.login-shell { width: min(430px, 100%); }
.login-card { padding: 40px; border: 1px solid rgba(255,255,255,.12); border-radius: 20px; background: #fff; box-shadow: 0 25px 80px rgba(0,0,0,.32); }
.login-logo-frame { width: 125px; height: 143px; margin: 0 auto 20px; }
.login-logo { width: 125px; height: 143px; object-fit: contain; display: block; }
.login-card h1 { font-size: 2.2rem; }
.login-card .muted { margin: 12px 0 24px; }
.login-form { display: grid; gap: 12px; }
.login-form label { font-size: .8rem; font-weight: 750; }
.login-form .button { margin-top: 5px; }

.footer { padding: 24px 20px 32px; text-align: center; color: #8b8379; font-size: 0.75rem; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.autocomplete-menu {
  position: absolute;
  z-index: 50;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: white;
  box-shadow: 0 14px 32px rgba(37, 29, 21, 0.17);
}

.autocomplete-option {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  display: block;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-size: 0.84rem;
}

.autocomplete-option:hover,
.autocomplete-option.active {
  background: #f3eee7;
}

@media (max-width: 980px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wine-table-header { display: none; }
  .wine-rows { display: grid; gap: 14px; padding-top: 20px; }
  .wine-row {
    position: relative;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fdfbf8;
  }
  .wine-row .field::before, .line-total::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: .7rem;
    font-weight: 800;
    text-transform: uppercase;
  }
  .line-total { align-self: end; min-height: 40px; padding: 11px 0; }
  .remove-wine { position: absolute; top: 7px; right: 7px; }
}

@media (max-width: 680px) {
  .topbar-inner, .page-shell { width: min(100% - 24px, 1280px); }
  .topbar-inner { min-height: 66px; }
  .brand-logo { width: 36px; height: 42px; }
  .brand-logo img { width: 36px; height: 42px; }
  .brand small { display: none; }
  .brand strong { font-size: 1rem; }
  .page-shell { padding: 32px 0 58px; }
  .intro { align-items: flex-start; flex-direction: column; gap: 18px; }
  .panel { border-radius: 14px; }
  .panel-heading { align-items: flex-start; flex-direction: column; padding: 18px; }
  .panel-heading p { display: none; }
  .wines-heading { flex-direction: row; align-items: center; }
  .form-grid { grid-template-columns: 1fr; padding: 18px; gap: 16px; }
  .compact-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .field-short { max-width: none; }
  .wine-table-wrap { padding: 0 14px 16px; }
  .wine-row { grid-template-columns: 1fr; padding: 16px; padding-top: 25px; }
  .summary-card { grid-template-columns: 1fr 1fr; padding: 20px; }
  .summary-total { grid-column: 1 / -1; padding-top: 15px; border-top: 1px solid rgba(255,255,255,.14); text-align: left; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
  .login-page { padding: 14px; }
  .login-card { padding: 28px 22px; }
  .input-action { grid-template-columns: 1fr; }
}

@media print { .topbar, .footer { display: none; } }
