:root {
  --bg: #f7f3ee;
  --surface: #ffffff;
  --ink: #2b2422;
  --muted: #7a6f6a;
  --line: #e6ddd4;
  --wine: #7b1e3a;
  --wine-soft: #f3e3e8;
  --ok: #2f6b3f;
  --ok-soft: #e2f0e5;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --bad: #a3242b;
  --bad-soft: #f8e1e2;
  --radius: 10px;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 Inter, system-ui, sans-serif; }
a { color: var(--wine); }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 600; line-height: 1.2; }
h1 { font-size: 1.8rem; margin: 0 0 .25rem; }
h2 { font-size: 1.25rem; margin: 2rem 0 .75rem; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem; padding: .75rem 1rem; background: var(--wine); color: #fff; }
.topbar a { color: #fff; text-decoration: none; }
.topbar__who { margin-left: auto; opacity: .85; }
.brand { font-family: Fraunces, Georgia, serif; font-size: 1.3rem; font-weight: 600; }
.brand { display: inline-flex; align-items: center; gap: .4rem; }
.brand__mark { height: 2.2rem; width: auto; }
.login__mark { display: block; height: 7rem; width: auto; margin: 0 auto .5rem; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; }
.nav a { opacity: .9; }
.nav a:hover { opacity: 1; text-decoration: underline; }
.nav__scan { background: #fff; color: var(--wine) !important; padding: .15rem .7rem; border-radius: 99px; font-weight: 600; }
.nav__logout { background: none; border: 0; color: #fff; opacity: .7; cursor: pointer; font: inherit; padding: 0; }

.page { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.lead { color: var(--muted); margin: 0 0 1.5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: ui-monospace, monospace; }

.flash { padding: .75rem 1rem; border-radius: var(--radius); margin: 0 0 1rem; }
.flash--notice { background: var(--ok-soft); color: var(--ok); }
.flash--alert { background: var(--bad-soft); color: var(--bad); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat { font-family: Fraunces, Georgia, serif; font-size: 2rem; }

.header-row { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }

.btn, button, input[type=submit] {
  display: inline-block; border: 1px solid var(--wine); background: var(--wine); color: #fff; border-radius: 8px;
  padding: .5rem 1rem; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn--ghost { background: transparent; color: var(--wine); }
.btn--small { padding: .2rem .6rem; font-size: .875rem; font-weight: 400; }
.btn--ok { background: var(--ok); border-color: var(--ok); }
.btn--bad { background: transparent; color: var(--bad); border-color: var(--bad); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
table input { width: 100%; min-width: 4rem; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .8rem; font-weight: 600; background: var(--line); }
.badge--draft { background: var(--line); }
.badge--sent, .badge--expected { background: var(--warn-soft); color: var(--warn); }
.badge--received, .badge--in_stock { background: var(--ok-soft); color: var(--ok); }
.badge--sold { background: var(--wine-soft); color: var(--wine); }
.badge--missing, .badge--damaged { background: var(--bad-soft); color: var(--bad); }

form .field { margin-bottom: 1rem; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff;
}
textarea { min-height: 5rem; }
.form-grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.errors { background: var(--bad-soft); color: var(--bad); padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }

.scan { display: flex; gap: .5rem; margin-bottom: 1rem; }
.scan input { font-size: 1.4rem; font-family: ui-monospace, monospace; text-transform: uppercase; }
.scan-result { min-height: 2.75rem; }
.camera { width: 100%; max-width: 420px; border-radius: var(--radius); background: #000; margin-bottom: 1rem; }
.camera[hidden] { display: none; }

.portal-link { display: flex; gap: .5rem; align-items: center; }
.portal-link input { font-family: ui-monospace, monospace; font-size: .85rem; }

.barcode svg { max-width: 260px; height: auto; }
.qr svg { width: 160px; height: 160px; }

.login { max-width: 380px; margin: 3rem auto; }

@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .hide-mobile { display: none; }
  .wine-rows td { display: block; border: 0; padding: .25rem .75rem; }
  .wine-rows tr { display: block; border-bottom: 1px solid var(--line); padding: .5rem 0; }
  .wine-rows thead { display: none; }
  .wine-rows td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--muted); }
}

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .5rem 1.5rem; margin: 0; }
.facts dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
