:root {
  --bg: #f8f7f4; --surface: #fff; --text: #1d1b18; --muted: #6d675f; --line: #e6e2db;
  --accent: #b9543a; --accent-text: #fff; --danger: #a33a3a;
  --st-da-contattare: #7d776e; --st-contattato: #2c6aa8; --st-in-attesa-risposta: #9a6a00;
  --st-in-trattativa: #7348a8; --st-attivo: #2a7d50; --st-scartato: #a33a3a;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311; --surface: #1c1b18; --text: #ece8e1; --muted: #9b958c; --line: #2d2a26;
    --accent: #e0795d; --accent-text: #1a0f0b; --danger: #e07070;
    --st-da-contattare: #a39d94; --st-contattato: #6ea8e0; --st-in-attesa-risposta: #d9a441;
    --st-in-trattativa: #b08be0; --st-attivo: #62c08c; --st-scartato: #e07070;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h2 { font-size: 1.35rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 1.8em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 8px; padding: .5rem .9rem; background: var(--accent); color: var(--accent-text); font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.link { background: none; color: var(--muted); padding: 0; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
button.danger { color: var(--danger); }
input, select, textarea { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; }
input:focus, select:focus, textarea:focus, button:focus-visible, tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }
label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
.stack { display: grid; gap: .9rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .9rem; }
.error { color: var(--danger); margin: 0; min-height: 1.2em; }

/* Header */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1.5rem; padding: .8rem 24px; background: var(--bg); border-bottom: 1px solid var(--line); }
.title { display: flex; align-items: center; gap: .7rem; }
.logo { display: block; height: 40px; width: auto; }
.logo-lg { height: 72px; margin-bottom: .6rem; }
.tabs { display: flex; gap: .3rem; }
.tabs a { text-decoration: none; padding: .35rem .75rem; border-radius: 999px; color: var(--muted); }
.tabs a.on { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.user { margin-left: auto; display: flex; gap: .9rem; align-items: center; color: var(--muted); }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }

/* Contatori e filtri */
.counters { display: grid; grid-template-columns: repeat(6, 1fr); gap: .6rem; margin-bottom: 1.2rem; }
.counter { display: grid; text-align: left; background: var(--surface); color: var(--muted); border: 1px solid var(--line); font-weight: 500; font-size: .85rem; padding: .7rem .9rem; }
.counter .n { font-size: 1.5rem; font-weight: 650; color: var(--c); font-variant-numeric: tabular-nums; }
.counter.on { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: .6rem; }
.toolbar input[type=search] { flex: 1 1 160px; width: auto; min-width: 0; }
.toolbar select { width: auto; }
.toolbar .spacer { flex: 1; }
.toolbar p { margin: 0; flex: 1 1 400px; }
/* Se il gruppo di pulsanti va a capo, resta allineato a destra */
.toolbar #export-brands, .toolbar #export-agencies { margin-left: auto; }

@media (min-width: 1280px) {
  .toolbar select { max-width: 170px; }
}

/* Tabella */
.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list th { text-align: left; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
.list th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.list th[data-sort]:hover { color: var(--text); }
.list th[aria-sort=ascending]::after { content: ' ↑'; }
.list th[aria-sort=descending]::after { content: ' ↓'; }
.list th[aria-sort=ascending], .list th[aria-sort=descending] { color: var(--text); }
.list td { padding: .65rem .9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tr:last-child td { border-bottom: 0; }
.list:not(.static) tbody tr { cursor: pointer; }
.list:not(.static) tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }

.list td.site { text-align: right; white-space: nowrap; }
.site-btn + .site-btn { margin-left: .35rem; }
.links-sm { display: none; }
.rec-sm { display: none; }
.list th.center, .list td.center { text-align: center; }
.list th[data-sort=consigliato] { white-space: normal; width: 6.5rem; }
.site-btn { display: inline-block; font-size: .8rem; font-weight: 550; text-decoration: none; padding: .2rem .6rem; border: 1px solid var(--line); border-radius: 999px; color: var(--text); }
.site-btn:hover { border-color: var(--accent); color: var(--accent); }
.pill { display: inline-block; white-space: nowrap; font-size: .8rem; font-weight: 550; padding: .1rem .55rem; border-radius: 999px; color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); }
.s-da-contattare { --c: var(--st-da-contattare); }
.s-contattato { --c: var(--st-contattato); }
.s-in-attesa-risposta { --c: var(--st-in-attesa-risposta); }
.s-in-trattativa { --c: var(--st-in-trattativa); }
.s-attivo { --c: var(--st-attivo); }
.s-scartato { --c: var(--st-scartato); }
.prio { display: inline-grid; place-items: center; min-width: 1.7rem; height: 1.5rem; padding: 0 .3rem; border-radius: 6px; font-size: .75rem; font-weight: 700; border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.prio.p-A { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.prio.p-B { color: var(--accent); border-color: var(--accent); }
.urgent { color: var(--accent); font-size: .7rem; vertical-align: middle; }

/* Pannello laterale */
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .25); z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 10; width: min(560px, 100vw); overflow-y: auto; background: var(--surface); border-left: 1px solid var(--line); padding: 28px; transform: translateX(100%); transition: transform .2s ease; }
.drawer.open { transform: none; }
.drawer .close { position: absolute; top: 18px; right: 22px; font-size: 1.1rem; text-decoration: none; }
.drawer h2 { padding-right: 2rem; }
.field { display: grid; grid-template-columns: 150px 1fr; gap: .8rem; padding: .35rem 0; }
.field .label { color: var(--muted); font-size: .85rem; }
.links { margin: .2rem 0 0; }
.callout { background: color-mix(in srgb, var(--accent) 10%, transparent); border-left: 3px solid var(--accent); padding: .6rem .8rem; border-radius: 0 8px 8px 0; font-size: .9rem; }
.work { margin-top: 1.4rem; padding-top: .2rem; border-top: 1px solid var(--line); }
.danger-zone { display: flex; justify-content: space-between; align-items: center; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }

/* Info */
.prose { max-width: 780px; }
.prose h2 { margin-top: 2rem; }
.prose dt { font-weight: 600; margin-top: .8rem; }
.prose dd { margin: .15rem 0 0; color: var(--muted); }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 32px; }
.login-card h1 { font-size: 1.5rem; margin: .2rem 0 1.4rem; }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: .6rem; padding: .7rem 16px; }
  .tabs { order: 3; width: 100%; }
  main { padding: 16px; }
  .counters { grid-template-columns: repeat(3, 1fr); }
  .hide-sm { display: none; }
  .rec-sm { display: inline; }
  .links-sm { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
  .links-sm .site-btn + .site-btn { margin-left: 0; }
  .list th, .list td { padding-left: .6rem; padding-right: .6rem; }
  .toolbar select, .toolbar button { flex: 1 1 45%; }
  .field { grid-template-columns: 1fr; gap: 0; }
  .drawer { padding: 20px 16px; }
}
