:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f7faff;
  --panel-strong: #eaf2ff;
  --line: #d5dbe7;
  --line-soft: #edf1f7;
  --text: #0b1c30;
  --muted: #5d6675;
  --primary: #0b1c30;
  --primary-2: #131b2e;
  --action: #0051d5;
  --action-soft: #dbe7ff;
  --green: #047857;
  --green-soft: #d1fae5;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --red: #ba1a1a;
  --red-soft: #ffdad6;
  --shadow-pop: 0 18px 45px -28px rgba(11, 28, 48, .32);
  --shadow-panel: 0 14px 32px -28px rgba(11, 28, 48, .30);
  --radius: 8px;
}

* { box-sizing: border-box; }

svg {
  display: block;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg use {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #fbfdff 0%, var(--bg) 340px),
    var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.hidden { display: none !important; }

h1,
h2 {
  margin: 0;
  color: var(--primary);
  font-family: "Hanken Grotesk", Inter, system-ui, sans-serif;
  letter-spacing: 0;
}

h1 { font-size: clamp(28px, 3vw, 38px); line-height: 1.05; }
h2 { font-size: 28px; line-height: 1.15; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  line-height: 16px;
  font-weight: 700;
  letter-spacing: .05em;
}

.muted { color: var(--muted); }
.right { text-align: right; }

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.92) 0%, rgba(245,247,251,.96) 100%),
    radial-gradient(circle at top left, rgba(0,81,213,.10), transparent 30%),
    radial-gradient(circle at bottom right, rgba(11,28,48,.08), transparent 28%),
    linear-gradient(90deg, rgba(11,28,48,.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(11,28,48,.05) 1px, transparent 1px),
    var(--bg);
  background-size: auto, auto, 44px 44px, 44px 44px, auto;
}

.auth-shell {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid rgba(213, 219, 231, .92);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}

.auth-brand {
  min-height: 520px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px;
  background:
    linear-gradient(145deg, rgba(0,81,213,.16), transparent 34%),
    linear-gradient(180deg, #0b1c30 0%, #07111f 100%);
  color: #fff;
}

.auth-brand .eyebrow {
  color: rgba(255,255,255,.62);
}

.auth-brand h1 {
  max-width: 420px;
  color: #fff;
  font-size: clamp(38px, 5vw, 56px);
}

.auth-copy {
  max-width: 430px;
  margin: 18px 0 0;
  color: rgba(255,255,255,.74);
  font-size: 16px;
  line-height: 1.6;
}

.auth-logo {
  width: min(280px, 100%);
  min-height: 68px;
  display: flex;
  align-items: center;
  margin-bottom: 36px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255,255,255,.14);
}

.auth-logo img {
  width: 100%;
  height: auto;
  object-fit: contain;
}

.auth-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 34px;
}

.auth-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  color: rgba(255,255,255,.78);
  font-size: 12px;
  font-weight: 700;
}

.auth-box {
  align-self: center;
  width: 100%;
  max-width: 420px;
  justify-self: center;
  background: var(--panel);
  padding: 44px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  margin-bottom: 22px;
  color: var(--primary);
  font-family: "Hanken Grotesk", Inter, system-ui, sans-serif;
  font-size: 20px;
  font-weight: 800;
}

.auth-box h1 { margin-bottom: 24px; }
.auth-box h2 { margin-bottom: 24px; }

label {
  display: block;
  margin: 14px 0 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fbfcff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input {
  height: 42px;
  padding: 0 12px;
}

select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  padding: 10px 12px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--action);
  box-shadow: 0 0 0 3px rgba(0, 81, 213, .14);
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--primary) 0%, #07111f 100%);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 0 14px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .08s ease;
}

button:hover { background: #000; }
button:active { transform: translateY(1px); }
.auth-box button { width: 100%; margin-top: 18px; }
.form-error {
  min-height: 18px;
  margin: 12px 0 0;
  color: var(--red);
  font-size: 13px;
}

.ghost {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--line);
}

.ghost:hover {
  background: var(--panel-soft);
  color: var(--primary);
}

.danger { color: var(--red); }

.menu-toggle {
  display: none;
  width: 42px;
  min-height: 42px;
  padding: 0;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-direction: column;
}

.menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transform-origin: center;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 246px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background:
    radial-gradient(circle at 20% 0%, rgba(0,81,213,.28), transparent 34%),
    linear-gradient(180deg, #061a31 0%, #031021 100%);
  color: #fff;
  padding: 20px 14px;
  border-right: 1px solid rgba(255,255,255,.10);
}

.logo-panel {
  min-height: 76px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,.12);
  margin-bottom: 16px;
  padding: 0 8px;
  cursor: pointer;
}

.logo-panel:hover { opacity: .86; }

.logo-panel img {
  max-width: 184px;
  max-height: 48px;
  object-fit: contain;
}

nav {
  display: grid;
  gap: 4px;
}

nav button {
  width: 100%;
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: rgba(255,255,255,.74);
  border-radius: 7px;
  font-weight: 600;
  min-height: 42px;
  padding: 0 10px;
}

nav button.active,
nav button:hover {
  background: linear-gradient(90deg, rgba(0,81,213,.95), rgba(0,81,213,.70));
  color: #fff;
  box-shadow: 0 10px 22px -16px rgba(0,81,213,.9);
}

nav button svg {
  width: 18px;
  height: 18px;
  color: currentColor;
}

.content {
  min-width: 0;
  padding: 24px 28px 36px;
}

.topbar,
.page-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-actions.compact {
  margin: 18px 0 10px;
}

.page-actions.compact h2 {
  font-size: 18px;
}

.topbar {
  align-items: center;
  margin: -4px -4px 22px;
  padding: 4px 4px 18px;
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  font-size: clamp(24px, 2.4vw, 32px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.top-search {
  width: min(280px, 28vw);
  height: 42px;
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.top-search svg {
  width: 17px;
  height: 17px;
}

.top-search input {
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.icon-only {
  width: 42px;
  min-height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 8px;
}

.icon-only svg {
  width: 18px;
  height: 18px;
}

.user-chip {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.user-chip span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e9f1ff;
  color: #0f4fb8;
  font-size: 11px;
  font-weight: 900;
}

.user-chip strong {
  color: var(--primary);
  font-size: 12px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.cards article,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
}

.cards article {
  position: relative;
  min-height: 122px;
  padding: 18px;
  overflow: hidden;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.cards article::after {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 14px;
  height: 24px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(0,81,213,.12), rgba(0,81,213,.55), rgba(0,81,213,.18));
  clip-path: polygon(0 70%, 14% 52%, 28% 62%, 43% 35%, 58% 50%, 72% 20%, 88% 44%, 100% 30%, 100% 100%, 0 100%);
}

.cards article:nth-child(6)::after,
.cards article:nth-child(8)::after {
  background:
    linear-gradient(90deg, rgba(217,79,69,.12), rgba(217,79,69,.55), rgba(217,79,69,.18));
}

.cards article:hover {
  border-color: #b8c5d9;
  transform: translateY(-1px);
}

.cards span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
}

.cards strong {
  color: var(--primary);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(22px, 2.1vw, 32px);
  line-height: 1;
  overflow-wrap: anywhere;
  position: relative;
  z-index: 1;
}

.kpi-icon,
.section-icon {
  display: inline-grid;
  place-items: center;
  border: 1px solid #d7e2f2;
  background: #eef6ff;
  color: #2563eb;
}

.kpi-icon {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.kpi-icon svg {
  width: 20px;
  height: 20px;
}

.cards article:nth-child(2n) .kpi-icon {
  background: #f7f7fb;
  color: #111827;
}

.cards article:nth-child(6) .kpi-icon,
.cards article:nth-child(8) .kpi-icon {
  background: #fff1f0;
  color: #d94f45;
}

.section-icon {
  width: 32px;
  height: 32px;
  margin-bottom: 10px;
  border-radius: 7px;
}

.section-icon svg {
  width: 17px;
  height: 17px;
}

.scadenzario-cards article:nth-child(1) {
  border-left: 4px solid var(--action);
}

.scadenzario-cards article:nth-child(2) {
  border-left: 4px solid #d94f45;
}

.scadenzario-cards article:nth-child(3) {
  border-left: 4px solid #111827;
}

.scadenzario-cards article:nth-child(4) {
  border-left: 4px solid #f59e0b;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e5eef9;
  color: var(--primary);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.badge.credito {
  background: #dcfce7;
  color: #166534;
}

.badge.debito {
  background: #fee2e2;
  color: #991b1b;
}

.badge.scaduto {
  background: #fef3c7;
  color: #92400e;
}

.row-overdue td {
  background: #fffbeb;
}

.panel {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.panel p:last-child {
  color: var(--muted);
  line-height: 1.6;
  max-width: 820px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .95fr);
  gap: 14px;
}

.chart-card {
  min-width: 0;
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-panel);
}

.chart-card:hover,
.cards article:hover {
  box-shadow: 0 20px 38px -30px rgba(11, 28, 48, .45);
}

.chart-card-wide {
  grid-row: span 2;
}

.chart-card header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.chart-card h2 {
  font-size: 18px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chart-legend span::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--action);
}

.chart-legend .legend-costs::before { background: #d94f45; }
.chart-legend .legend-orders::before { background: #111827; }

.bar-chart {
  min-height: 300px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
  padding-top: 14px;
}

.bar-group {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.bar-stack {
  height: 214px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #f8fbff 0%, #fff 100%);
}

.bar-stack i {
  width: 22%;
  min-width: 10px;
  border-radius: 4px 4px 0 0;
  background: var(--action);
}

.bar-stack .costs { background: #d94f45; }
.bar-stack .orders { background: #111827; }

.bar-group footer {
  display: grid;
  gap: 4px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.bar-group footer strong {
  color: var(--primary);
  font-size: 12px;
}

.line-chart {
  display: grid;
  gap: 12px;
  min-height: 264px;
}

.line-chart svg {
  width: 100%;
  min-height: 214px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, #f8fbff 0%, #fff 100%);
}

.grid-lines line {
  stroke: #e5eaf2;
  stroke-width: 1;
}

.line-series {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sales-line { stroke: #2563eb; }
.costs-line { stroke: #d94f45; }
.line-dot { stroke: #fff; stroke-width: 2; }
.sales-dot { fill: #2563eb; }
.costs-dot { fill: #d94f45; }

.axis-labels text {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.line-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.line-summary span {
  padding: 11px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fbfcff;
  color: var(--primary);
  font-weight: 800;
}

.donut-panel {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

.donut {
  width: 148px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #fff 0 49%, transparent 50%),
    conic-gradient(var(--segments));
  border: 1px solid var(--line-soft);
  box-shadow: inset 0 0 0 12px #f8fafc, 0 18px 30px -28px rgba(11,28,48,.58);
}

.donut div {
  width: 86px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  border-radius: 50%;
  background: #fff;
}

.donut strong {
  color: var(--primary);
  font-size: 18px;
}

.donut span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.donut-legend {
  display: grid;
  gap: 8px;
}

.donut-legend section {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fbfcff;
}

.donut-legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.donut-legend span,
.donut-legend strong {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.donut-legend span {
  color: var(--muted);
}

.status-list,
.rank-list,
.cash-panel {
  display: grid;
  gap: 10px;
}

.status-item,
.rank-item,
.cash-row {
  display: grid;
  gap: 7px;
  padding: 11px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fbfcff;
}

.status-item header,
.rank-item header,
.cash-row header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.status-item strong,
.rank-item strong,
.cash-row strong {
  color: var(--primary);
}

.status-item span,
.rank-item span,
.cash-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.progress i {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  border-radius: inherit;
  background: var(--action);
}

.progress.costs i { background: #d94f45; }
.progress.dark i { background: #111827; }

.cash-balance {
  padding: 16px;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #0b1c30 0%, #0051d5 100%);
  color: #fff;
}

.cash-balance span {
  display: block;
  margin-bottom: 8px;
  color: rgba(255,255,255,.78);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.cash-balance strong {
  color: #fff;
  font-size: 26px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.toolbar.document-toolbar {
  grid-template-columns: auto minmax(240px, 1fr) auto;
}

.segmented-control {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f4f7fb;
  flex: 0 0 auto;
}

.segmented-control button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 5px;
  color: #53637a;
  background: transparent;
  box-shadow: none;
}

.segmented-control button.active {
  color: #fff;
  background: #0b5bd3;
}

.select-search {
  margin-bottom: 5px;
  background: #f8fafc;
}

select[multiple] {
  min-height: 126px;
  padding: 6px;
}

select[multiple] option {
  padding: 7px 8px;
  border-radius: 4px;
}

.field-help {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border-radius: 4px;
  color: #0756bb;
  background: #eaf2ff;
  font-size: 11px;
  font-weight: 800;
}

.danger-text {
  color: #b42318;
  font-weight: 700;
}

.warning-text {
  color: #a15c00;
  font-weight: 700;
}

#ddt-righe input,
#ddt-righe select {
  min-width: 108px;
}

#ddt-righe td:first-child select {
  min-width: 230px;
}

.enrichment-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fbfcff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.enrichment-preview {
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  background: #eef2ff;
  color: #1e3a8a;
  line-height: 1.45;
}

.registry-preview {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--action);
  border-radius: var(--radius);
  background: #fbfcff;
  box-shadow: var(--shadow-panel);
}

.registry-preview header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.registry-preview h3 {
  margin: 4px 0 0;
  color: var(--primary);
  font-size: 22px;
}

.registry-preview .preview-code {
  display: inline-flex;
  width: fit-content;
  padding: 5px 8px;
  border-radius: 4px;
  background: #e5eef9;
  color: var(--primary);
  font-size: 11px;
  font-weight: 900;
}

.registry-preview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.registry-preview-grid div {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel);
}

.registry-preview-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.registry-preview-grid strong,
.registry-preview-grid p {
  margin: 0;
  color: var(--primary);
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.preview-subsection {
  display: grid;
  gap: 10px;
}

.preview-subsection h4 {
  margin: 0;
  color: var(--primary);
  font-size: 15px;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.document-flow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: -8px 0 16px;
}

.document-flow span {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--action);
  border-radius: var(--radius);
  background: #fbfcff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-panel);
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  background: var(--panel);
}

th,
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

th {
  background: #f7f9fd;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .05em;
}

td strong:first-child {
  color: #000;
}

tbody tr:hover {
  background: #f3f8ff;
}

.selected-row,
.selected-row:hover {
  background: #edf6ff;
  box-shadow: inset 3px 0 0 var(--action);
}

.clickable-row {
  cursor: pointer;
}

tr:last-child td { border-bottom: 0; }

.row-actions {
  display: inline-flex;
  justify-content: flex-end;
  gap: 8px;
}

.row-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(11, 28, 48, .48);
  backdrop-filter: blur(2px);
}

.modal-box {
  width: min(940px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 22px;
  box-shadow: var(--shadow-pop);
}

.document-editor {
  position: static;
  inset: auto;
  z-index: auto;
  display: block;
  place-items: initial;
  padding: 0;
  margin: 0 0 18px;
  background: transparent;
  backdrop-filter: none;
  scroll-margin-top: 80px;
}

.document-editor .modal-box {
  width: 100%;
  max-height: none;
  overflow: visible;
  box-shadow: none;
  border-color: var(--line);
}

.document-editor .modal-head {
  align-items: center;
}

.document-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.document-summary article {
  min-height: 82px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fbfcff;
}

.document-summary.compact-summary article {
  min-height: 72px;
}

.document-summary span,
.document-totals span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.document-summary strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--primary);
  font-size: 16px;
}

.document-totals {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 0 0;
}

.document-totals span {
  min-width: 160px;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.document-totals strong {
  color: var(--primary);
  font-size: 18px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.icon-btn {
  width: 34px;
  min-height: 34px;
  padding: 0;
  background: var(--panel-soft);
  color: var(--primary);
}

.icon-btn:hover { background: var(--panel-strong); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label {
  margin: 0;
  display: grid;
  gap: 6px;
}

.form-grid .wide { grid-column: 1 / -1; }

.invoice-ddt-picker { display: grid; gap: 10px; min-width: 0; }
.invoice-ddt-options { max-height: 260px; overflow: auto; border-block: 1px solid var(--line); }
.form-grid .invoice-ddt-option {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.invoice-ddt-option input { width: 18px; height: 18px; margin: 0; }
.invoice-ddt-option > span { display: grid; gap: 4px; overflow-wrap: anywhere; }
.invoice-ddt-option:has(input:checked) { background: #edf7f4; }
.invoice-ddt-option:has(input:disabled) { opacity: .55; cursor: default; }
.invoice-ddt-picker output { text-align: right; font-weight: 600; }
@media (max-width: 540px) {
  .form-grid .invoice-ddt-option { grid-template-columns: 20px minmax(0, 1fr); }
  .invoice-ddt-option > strong { grid-column: 2; }
}

.modal-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.line-section {
  margin-top: 10px;
}

#acquisto-righe input,
#acquisto-righe select,
#ordine-righe input,
#ordine-righe select {
  min-width: 110px;
}

#acquisto-righe select,
#ordine-righe select {
  min-width: 260px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.overview-grid .preview-card strong {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 24px;
}

.preview-card {
  display: grid;
  gap: 7px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fbfcff;
}

.preview-card span {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .05em;
}

.preview-card strong {
  color: #000;
  font-size: 18px;
}

.preview-card p,
.preview-note {
  color: var(--muted);
  line-height: 1.45;
}

.preview-note {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-left: 3px solid var(--primary);
  background: var(--panel-soft);
}

.preview-lines table {
  min-width: 760px;
}

@media (max-width: 960px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }
  .auth-brand {
    min-height: auto;
    padding: 32px;
  }
  .auth-brand h1 {
    font-size: 36px;
  }
  .auth-logo {
    width: min(240px, 100%);
    margin-bottom: 24px;
  }
  .auth-box {
    max-width: none;
    padding: 32px;
  }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(82vw, 320px);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform .18s ease;
    box-shadow: var(--shadow-pop);
  }
  body.menu-open .sidebar { transform: translateX(0); }
  body.menu-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(11, 28, 48, .38);
  }
  .menu-toggle { display: inline-flex; }
  .content { padding: 20px; }
  .cards { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .topbar {
    flex-wrap: wrap;
  }
  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .top-search {
    width: min(340px, 100%);
    flex: 1 0 220px;
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .chart-card-wide {
    grid-row: auto;
  }
  .page-actions,
  .toolbar {
    grid-template-columns: 1fr;
    display: grid;
  }
  .toolbar.document-toolbar {
    grid-template-columns: 1fr;
  }
  .registry-preview-grid {
    grid-template-columns: 1fr 1fr;
  }
  .button-group {
    justify-content: stretch;
  }
  .button-group button {
    flex: 1 1 180px;
  }
  .document-flow {
    grid-template-columns: 1fr;
  }
  .document-summary {
    grid-template-columns: 1fr 1fr;
  }
  .document-totals {
    display: grid;
  }
  .form-grid { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: 1fr; }
  .modal-actions { grid-template-columns: 1fr; }
  .modal-actions span { display: none; }
}

@media (max-width: 560px) {
  .auth-screen { padding: 14px; }
  .auth-brand { padding: 24px; }
  .auth-brand h1 { font-size: 32px; }
  .auth-copy { font-size: 14px; }
  .auth-box { padding: 24px; }
  .content { padding: 16px; }
  .cards { grid-template-columns: 1fr; }
  .chart-card {
    padding: 16px;
  }
  .chart-card header {
    display: grid;
  }
  .registry-preview header {
    display: grid;
  }
  .registry-preview-grid {
    grid-template-columns: 1fr;
  }
  .chart-legend {
    justify-content: flex-start;
  }
  .topbar-actions .user-chip,
  .topbar-actions .icon-only {
    display: none;
  }
  .topbar-actions {
    width: auto;
    overflow: visible;
    padding: 0;
  }
  .topbar-actions .top-search {
    display: none;
  }
  .bar-chart {
    min-height: auto;
    grid-template-columns: 1fr;
  }
  .bar-stack {
    height: 120px;
  }
  .line-summary,
  .donut-panel {
    grid-template-columns: 1fr;
  }
  .donut {
    margin: 0 auto;
  }
  .topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
  }
  .document-summary {
    grid-template-columns: 1fr;
  }
  h1 { font-size: 30px; }
  h2 { font-size: 24px; }
}
