:root {
  --bg: #eef0ee;
  --surface: #ffffff;
  --ink: #17201c;
  --muted: #68736e;
  --rule: #d5dad6;
  --pos: #2f6b4f;
  --neg: #b0402d;
  --neg-soft: #f3ded9;
  --pos-soft: #dcebe3;
  --focus: #17201c;
  font-family: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { line-height: 1.4; font-feature-settings: "tnum" 1; }
h1, h2, h3 { font-weight: 600; margin: 0; }
h1 { font-size: 22px; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
h3 { font-size: 14px; margin-bottom: 8px; }
p { margin: 0; }
a { color: inherit; }
button {
  font: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule); border-radius: 3px;
  padding: 5px 10px; cursor: pointer;
}
button:hover { border-color: var(--ink); }
button:disabled { opacity: .5; cursor: default; }
button.danger:hover { color: var(--neg); border-color: var(--neg); }
input {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule); border-radius: 3px; padding: 7px 9px; width: 100%;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.sub { display: block; color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }

/* ---- layout */
.layout { min-height: 100vh; }
main { padding: 28px 32px; }
@media (max-width: 860px) { main { padding: 18px; overflow-x: auto; } }

/* ---- form */
.add { display: flex; flex-direction: column; gap: 10px; }
.add label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.add input { font-size: 15px; }
.add input[name=code] { text-transform: uppercase; letter-spacing: .04em; }
.add button { background: var(--ink); color: #fff; border-color: var(--ink); padding: 9px; font-size: 14px; }

/* ---- flash */
.flash {
  display: inline-block; margin-bottom: 14px; padding: 6px 10px; font-size: 13px;
  border-left: 3px solid var(--pos); background: var(--pos-soft);
}
.flash.error { border-color: var(--neg); background: var(--neg-soft); }

/* ---- main table */
.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--rule); }
.grid th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--rule);
}
.grid td { padding: 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover td { background: #f7f8f7; }
.grid tr.failed td.code { color: var(--neg); }
.grid tr.busy td { opacity: .6; }
.grid .code { font-weight: 500; letter-spacing: .03em; white-space: nowrap; }
.grid .name { max-width: 240px; }
.grid .name span { display: block; color: var(--muted); font-size: 12px; }
.grid .num, .hist .num { text-align: right; white-space: nowrap; }
.grid td.num input { width: 96px; text-align: right; padding: 5px 7px; }
.grid .when { white-space: nowrap; color: var(--muted); font-size: 13px; }
.grid .row-actions { text-align: right; }
.tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px; font-size: 11px;
  border-radius: 2px; background: var(--ink); color: #fff; vertical-align: middle;
}

/* ---- the delta column: the one loud element */
.delta-h { text-align: center; }
.grid .delta { width: 230px; text-align: center; }
.grid .delta b { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; display: block; line-height: 1.1; }
.bar { position: relative; height: 6px; margin-bottom: 6px; background: var(--bg); }
.bar::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--rule); }
.bar i { position: absolute; top: 0; height: 100%; display: block; }
.bar.neg i { right: 50%; background: var(--neg); }
.bar.pos i { left: 50%; background: var(--pos); }
.bar.neg + b { color: var(--neg); }
.bar.pos + b { color: var(--pos); }
.legend { margin-top: 12px; color: var(--muted); font-size: 12px; }

.empty-state { padding: 60px 0; max-width: 420px; }
.empty-state .sub { margin-top: 6px; }

/* ---- history panel */
.detail:empty { display: none; }
.detail { background: var(--surface); border-top: 1px solid var(--rule); }
.detail-inner { padding: 24px 32px 40px; max-width: 1100px; }
.detail header { display: flex; align-items: baseline; gap: 16px; margin-bottom: 14px; }
.detail header h2 { font-size: 18px; }
.detail header h2 span { font-weight: 400; color: var(--muted); margin-left: 8px; }
.detail header a { font-size: 13px; color: var(--muted); }
.detail header .close { margin-left: auto; }
.spark { color: var(--ink); display: block; margin-bottom: 18px; }
.cols { display: grid; grid-template-columns: 2fr 1fr; gap: 32px; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } .detail-inner { padding: 18px; } }
.hist { width: 100%; border-collapse: collapse; font-size: 13px; }
.hist th { text-align: left; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--rule); }
.hist td { padding: 6px 8px; border-bottom: 1px solid var(--rule); }
.hist tr.changed td { font-weight: 600; }
.hist tr.failed td { color: var(--neg); }

@media (prefers-reduced-motion: no-preference) {
  .htmx-request .grid { transition: opacity .15s; opacity: .7; }
}

/* ---- attributi prodotto */
.grid .name .attrs { color: var(--muted); font-size: 12px; margin-top: 2px; }
.attrs-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0 0 18px; font-size: 13px; max-width: 720px; }
.attrs-list dt { color: var(--muted); }
.attrs-list dd { margin: 0; }
.attrs-list dd span { display: block; }
.attrs-list dd b { font-weight: 500; }

/* ---- colonne per sito */
.grid th.site-h, .grid th.mid-h { text-align: center; }
.grid:not(.countries) td.when { text-align: center; }
.grid .site { width: 190px; text-align: center; }
.grid .site b { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; display: block; line-height: 1.1; }
.grid .site .price { display: block; font-size: 13px; margin-top: 2px; }
.grid .site .fail { color: var(--neg); }
.sparks { display: flex; gap: 32px; flex-wrap: wrap; margin-bottom: 18px; }
.spark-fig { margin: 0; }
.spark-fig figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.spark { margin-bottom: 0; }
.detail header a + a { margin-left: -4px; }
.tag.muted-tag { background: var(--muted); }
.grid .name { max-width: 320px; }
.grid .name .comp { line-height: 1.35; }

/* ---- viste */
.views { display: flex; gap: 2px; margin-bottom: 14px; }
.views a {
  text-decoration: none; font-size: 13px; padding: 6px 12px; color: var(--muted);
  border: 1px solid var(--rule); background: var(--surface); cursor: pointer;
}
.views a:first-child { border-radius: 3px 0 0 3px; }
.views a:last-child { border-radius: 0 3px 3px 0; }
.views a.on { color: #fff; background: var(--ink); border-color: var(--ink); }

/* ---- tabella per paese */
.grid.countries td { padding: 9px 10px; }
.grid.countries tr.first td { border-top: 2px solid var(--rule); }
.grid.countries .code .name-sub { display: block; font-weight: 400; letter-spacing: 0; color: var(--muted); font-size: 12px; max-width: 200px; white-space: normal; }
.grid.countries .site-name { color: var(--muted); font-size: 13px; white-space: nowrap; }
.grid th.cc-h { text-align: right; }
.grid.countries .when { text-align: right; }
.grid .cc { text-align: right; white-space: nowrap; font-size: 13px; min-width: 96px; }
.grid .cc.base { border-right: 1px solid var(--rule); }
.grid .cc b { display: block; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.15; }
.grid .cc b.neg { color: var(--neg); }
.grid .cc b.pos { color: var(--pos); }
.grid .cc b.flat { color: var(--muted); }
.grid .cc .local { display: block; font-size: 12px; }
.grid .cc .local i { font-style: normal; color: var(--muted); }
.strike { color: var(--muted); text-decoration: line-through; font-size: 12px; }
.disc { color: var(--neg); font-size: 12px; }
.dot { display: inline-block; font-size: 10px; color: var(--muted); border: 1px solid var(--rule); border-radius: 2px; padding: 0 4px; margin-top: 2px; }
.sub.fail { color: var(--neg); }

/* ---- storico per paese */
.country-hist { margin-bottom: 22px; }
.country-hist h4 { font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.country-hist .sub-inline { font-weight: 400; color: var(--muted); font-size: 12px; }
.cc-table tr.base-row td { background: #f7f8f7; }
.cc-matrix { margin-top: 8px; }
.cc-matrix th { font-size: 11px; }

.grid.countries .row-actions { white-space: nowrap; }
.grid.countries .row-actions button { display: block; width: 100%; margin-bottom: 4px; }
button.small { font-size: 12px; padding: 3px 8px; margin-right: 10px; }
.add .opt { font-weight: 400; color: var(--muted); }
.grid .site b.nodelta { color: var(--muted); font-size: 18px; }

/* ---- form multi-codice */
#code-rows { display: flex; flex-direction: column; gap: 8px; }
.code-row { display: grid; grid-template-columns: 1fr 96px 26px; gap: 6px; align-items: end; }
.code-row label { min-width: 0; }
.code-row input[name=price] { padding: 7px 6px; }
.code-row .rm { padding: 6px 0; font-size: 15px; line-height: 1; color: var(--muted); }
.add .more { background: var(--surface); color: var(--ink); border-style: dashed; }
.add .hint { color: var(--muted); font-size: 12px; }
.grid .site .open { display: block; font-size: 12px; color: var(--muted); text-decoration: none; margin-top: 2px; }
.grid .site .open:hover { color: var(--ink); text-decoration: underline; }

/* ---- login */
body.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); margin: 0; }
.login-page main.login { width: min(420px, 92vw); max-width: 420px; margin: 0; padding: 32px; background: var(--surface); border: 1px solid var(--rule); flex: 0 0 auto; }
.login h1 { margin: 0 0 12px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.login label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.who { font-size: 12px; color: var(--muted); }
.who .inline { display: inline; }
.who button.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 12px; }
.login h1.brand { text-align: center; font-weight: 700; font-size: 26px; margin-bottom: 18px; }
.login p { text-align: center; }

/* ---- link alla scheda accanto al nome del sito */
.site-name .ext { display: inline-block; vertical-align: -1px; margin-left: 3px; color: var(--muted); }
.site-name .ext:hover { color: var(--ink); }

/* ---- intestazione a scomparsa (stato in cookie ffhead) */
.top { background: var(--surface); border-bottom: 1px solid var(--rule); }
.top-bar { display: flex; align-items: center; gap: 10px; padding: 14px 32px; }
.top-bar h1 { margin-right: auto; }
.head-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
}
.head-toggle:hover { background: var(--bg); color: var(--ink); }
.top-body {
  display: grid; grid-template-columns: minmax(280px, 1.2fr) minmax(320px, 1fr) minmax(200px, .6fr);
  gap: 36px; padding: 0 32px 24px; border-top: 1px solid var(--rule); padding-top: 20px;
}
.top-body h2 { margin-bottom: 10px; }
.top-intro { display: flex; flex-direction: column; gap: 10px; }
.layout.head-hidden .top-body { display: none; }
.add-actions { display: flex; gap: 8px; }
.add-actions button { flex: 1; }
.filters { display: flex; flex-direction: column; gap: 10px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filters input { font-size: 15px; }
.filters .hint { color: var(--muted); font-size: 12px; min-height: 1em; }
.grid tr.filtered-out { display: none; }
.grid .row-actions button { display: block; width: 100%; margin-bottom: 4px; white-space: nowrap; }
@media (max-width: 1100px) { .top-body { grid-template-columns: 1fr 1fr; } .top-intro { grid-column: 1 / -1; } }
@media (max-width: 860px) { .top-body { grid-template-columns: 1fr; padding: 16px 18px; } .top-bar { padding: 12px 18px; } }
.credit { font-size: 13px; color: var(--muted); }
.credit b { font-weight: 500; color: var(--ink); }
.credit.low { color: var(--neg); border-left: 3px solid var(--neg); padding-left: 8px; }
