:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --border: #dde1e7;
  --accent: #1f5fbf;
  --accent-soft: #e8f0fc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #067647;
  --ok-soft: #e7f6ee;
  --warn: #9a6700;
  --warn-soft: #fff6dd;
  --sidebar: #17202f;
  --radius: 8px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.6rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Layout */
.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #cfd6e3; padding: 1rem 0.75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; padding: 0.25rem 0.6rem 1rem; }
.sidebar nav a { display: block; color: #cfd6e3; padding: 0.42rem 0.6rem; border-radius: 6px; margin-bottom: 2px; }
.sidebar nav a:hover { background: #253045; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar .sez { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: #7f8aa0; margin: 1rem 0.6rem 0.3rem; }
.sidebar form { margin-top: 1.5rem; padding: 0 0.6rem; }
.sidebar .utente { font-size: 0.85rem; color: #9aa5b8; padding: 0 0.6rem; margin-top: 1.5rem; }
main { padding: 1.5rem 2rem 3rem; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head .azioni { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn.menu-toggle { display: none; }

/* Pannelli */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; }
.card .label { color: var(--muted); font-size: 0.82rem; }
.card .value { font-size: 1.4rem; font-weight: 650; margin-top: 0.2rem; font-variant-numeric: tabular-nums; }
.card a.value { display: block; color: var(--text); }

/* Tabelle */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 650; background: #fafbfc; }
tr.inattivo td { color: var(--muted); }

/* Form */
form.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.75rem 1rem; }
form.grid .full, .full { grid-column: 1 / -1; }
label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 0.2rem; font-weight: 550; }
input, select, textarea {
  width: 100%; font: inherit; padding: 0.45rem 0.6rem; border: 1px solid #c7ccd4; border-radius: 6px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; margin-right: 0.4rem; }
.check { display: flex; align-items: center; font-size: 0.95rem; color: var(--text); font-weight: normal; }
textarea { min-height: 70px; }
.filtri { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filtri > div { min-width: 140px; }
.filtri input[type=search] { min-width: 240px; }

.btn {
  display: inline-flex; align-items: center; gap: 0.35rem; font: inherit; font-weight: 550; font-size: 0.92rem;
  padding: 0.45rem 0.9rem; border-radius: 6px; border: 1px solid #c7ccd4; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #194f9f; }
.btn.danger { color: var(--danger); border-color: #f0b4ae; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 0.25rem 0.55rem; font-size: 0.82rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.badge { display: inline-block; font-size: 0.75rem; padding: 0.1rem 0.45rem; border-radius: 999px; background: #eef0f3; color: #475467; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }

.flash { padding: 0.7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #a6e0c0; color: var(--ok); }
.flash.errore { background: var(--danger-soft); border-color: #f0b4ae; color: var(--danger); }
.flash.info { background: var(--accent-soft); border-color: #b9cff2; color: var(--accent); }

.paginazione { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.75rem; }

/* Righe documento (DDT / fattura) */
.righe td { padding: 0.3rem 0.4rem; vertical-align: middle; }
.righe input, .righe select { padding: 0.3rem 0.45rem; }
.righe .q { width: 90px; }
.righe .rame { width: 110px; }
.voce-box { position: relative; }
.suggerimenti { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,0.12); max-height: 280px; overflow-y: auto; }
.suggerimenti div { padding: 0.35rem 0.6rem; cursor: pointer; display: flex; justify-content: space-between; gap: 1rem; }
.suggerimenti div.sel, .suggerimenti div:hover { background: var(--accent-soft); }
.suggerimenti .nuova { color: var(--accent); font-style: italic; }

.login-box { max-width: 360px; margin: 12vh auto; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 2rem; }
.login-box h1 { margin-bottom: 1rem; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 1rem; }

.chart-box { position: relative; height: 340px; }
.stack > * + * { margin-top: 0.75rem; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: 0.88rem; }
.dl dd { margin: 0; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; width: 240px; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: none; }
  .btn.menu-toggle { display: inline-flex; margin-bottom: 0.75rem; }
  main { padding: 1rem; }
}
@media print {
  .sidebar, .head .azioni, .filtri, .menu-toggle { display: none !important; }
  .app { display: block; }
  main { padding: 0; }
}
