:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --green: #067647;
  --red: #b42318;
  --amber: #b54708;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- guscio applicazione ---------- */
.app { display: flex; min-height: 100vh; }
.navtoggle { display: none; }

.side {
  width: 236px; flex: 0 0 236px;
  background: #101216; color: #d7dae0;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-top { padding: 18px 18px 10px; }
.brand { font-weight: 700; font-size: 15px; color: #fff; letter-spacing: -.01em; display: block; }
.brand span { color: #8b8ff5; font-weight: 500; }
.brand:hover { text-decoration: none; }

.side-nav { flex: 1; padding: 8px 10px; overflow-y: auto; }
.side-group {
  margin: 18px 8px 6px; font-size: 10px; letter-spacing: .11em;
  text-transform: uppercase; color: #6a707c;
}
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px; margin-bottom: 1px;
  color: #b9bec9; font-size: 14px; font-weight: 500;
}
.side-nav a:hover { background: #1b1e25; color: #fff; text-decoration: none; }
.side-nav a.on { background: #24273a; color: #fff; }
.side-nav .ic { width: 16px; text-align: center; opacity: .75; font-size: 13px; }

.side-bottom { padding: 12px; border-top: 1px solid #22252c; }
.avatar {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%;
  background: #4f46e5; color: #fff; display: grid; place-items: center;
  font-size: 13px; font-weight: 600;
}
.side-bottom .btn.ghost { background: #1b1e25; border-color: #2b2f38; color: #c4c9d3; }
.side-bottom .btn.ghost:hover { background: #24273a; }

.content { flex: 1; min-width: 0; }
.wrap { max-width: 1180px; padding: 26px 26px 72px; }

.mobilebar { display: none; }
.scrim { display: none; }

.head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 13px; margin: 2px 0 0; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* Sotto i 900px la barra laterale diventa un pannello a scomparsa. */
@media (max-width: 900px) {
  .side {
    position: fixed; z-index: 30; left: 0; top: 0;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .navtoggle:checked ~ .side { transform: translateX(0); }
  .navtoggle:checked ~ .scrim {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: rgba(16,18,22,.5);
  }
  .mobilebar {
    display: flex; align-items: center; gap: 12px;
    background: #fff; border-bottom: 1px solid var(--line);
    padding: 0 14px; min-height: 52px; position: sticky; top: 0; z-index: 10;
  }
  .burger { font-size: 22px; cursor: pointer; margin: 0; line-height: 1; user-select: none; }
  .mobilebar-title { font-weight: 600; font-size: 15px; }
  .wrap { padding: 18px 16px 64px; }
}

/* ---------- statistiche ---------- */
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .n { font-size: 26px; font-weight: 650; letter-spacing: -.02em; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- tabelle ---------- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 0 12px 8px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- controlli ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--ink); color: #fff; border: 1px solid var(--ink);
  padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: inherit;
}
.btn:hover { text-decoration: none; opacity: .88; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { background: #fff; color: var(--red); border-color: #f2c8c2; }

label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 14px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
form.inline { display: inline; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 180px; }

/* ---------- etichette ---------- */
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; background: var(--bg); color: var(--muted);
  border: 1px solid var(--line); white-space: nowrap;
}
.tag.cliente { background: #ecfdf3; color: var(--green); border-color: #abefc6; }
.tag.fornitore { background: #eff8ff; color: #175cd3; border-color: #b2ddff; }
.tag.distributore { background: #fdf4ff; color: #9f1ab1; border-color: #f6d0fe; }
.tag.vinta { background: #ecfdf3; color: var(--green); border-color: #abefc6; }
.tag.persa { background: #fef3f2; color: var(--red); border-color: #fecdca; }
.tag.late { background: #fef3f2; color: var(--red); border-color: #fecdca; }

/* ---------- varie ---------- */
.flash {
  background: #ecfdf3; border: 1px solid #abefc6; color: var(--green);
  padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 14px;
}
.error {
  background: #fef3f2; border: 1px solid #fecdca; color: var(--red);
  padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 14px;
}
.empty { color: var(--muted); text-align: center; padding: 32px 12px; font-size: 14px; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.muted { color: var(--muted); }
.strike { text-decoration: line-through; color: var(--muted); }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-box { width: 100%; max-width: 360px; }
.login-box .card { padding: 26px; margin: 0; }
.login-box h1 { margin-bottom: 4px; }

@media (max-width: 820px) {
  .dl { grid-template-columns: 1fr; gap: 2px 0; }
  .dl dd { margin-bottom: 8px; }
}

/* ---------- creatives ---------- */
.cre-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.cre {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column;
}
.cre-thumb {
  position: relative; display: block; aspect-ratio: 4 / 3;
  background: #eef0f3; overflow: hidden;
}
.cre-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cre-ph {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 30px; color: #a8afba;
}
.cre-win {
  position: absolute; top: 8px; left: 8px;
  background: #b54708; color: #fff; font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
}
.cre-body { padding: 12px; }
.cre-title {
  display: block; font-weight: 550; font-size: 14px; color: var(--ink);
  margin-bottom: 7px; line-height: 1.35;
}
.cre-title:hover { color: var(--accent); text-decoration: none; }
.cre-meta { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 4px; }

/* etichette di stato aggiuntive */
.tag.win { background: #fef0c7; color: #b54708; border-color: #fedf89; }
.tag.approvata, .tag.pubblicata { background: #ecfdf3; color: var(--green); border-color: #abefc6; }
.tag.in_revisione { background: #fef0c7; color: var(--amber); border-color: #fedf89; }
.tag.archiviata { background: #f2f4f7; color: #667085; }

label.check { display: flex; align-items: center; gap: 9px; font-weight: 400; }
label.check input { width: auto; }

/* ---------- barre di volume ---------- */
.bar {
  position: relative; height: 8px; border-radius: 999px;
  background: #eceef2; overflow: hidden; min-width: 90px;
}
.bar-fill, .bar-win {
  position: absolute; left: 0; top: 0; height: 100%; border-radius: 999px;
}
.bar-fill { background: #c7c9f7; }
.bar-win { background: var(--accent); }

/* ---------- istogramma mensile ---------- */
.months { display: flex; gap: 10px; align-items: flex-end; overflow-x: auto; padding-top: 8px; }
.month { flex: 1 0 46px; text-align: center; }
.month-bars {
  position: relative; height: 110px; display: flex; align-items: flex-end;
  justify-content: center; gap: 3px;
}
.mb-tot, .mb-win { width: 12px; border-radius: 3px 3px 0 0; min-height: 2px; }
.mb-tot { background: #c7c9f7; }
.mb-win { background: var(--accent); }
.month-lab { font-size: 11px; color: var(--muted); margin-top: 6px; }
.month-n { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.month-n small { font-weight: 400; color: var(--muted); }


/* ---------- pannello di generazione ---------- */
.gen {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 18px; overflow: hidden;
}
.gen > summary {
  padding: 14px 18px; cursor: pointer; display: flex;
  align-items: center; justify-content: space-between; gap: 12px;
  list-style: none; user-select: none;
}
.gen > summary::-webkit-details-marker { display: none; }
.gen > summary:hover { background: #fafbfc; }
.gen-title { font-weight: 600; font-size: 15px; color: var(--accent); }
.gen-body { padding: 0 18px 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.gen-body textarea { min-height: 74px; }

.gen-wait, .gen-fail {
  margin-top: 8px; padding: 6px; border-radius: 7px; text-align: center;
  font-size: 12px; font-weight: 500;
}
.gen-wait { background: var(--accent-soft); color: var(--accent); }
.gen-fail { background: #fef3f2; color: var(--red); }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .92em; background: var(--bg); padding: 1px 5px;
  border-radius: 4px; border: 1px solid var(--line);
}

/* ---------- selettore workspace (stile Slack) ---------- */
.ws { position: relative; }
.ws > summary {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 8px; cursor: pointer;
  list-style: none; user-select: none;
}
.ws > summary::-webkit-details-marker { display: none; }
.ws > summary:hover { background: #1b1e25; }
.ws-badge {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 8px;
  background: #4f46e5; color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.ws-badge.sm { width: 22px; height: 22px; flex: 0 0 22px; border-radius: 6px; font-size: 11px; }
.ws-txt { min-width: 0; line-height: 1.25; flex: 1; }
.ws-txt strong {
  display: block; font-size: 14px; color: #fff; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ws-txt small { display: block; font-size: 11px; color: #767d8a; }
.ws-caret { color: #767d8a; font-size: 13px; }

.ws-menu {
  position: absolute; left: 6px; right: -8px; top: 100%; z-index: 40;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(16, 18, 22, .28);
  padding: 8px; margin-top: 4px;
}
.ws-label {
  margin: 4px 8px 8px; font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted);
}
.ws-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 8px; border-radius: 7px; border: 0; background: none;
  font: inherit; font-size: 14px; color: var(--ink); cursor: pointer; text-align: left;
}
.ws-item:hover { background: var(--bg); }
.ws-item.on { background: var(--accent-soft); cursor: default; }
.ws-tick { margin-left: auto; color: var(--accent); }
.ws-add {
  display: block; margin-top: 6px; padding: 8px;
  border-top: 1px solid var(--line); font-size: 13px; color: var(--accent);
}
.ws-add:hover { text-decoration: none; background: var(--bg); border-radius: 7px; }

/* ---------- temi ricorrenti ---------- */
.themes { display: flex; flex-wrap: wrap; gap: 8px; }
.theme {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 500;
}
.theme-n {
  background: var(--accent); color: #fff; border-radius: 999px;
  font-size: 11px; padding: 0 6px; font-weight: 600;
}

/* ---------- pannello generazione, versione a prompt ---------- */
.gen-prompt {
  min-height: 96px; font-size: 15px; line-height: 1.5;
  border-width: 1.5px;
}
.gen-row {
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
  margin-top: 4px;
}
.gen-row .field { margin-bottom: 0; flex: 1 1 190px; }
.gen-go { flex: 0 0 auto; height: 38px; padding: 0 22px; }

.gen-drop {
  display: block; border: 1.5px dashed var(--line); border-radius: 9px;
  padding: 14px 16px; cursor: pointer; font-weight: 400;
  background: #fcfcfd; transition: border-color .15s, background .15s;
}
.gen-drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.gen-drop strong { display: block; font-size: 14px; font-weight: 550; margin-bottom: 2px; }
.gen-drop span { display: block; font-size: 12px; }
.gen-drop input[type="file"] { margin-top: 10px; font-size: 13px; width: 100%; }

.gen-adv { margin-top: 14px; }
.gen-adv > summary {
  cursor: pointer; font-size: 13px; color: var(--muted);
  padding: 4px 0; user-select: none;
}
.gen-adv > summary:hover { color: var(--ink); }
.gen-adv .row { margin-top: 10px; }

.cre-actions { display: flex; gap: 6px; margin-top: 8px; }

/* ---------- accessi per workspace ---------- */
.access {
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.access:last-of-type { border-bottom: 0; padding-bottom: 0; }
.access-who { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; flex-wrap: wrap; }
.access-form { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.access-brand { font-size: 13px; margin: 0; }
.access-brand input { width: auto; }


/* ---------- spazio impostazioni ---------- */
.setwrap { display: flex; gap: 30px; align-items: flex-start; }
.setnav { flex: 0 0 190px; position: sticky; top: 26px; }
.setnav-group {
  margin: 0 0 8px; font-size: 10px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted);
}
.setnav-group ~ .setnav-group { margin-top: 22px; }
.setnav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: 7px; margin-bottom: 1px;
  color: var(--muted); font-size: 14px; font-weight: 500;
}
.setnav a:hover { background: var(--panel); color: var(--ink); text-decoration: none; }
.setnav a.on { background: var(--accent-soft); color: var(--accent); }
.setnav .ic { width: 15px; text-align: center; font-size: 12px; opacity: .8; }
.setmain { flex: 1; min-width: 0; }
.setmain .card { max-width: 640px; }

@media (max-width: 820px) {
  .setwrap { flex-direction: column; gap: 18px; }
  .setnav { position: static; flex: 1 1 auto; width: 100%; display: flex; flex-wrap: wrap; gap: 4px; }
  .setnav-group { display: none; }
  .setnav-group ~ .setnav-group { margin-top: 0; }
}

/* ---------- blocco profilo: tutta la riga porta alle impostazioni ---------- */
.side-me {
  display: block; padding: 8px; border-radius: 8px; margin-bottom: 10px;
  color: inherit;
}
.side-me:hover { background: #1b1e25; text-decoration: none; }
.side-me:hover .side-me-gear,
.side-me:hover .side-me-hint { color: #fff; }
.side-me.on { background: #24273a; }

.side-me-row { display: flex; align-items: center; gap: 9px; min-width: 0; }
.side-me-txt { min-width: 0; line-height: 1.3; flex: 1; }
.side-me-txt strong {
  display: block; font-size: 13px; color: #eef0f4; font-weight: 550;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-me-txt small {
  display: block; font-size: 11px; color: #767d8a;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-me-gear { flex: 0 0 auto; color: #767d8a; font-size: 14px; line-height: 1; }
.side-me-hint {
  display: block; margin: 6px 0 0 39px;
  font-size: 12px; font-weight: 500; color: #8b8ff5;
}

/* ---------- schede modello ---------- */
.modelgrid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.model { display: block; margin: 0; cursor: pointer; font-weight: 400; }
.model input { position: absolute; opacity: 0; pointer-events: none; }
.model-body {
  display: block; border: 1.5px solid var(--line); border-radius: 9px;
  padding: 12px 14px; background: #fff; height: 100%;
  transition: border-color .12s, background .12s;
}
.model:hover .model-body { border-color: #c7c9f7; }
.model input:checked + .model-body {
  border-color: var(--accent); background: var(--accent-soft);
}
.model input:focus-visible + .model-body { outline: 2px solid var(--accent); outline-offset: 2px; }
.model-name {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: 14px; font-weight: 550; margin-bottom: 3px;
}
.model-note { display: block; font-size: 12px; color: var(--muted); line-height: 1.45; }

/* ---------- schede a linguette ---------- */
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 9px; }
.tabs a {
  padding: 6px 16px; border-radius: 7px; font-size: 14px;
  font-weight: 500; color: var(--muted);
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(16,18,22,.09); }
