:root {
  --wine: #722f37; --wine-dark: #4a1f24; --gold: #c9a227;
  --bg: #f7f4f0; --card: #ffffff; --ink: #2b2420; --muted: #8a7f78;
  --line: #ece5df;
  --yellow-bg: #fde68a; --yellow-ink: #78350f; --yellow-br: #d97706;
  --green-bg: #bbf7d0; --green-ink: #14532d; --green-br: #16a34a;
  --red-bg: #fecaca; --red-ink: #7f1d1d; --red-br: #dc2626;
}
* { box-sizing: border-box; }
body {
  font: 14.5px/1.55 -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink); margin: 0;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  background: var(--card); border-bottom: 3px solid var(--wine);
  padding: 12px 4vw; box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.brand { font-size: 20px; font-weight: 800; color: var(--wine-dark); letter-spacing: .5px; }
.brand span { color: var(--gold); }
.brand small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.brand.big { font-size: 30px; }
.topbar nav { display: flex; gap: 6px; }
.topbar nav a {
  text-decoration: none; color: var(--wine); padding: 7px 14px; border-radius: 8px;
  font-weight: 600;
}
.topbar nav a:hover { background: var(--bg); }
.topbar nav a.active { background: var(--wine); color: #fff; }
.userbox { margin-left: auto; color: var(--muted); font-size: 13px; }
.userbox a { color: var(--wine); }
.role {
  background: var(--gold); color: #3a2c00; border-radius: 5px; padding: 1px 7px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
}

main { padding: 22px 4vw 60px; max-width: 1200px; margin: 0 auto; }

/* ---------- flash ---------- */
.flash { margin: 14px 4vw 0; padding: 11px 16px; border-radius: 9px; font-weight: 600; }
.flash.success { background: var(--green-bg); color: var(--green-ink); }
.flash.error { background: var(--red-bg); color: var(--red-ink); }
.flash.info { background: #e6eefc; color: #1e3a8a; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; color: var(--wine-dark); margin: 0; }
.page-head .spacer { flex: 1; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters a {
  text-decoration: none; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 20px; padding: 5px 14px; font-size: 13px;
}
.filters a.on { background: var(--wine); color: #fff; border-color: var(--wine); }
.filters a b { font-weight: 700; }
.filters form.sales-filter { display: inline-flex; margin: 0 0 0 auto; }
select.sales-filter {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 20px;
  font: inherit; font-size: 13px; background: var(--card); color: var(--ink);
  cursor: pointer; max-width: 220px;
}
select.sales-filter.on { background: var(--wine); color: #fff; border-color: var(--wine); }

/* ---------- cards / sections ---------- */
.card {
  background: var(--card); border-radius: 12px; padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07); margin-bottom: 18px;
}

/* ---------- table ---------- */
table { width: 100%; border-collapse: collapse; background: var(--card);
  border-radius: 12px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: .5px; border-bottom: 2px solid var(--line); padding: 10px 12px; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.row-red { background: #fef4f4; }
tr.row-green { background: #f3fbf5; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.col-date, td.col-date { white-space: nowrap; min-width: 118px; }
.sub { color: var(--muted); font-size: 12.5px; }
a.rowlink { color: var(--wine-dark); font-weight: 600; text-decoration: none; }
a.rowlink:hover { text-decoration: underline; }

/* ---------- badge ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px;
  font-weight: 700; border: 1px solid transparent; white-space: nowrap; }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow-ink); border-color: var(--yellow-br); }
.badge.green  { background: var(--green-bg);  color: var(--green-ink);  border-color: var(--green-br); }
.badge.red    { background: var(--red-bg);    color: var(--red-ink);    border-color: var(--red-br); }

/* ---------- buttons ---------- */
.btn { display: inline-block; cursor: pointer; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); border-radius: 8px; padding: 7px 14px;
  font-size: 13.5px; font-weight: 600; text-decoration: none; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--wine); color: #fff; border-color: var(--wine); }
.btn.primary:hover { background: var(--wine-dark); }
.btn.gold { background: var(--gold); color: #3a2c00; border-color: var(--gold); }
.btn.danger { color: var(--red-ink); border-color: var(--red-br); }
.btn.danger:hover { background: var(--red-bg); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.full { width: 100%; text-align: center; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin: 0; }

/* ---------- forms ---------- */
form label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13.5px; }
form input[type=text], form input[type=password], form textarea, form select {
  width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid #ddd4cc;
  border-radius: 8px; font: inherit; font-weight: 400; background: #fff; }
form textarea { min-height: 80px; resize: vertical; }
.req { color: var(--red-br); }
.form-narrow { max-width: 560px; }

/* ---------- detail ---------- */
.detail-grid { display: grid; grid-template-columns: 160px 1fr; gap: 8px 18px; }
.detail-grid dt { color: var(--muted); font-size: 13px; }
.detail-grid dd { margin: 0; font-weight: 600; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.timeline li:last-child { border-bottom: 0; }
details.ext > summary { cursor: pointer; color: var(--wine); font-weight: 600; font-size: 13px; }
details.ext { margin-top: 8px; }

/* ---------- login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--card); padding: 34px 32px; border-radius: 16px;
  box-shadow: 0 6px 30px rgba(0,0,0,.12); width: 360px; max-width: 92vw;
  border-top: 4px solid var(--wine); }
.login-sub { color: var(--muted); margin: 6px 0 18px; }
.login-card .brand { display: block; margin-bottom: 2px; }

/* ---------- misc ---------- */
.tag-pending { display: inline-block; margin-top: 5px; font-size: 11px; font-weight: 700;
  color: #92400e; background: #fff7ed; border: 1px solid #fdba74; border-radius: 6px;
  padding: 1px 8px; white-space: nowrap; }
.tag-forget { display: inline-block; margin-top: 5px; font-size: 11px; font-weight: 700;
  color: var(--red-ink); background: var(--red-bg); border: 1px solid var(--red-br);
  border-radius: 6px; padding: 1px 8px; white-space: nowrap; }
.tag-count { display: inline-block; margin-top: 5px; font-size: 11px; font-weight: 700;
  color: #1e3a8a; background: #e6eefc; border: 1px solid #93c5fd; border-radius: 6px;
  padding: 1px 8px; white-space: nowrap; }
.badge.orange { background: #fff7ed; color: #92400e; border-color: #fdba74; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* ---------- bulk actions (admin) ---------- */
.bulkbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--wine); color: #fff; padding: 10px 14px; border-radius: 10px;
  margin-bottom: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.18);
  position: sticky; top: 8px; z-index: 5;
}
/* mentre c'è una selezione, nascondo le azioni di riga per evitare ambiguità */
table.bulk-active td.actions { visibility: hidden; }
.bulkbar-info { font-weight: 600; margin-right: 4px; }
.bulkbar-info b { font-size: 16px; }
.bulkbar .btn { background: #fff; border-color: #fff; }
.bulkbar .btn.danger { color: var(--red-ink); }
.bulkbar-sep { width: 1px; align-self: stretch; background: rgba(255,255,255,.35); margin: 0 2px; }
.bulk-select { padding: 6px 10px; border-radius: 8px; border: 1px solid #fff;
  font: inherit; font-size: 13px; max-width: 200px; }
.col-sel { width: 34px; text-align: center; }
.col-sel input { width: 17px; height: 17px; cursor: pointer; vertical-align: middle; }
.kpi-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.kpi { background: var(--card); border-radius: 12px; padding: 14px 18px; min-width: 150px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07); border-top: 4px solid var(--wine); }
.kpi .v { font-size: 24px; font-weight: 800; color: var(--wine-dark); }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
