/* GesACom Web: stessi colori dell'app React. Tema: quello del sistema, oppure scelto (data-tema su <html>) */
:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f8fafc; --border: #e3e8ef;
  --text: #0f172a; --muted: #64748b; --accent: #2563eb; --accent-strong: #1d4ed8; --accent-soft: #e8efff;
  --danger: #dc2626; --success: #16a34a; --warning: #d97706;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="chiaro"]) {
    --bg: #0b1120; --surface: #111a2e; --surface-2: #0f172a; --border: #22304a;
    --text: #e2e8f0; --muted: #94a3b8; --accent: #60a5fa; --accent-strong: #3b82f6; --accent-soft: #172554;
    --danger: #f87171; --success: #4ade80; --warning: #fbbf24;
    color-scheme: dark;
  }
}
:root[data-tema="scuro"] {
  --bg: #0b1120; --surface: #111a2e; --surface-2: #0f172a; --border: #22304a;
  --text: #e2e8f0; --muted: #94a3b8; --accent: #60a5fa; --accent-strong: #3b82f6; --accent-soft: #172554;
  --danger: #f87171; --success: #4ade80; --warning: #fbbf24;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 Inter, ui-sans-serif, system-ui, "Segoe UI", sans-serif; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.tabular { font-variant-numeric: tabular-nums; }
.tenue { color: var(--muted); }
.piccolo { font-size: 12px; }
.forte { font-weight: 500; }
.ic { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* guscio e menu */
.guscio { display: flex; height: 100vh; }
.menu { width: 248px; flex: none; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; transition: width .2s, transform .2s; }
.marchio { display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 16px; flex: none; }
.marchio b { display: block; font-size: 14px; }
.marchio small { display: block; color: var(--muted); font-size: 11px; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.voci { flex: 1; overflow-y: auto; padding: 0 10px 14px; }
.menu .sezione { margin: 14px 10px 4px; font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); min-height: 1px; }
.menu .voce { display: flex; align-items: center; gap: 11px; height: 36px; padding: 0 10px; border-radius: 8px; color: var(--text); opacity: .86; font-size: 13.5px; }
.menu .voce:hover { background: var(--surface-2); opacity: 1; }
.menu .voce.attiva { background: var(--accent-soft); color: var(--accent); font-weight: 500; opacity: 1; }
.menu .voce .testo-menu { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.menu .punto { margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--border); flex: none; }
.riduci { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 20px; border: 0; border-top: 1px solid var(--border); background: none; color: var(--muted); font-size: 12px; cursor: pointer; }
.riduci:hover { color: var(--text); }
html.menu-compatto .menu { width: 68px; }
html.menu-compatto .menu .testo-menu { display: none; }
html.menu-compatto .menu .sezione { border-top: 1px solid var(--border); margin: 10px 12px; }
html.menu-compatto .menu .voce { justify-content: center; padding: 0; }
html.menu-compatto .marchio { justify-content: center; padding: 0; }
html.menu-compatto .riduci { justify-content: center; padding: 0; }
html.menu-compatto .freccia-riduci { transform: scaleX(-1); }
.velo { display: none; }
.area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.testata { height: 56px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.testata h1 { font-size: 15px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icona-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; border: 0; background: none; color: var(--muted); cursor: pointer; list-style: none; }
.icona-btn:hover { background: var(--surface-2); color: var(--text); }
.solo-stretto { display: none; }
.vai { margin-left: auto; display: flex; align-items: center; gap: 8px; width: 280px; height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 13px; }
.vai:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.vai kbd { margin-left: auto; font: 500 10px/1 inherit; padding: 3px 5px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); }
main { flex: 1; min-height: 0; overflow: auto; }

/* tendine della testata (tema, utente) */
.tendina-menu { position: relative; }
.tendina-menu > summary { list-style: none; cursor: pointer; }
.tendina-menu > summary::-webkit-details-marker { display: none; }
.elenco-tendina { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 200px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 30px rgba(15, 23, 42, .16); }
.elenco-tendina button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px; background: none; cursor: pointer; text-align: left; font-size: 13.5px; }
.elenco-tendina button:hover { background: var(--surface-2); }
.elenco-tendina button.scelto { color: var(--accent); }
.elenco-tendina .pericolo { color: var(--danger); }
.info-utente { padding: 8px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.utente { display: flex; align-items: center; gap: 9px; padding: 4px 8px 4px 4px; border-radius: 8px; }
.utente:hover { background: var(--surface-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; }
.nome-utente b { display: block; font-size: 13px; font-weight: 500; }
.nome-utente small { display: block; font-size: 11px; color: var(--muted); }

/* Vai a (Ctrl+K) */
.vai-a { width: 480px; max-width: calc(100vw - 32px); margin-top: 12vh; padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: 0 24px 60px rgba(15, 23, 42, .25); }
.vai-a::backdrop { background: rgba(2, 6, 23, .35); }
.vai-a input { width: 100%; height: 48px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 0 16px; background: none; font-size: 15px; }
.vai-a input:focus { outline: none; box-shadow: none; }
.vai-a ul { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto; }
.vai-a li a { display: block; padding: 8px 10px; border-radius: 6px; color: var(--text); }
.vai-a li a.scelta, .vai-a li a:hover { background: var(--accent-soft); color: var(--accent); }
.vai-a li a.non-pronta::after { content: " \00B7  in arrivo"; color: var(--muted); font-size: 12px; }

/* comandi */
.bottone { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 13px; }
.bottone:hover { background: var(--surface-2); }
.bottone.primario { background: var(--accent); border-color: var(--accent); color: #fff; height: 38px; }
.bottone.primario:hover { background: var(--accent-strong); }
.bottone.fantasma { border-color: transparent; color: var(--muted); }
input:not([type=hidden]), select { height: 38px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 0 10px; min-width: 0; }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.distintivo { display: inline-block; font-size: 11px; font-weight: 500; padding: 1px 6px; border-radius: 6px; vertical-align: 1px; }
.distintivo.ambra { background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--warning); }
.distintivo.rosso { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.distintivo.verde { background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success); }

/* elenchi */
.elenco { display: flex; flex-direction: column; height: 100%; padding: 18px 24px 24px; gap: 14px; }
.barra { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.barra .cerca { position: relative; display: flex; align-items: center; width: 360px; }
.barra .cerca .ic { position: absolute; left: 11px; color: var(--muted); }
.barra .cerca input { width: 100%; padding-left: 34px; }
.barra select { max-width: 220px; }
.carica { display: none; font-size: 12px; color: var(--accent); }
.htmx-request .carica, .carica.htmx-request { display: inline; }
.tabella { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.griglia { width: 100%; border-collapse: separate; border-spacing: 0; }
.griglia th, .griglia td { padding: 0 10px; height: 38px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); overflow: hidden; text-overflow: ellipsis; max-width: 360px; }
.griglia thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--muted); height: 40px; }
.griglia .riga-filtri th { position: sticky; top: 40px; z-index: 2; background: var(--surface); padding: 4px 6px; }
.griglia .riga-filtri input { height: 30px; width: 100%; font-size: 12px; }
.griglia tbody#righe tr { cursor: pointer; }
.griglia tbody#righe tr:hover td, .griglia tbody#righe tr:focus td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.griglia tbody#righe tr:focus { outline: none; }
.griglia .c-num, .griglia .c-num-breve { text-align: right; font-variant-numeric: tabular-nums; }
.griglia .c-num-breve { width: 96px; }
.griglia .c-codice { font-variant-numeric: tabular-nums; }
.griglia .c-descr { min-width: 260px; }
.griglia .c-breve { min-width: 120px; }
.griglia .c-um { width: 70px; }
.griglia .c-data { width: 130px; font-variant-numeric: tabular-nums; }
.griglia .seguito td, .griglia .vuoto td { text-align: center; color: var(--muted); cursor: default; }
.ordina { border: 0; background: none; padding: 0; cursor: pointer; color: inherit; font-weight: 600; font-size: 12px; }
.ordina.attiva { color: var(--accent); }
.c-num .ordina, .c-num-breve .ordina { width: 100%; text-align: right; }

/* scheda laterale */
.pannello { position: fixed; inset: 0 0 0 auto; width: 640px; max-width: 96vw; background: var(--surface); border-left: 1px solid var(--border); box-shadow: -12px 0 40px rgba(15, 23, 42, .16); overflow: auto; z-index: 20; }
.pannello:empty { display: none; }
.pannello:has(.scheda.larga) { width: 1040px; }
.scheda-testa { display: flex; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.scheda-testa h2 { margin: 0 0 2px; font-size: 17px; }
.chiudi { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.scheda-corpo { padding: 18px 22px; }
.scheda-corpo h3 { margin: 22px 0 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.dati { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.dati .largo { grid-column: 1 / -1; }
.dati dt { font-size: 11px; color: var(--muted); }
.dati dd { margin: 2px 0 0; min-height: 20px; overflow-wrap: anywhere; }
.dati dd:empty::after { content: "\2014"; color: var(--muted); opacity: .6; }
.note { white-space: pre-wrap; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.azioni-contatto { display: flex; flex-wrap: wrap; gap: 8px; }
.due-colonne { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; }
.riquadri { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 16px; }
.riquadro { border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; background: var(--surface-2); display: flex; flex-direction: column; }
.riquadro small { font-size: 11px; color: var(--muted); }
.riquadro b { font-size: 18px; font-variant-numeric: tabular-nums; }
.riquadro.evidenza { border-color: var(--accent); background: var(--accent-soft); }
.tabella-righe { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
.righe-ordine { width: 100%; border-collapse: collapse; font-size: 13px; }
.righe-ordine th { text-align: left; padding: 8px 10px; background: var(--surface-2); font-size: 11px; font-weight: 600; color: var(--muted); }
.righe-ordine td { padding: 8px 10px; border-top: 1px solid var(--border); vertical-align: top; }
.righe-ordine .c-num { text-align: right; white-space: nowrap; }
.righe-ordine tr.annullata td { color: var(--muted); text-decoration: line-through; }
.righe-ordine .vuoto { text-align: center; color: var(--muted); padding: 18px; }
.nota-riga { margin-top: 2px; font-size: 12px; color: var(--muted); white-space: pre-wrap; }

/* scrivania e pagine in arrivo */
.scrivania { max-width: 1040px; margin: 0 auto; padding: 32px; }
.scrivania h2 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.riquadri-voci { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-top: 28px; }
.riquadro-voce { display: flex; flex-direction: column; gap: 12px; padding: 20px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); transition: transform .15s, box-shadow .15s, border-color .15s; }
.riquadro-voce:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15, 23, 42, .08); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.riquadro-voce b { font-weight: 500; }
.icona-voce { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.icona-voce .ic { width: 19px; height: 19px; }
.icona-voce.grande { width: 48px; height: 48px; margin: 0 auto; }
.in-arrivo { max-width: 420px; margin: 14vh auto 0; text-align: center; padding: 0 16px; }
.in-arrivo h2 { margin: 16px 0 6px; font-size: 18px; }

/* riga d'ordine */
.pagina-riga { max-width: 1040px; padding: 18px 24px; }
.riga { display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.campi { display: grid; gap: 12px; }
.campi.due { grid-template-columns: 1fr 1fr; }
.campi.sei { grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); }
.campi label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); position: relative; }
.campi label input { color: var(--text); font-size: 14px; }
.campi input.num { text-align: right; font-variant-numeric: tabular-nums; }
.suggerimenti { position: absolute; top: 100%; left: 0; right: 0; z-index: 5; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 30px rgba(15, 23, 42, .14); margin-top: 4px; overflow: hidden; }
.suggerimenti:empty { display: none; }
.voce { border: 0; background: none; text-align: left; padding: 8px 12px; cursor: pointer; color: var(--text); font-size: 14px; }
.suggerimenti .voce:hover, .suggerimenti .voce:focus { background: var(--accent-soft); outline: none; }
.voce small { color: var(--muted); margin-left: 6px; }
.risultato { padding-top: 4px; }

/* accesso */
body.accesso { display: grid; place-items: center; }
.accesso-riquadro { width: 380px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; }
.accesso-riquadro .marchio { height: auto; padding: 0; }
.accesso-riquadro h1 { margin: 12px 0 4px; font-size: 22px; }
.modulo { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.modulo label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.modulo label input { color: var(--text); }
.errore { color: var(--danger); font-size: 13px; }

/* tablet in verticale e telefono: il menu diventa un pannello a scomparsa */
@media (max-width: 900px) {
  .menu { position: fixed; inset: 0 auto 0 0; z-index: 40; width: 264px; transform: translateX(-100%); box-shadow: 0 0 40px rgba(15, 23, 42, .25); }
  html.menu-aperto .menu { transform: none; }
  html.menu-aperto .velo { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(2, 6, 23, .4); }
  html.menu-compatto .menu { width: 264px; }
  html.menu-compatto .menu .testo-menu { display: initial; }
  html.menu-compatto .menu .voce { justify-content: flex-start; padding: 0 10px; }
  .riduci { display: none; }
  .solo-stretto { display: grid; }
  .testata { padding: 0 10px; gap: 6px; }
  .vai { width: 36px; padding: 0; justify-content: center; }
  .vai .testo-vai, .vai kbd, .nome-utente { display: none; }
  .elenco { padding: 12px; }
  .barra .cerca { width: 100%; }
  .barra select { max-width: none; flex: 1 1 140px; }
  .campi.due, .due-colonne { grid-template-columns: 1fr; }
}
