:root {
  --bg: #091326;
  --panel: rgba(23, 35, 57, .78);
  --panel-strong: rgba(31, 46, 73, .9);
  --ink: #f5f8ff;
  --muted: #aab7c8;
  --line: rgba(255, 255, 255, .1);
  --accent: #28cff2;
  --accent-strong: #2792ff;
  --warn: #ffc231;
  --danger: #ff4054;
  --green: #20cf78;
  --blue: #2d72e8;
  --shadow: 0 22px 55px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(112deg, transparent 0 16%, rgba(45,114,232,.16) 16% 20%, transparent 20% 38%, rgba(255,255,255,.08) 38% 41%, transparent 41% 66%, rgba(255,255,255,.06) 66% 69%, transparent 69%);
  background-size: 72px 72px, 72px 72px, 100% 100%;
}

.bootCheck {
  position: fixed;
  top: 12px;
  left: 280px;
  right: 24px;
  z-index: 9999;
  padding: 12px 16px;
  border-radius: 8px;
  border-left: 4px solid #ffbd2e;
  background: #ffc533;
  color: #071327;
  font-weight: 900;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
}
.bootCheck.danger {
  border-left-color: #ff3b52;
  background: #3a1723;
  color: #fff;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #071228;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  margin: 0;
  color: #f7fbff;
  font-size: 24px;
  font-weight: 900;
}
.studio {
  margin: 2px 0 14px;
  color: #f7fbff;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 4px;
}
.navGroup, .eyebrow {
  margin: 0 0 6px;
  color: #8f9db2;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 900;
}

.sidebar .eyebrow { color: #aab8c0; }
h1, h2, h3 { margin: 0; letter-spacing: 0; }
h1 { font-size: 30px; }
h2 { font-size: 26px; }
h3 { font-size: 17px; }

nav { display: grid; gap: 12px; border-top: 1px solid var(--line); padding-top: 16px; }
button, .importBtn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.08);
  color: var(--ink);
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}
button:disabled {
  opacity: .38;
  cursor: not-allowed;
  filter: grayscale(.35);
}

.nav {
  width: 100%;
  color: #dce5f2;
  background: transparent;
  border-color: transparent;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 14px;
  font-weight: 900;
}
.nav.active, .nav:hover {
  background: rgba(40, 207, 242, .12);
  border-color: rgba(255, 255, 255, .65);
  color: #fff;
}
.nav span {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(40, 207, 242, .14);
  color: var(--accent);
  font-size: 12px;
}

.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.primary:hover { background: var(--accent-strong); }
.sidebarFooter { margin-top: auto; display: grid; gap: 8px; }
.importBtn { text-align: center; }
.importBtn input { display: none; }

main {
  position: relative;
  min-width: 0;
  padding: 8px 24px 26px;
}

.hero {
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(52, 75, 117, .74), rgba(24, 34, 54, .78));
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 30px;
  margin-bottom: 14px;
}
.hero h2 {
  font-size: clamp(44px, 6vw, 74px);
  line-height: .92;
  font-weight: 900;
}
.hero p {
  margin: 12px 0 18px;
  color: #c4cedf;
  font-size: 17px;
}
.hero strong {
  align-self: flex-end;
  white-space: nowrap;
  letter-spacing: 8px;
  font-size: 14px;
}
.heroLine {
  height: 5px;
  max-width: 70%;
  border-radius: 999px;
  background: #eaf3ff;
  overflow: hidden;
}
.heroLine span {
  display: block;
  width: 78%;
  height: 100%;
  background: linear-gradient(90deg, #2792ff, #28cff2);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.filters {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.checkLine {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: var(--ink);
}
.checkLine input {
  width: 18px;
  min-height: 18px;
}
input, select, textarea {
  min-height: 38px;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(4, 12, 27, .82);
  color: var(--ink);
  padding: 8px 10px;
  font: 14px Arial, Helvetica, sans-serif;
}
textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.45;
}
.quickSearch { width: min(70vw, 760px); }
.commandBar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0 12px;
}
.blueAction { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 900; }
.greenAction { background: #18a761; border-color: #18a761; color: #fff; font-weight: 900; }
.redAction { background: #c92d3e; border-color: #c92d3e; color: #fff; font-weight: 900; }

.view { display: none; }
.view.active { display: block; }
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.moduleGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.moduleCard {
  min-height: 136px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}
.moduleCard header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}
.moduleCard h3 {
  font-size: 22px;
}
.moduleCard p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.moduleCard strong {
  font-size: 30px;
  font-weight: 900;
}
.moduleActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.moduleTag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: rgba(40, 207, 242, .14);
  color: var(--accent);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.metric, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric {
  min-height: 112px;
  padding: 18px;
}
.metric.cyan { background: #38c9eb; color: #03131f; }
.metric.red { background: var(--danger); }
.metric.yellow { background: var(--warn); color: #0a1425; }
.metric.green { background: var(--green); color: #051b13; }
.metric.dark { background: rgba(35, 49, 76, .84); }
.metric strong { display: block; font-size: 34px; margin-top: 8px; font-weight: 900; }
.metric span { color: inherit; opacity: .78; font-size: 12px; font-weight: 900; text-transform: uppercase; }
.metric small { display: block; margin-top: 6px; opacity: .75; font-size: 13px; }
.panel { padding: 18px; min-width: 0; }
.miniKpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.miniKpis div {
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(4, 12, 27, .45);
  padding: 12px;
}
.miniKpis strong {
  display: block;
  font-size: 28px;
  font-weight: 900;
}
.miniKpis span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.inlineCheck {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  min-width: 130px;
}
.inlineCheck input {
  width: 18px;
  min-height: 18px;
}
.xmlPanel { margin-bottom: 18px; }
.xmlToolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.grid.two, .split {
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(0, 1.6fr);
  gap: 18px;
}
.grid.two + .grid.two { margin-top: 18px; }
.panelHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panelHead input { max-width: 220px; }
.form { display: grid; gap: 12px; align-content: start; }
.invoiceWork {
  display: grid;
  gap: 18px;
}
.invoiceHead {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
}
.lineEditor {
  display: grid;
  gap: 8px;
}
.lineHeader,
.invoiceLine {
  display: grid;
  grid-template-columns: 150px 170px minmax(260px, 1fr) 140px 44px;
  gap: 8px;
  align-items: end;
}
.lineHeader {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.invoiceLine button {
  min-width: 38px;
  padding: 0;
}
.invoiceForm {
  overflow: visible;
}
.invoiceForm .panelHead {
  align-items: start;
}
.panelHead.compact {
  margin-bottom: 8px;
}
.panelHead.compact h4 {
  margin: 0;
  font-size: 14px;
}
.ownershipEditor,
.newSupplierInline {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(4, 12, 27, .32);
}
.ownershipEditor {
  display: grid;
  gap: 8px;
}
.ownershipHeader,
.ownershipRow {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 140px 140px 40px;
  gap: 8px;
  align-items: end;
}
.ownershipHeader {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.ownershipRow button {
  min-width: 38px;
  padding: 0;
}
.newSupplierInline.show {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) repeat(4, minmax(130px, 1fr));
  gap: 10px;
  align-items: end;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.hint { margin: -4px 0 14px; color: var(--muted); line-height: 1.45; }
.badge {
  min-width: 30px;
  border-radius: 999px;
  background: #f4e7d2;
  color: var(--warn);
  text-align: center;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.tableWrap { overflow: auto; max-height: calc(100vh - 190px); }
.tableNote {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.06);
  color: var(--muted);
  font-size: 13px;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 8px; text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: #111d33; color: #9eacc0; font-size: 12px; }
td.num, th.num { text-align: right; }
tr:hover td { background: rgba(255,255,255,.05); }
.rowActions { display: flex; gap: 6px; justify-content: flex-end; }
.rowActions button { min-height: 30px; padding: 4px 8px; }
.invoiceLine select,
.invoiceLine input {
  min-height: 44px;
}
.kmGridHeader,
.kmRow {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 120px 160px 170px 170px;
  gap: 10px;
  align-items: center;
}
.kmGridHeader {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.kmRow {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.list { display: grid; gap: 10px; }
.notice {
  border-left: 4px solid var(--warn);
  background: rgba(4, 12, 27, .55);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.35;
}
.notice.warn { border-left-color: var(--warn); background: rgba(255, 194, 49, .12); }
.notice.danger { border-left-color: var(--danger); background: rgba(255, 64, 84, .09); }
.notice strong { display: block; margin-bottom: 2px; }
.consumptionBadge {
  display: inline-flex;
  align-items: center;
  max-width: 360px;
  min-height: 28px;
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 900;
  white-space: normal;
  line-height: 1.2;
}
.consumptionBadge.ok {
  background: rgba(32, 207, 120, .16);
  color: #42f09a;
}
.consumptionBadge.neutral {
  background: rgba(255, 255, 255, .08);
  color: var(--muted);
}
.consumptionBadge.warn {
  background: rgba(255, 194, 49, .18);
  color: #ffd36a;
}
.consumptionBadge.danger {
  background: rgba(255, 64, 84, .18);
  color: #ff7a8a;
}
.consumptionBadge.block {
  background: var(--danger);
  color: #fff;
}
.sectionCode {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 4px;
}
.always {
  border-radius: 999px;
  background: var(--warn);
  color: #111;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 900;
}
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  background: #e9f5f2;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}
.pill.warn {
  background: #fff0d9;
  color: var(--warn);
}
.bars { display: grid; gap: 12px; }
.barRow { display: grid; grid-template-columns: 92px 1fr 110px; align-items: center; gap: 10px; font-size: 13px; }
.barTrack { height: 12px; background: #e6edf0; border-radius: 999px; overflow: hidden; }
.barFill { height: 100%; background: var(--blue); border-radius: 999px; }
.reportGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}
.reportFilters {
  margin-bottom: 18px;
}
.reportFilterGrid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
}
.mailTemplateGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.wideField {
  grid-column: 1 / -1;
}
.reportGrid .wide {
  grid-column: 1 / -1;
}
.printTotals {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.printTotals strong {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255,255,255,.06);
}
.invoicePrintList {
  display: grid;
  gap: 14px;
}
.invoicePrintCard {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(4, 12, 27, .28);
  break-inside: avoid;
}
.invoicePrintCard header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}
.invoicePrintCard span {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  opacity: 0;
  transform: translateY(10px);
  transition: .18s ease;
  background: #071228;
  color: #fff;
  border-radius: 8px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { align-items: stretch; flex-direction: column; }
  .metrics, .moduleGrid, .grid.two, .split, .reportGrid, .reportFilterGrid, .mailTemplateGrid { grid-template-columns: 1fr; }
  .invoiceHead,
  .lineHeader,
  .invoiceLine,
  .ownershipHeader,
  .ownershipRow,
  .newSupplierInline.show { grid-template-columns: 1fr; }
  .lineHeader { display: none; }
  .kmGridHeader { display: none; }
  .kmRow {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .tableWrap { max-height: none; }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }
  .sidebar, .topbar, button, .actions, .reportFilters { display: none !important; }
  body { display: block; background: #fff; }
  main { padding: 0; }
  .view { display: none !important; }
  body.print-riepilogo #riepilogo,
  body.print-dichiarazione #dichiarazione,
  body.print-report #report { display: block !important; }
  body:not(.print-dichiarazione):not(.print-report) #riepilogo { display: block !important; }
  .panel {
    box-shadow: none;
    border: 1px solid #d7dce5;
    padding: 8px;
    break-inside: avoid;
  }
  .hero { display: none; }
  .reportGrid {
    display: block;
  }
  .reportGrid .panel {
    margin-bottom: 8px;
  }
  .panelHead {
    margin-bottom: 6px;
  }
  .sectionCode {
    color: #333;
    margin-bottom: 3px;
  }
  .tableWrap { max-height: none; overflow: visible; }
  table { color: #111; font-size: 9px; page-break-inside: auto; }
  tr { break-inside: avoid; }
  th, td {
    padding: 4px 5px;
    white-space: normal;
  }
  th { color: #111; background: #f2f2f2; position: static; }
  h3 { font-size: 15px; color: #111; }
  .hint, .invoicePrintCard span { color: #333; }
  .printTotals {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .printTotals strong,
  .invoicePrintCard {
    border-color: #d7dce5;
    background: #fff;
    color: #111;
  }
}

/* Tema coordinato con il gestionale principale */
:root {
  --bg: #070b10;
  --panel: rgba(17, 23, 32, .9);
  --panel-strong: rgba(22, 30, 42, .94);
  --ink: #f6f8fb;
  --muted: #9ca8b8;
  --line: rgba(255, 255, 255, .1);
  --accent: #2dd4bf;
  --accent-strong: #38bdf8;
  --warn: #f2b84b;
  --danger: #f04452;
  --green: #14b8a6;
  --blue: #38bdf8;
  --shadow: 0 22px 70px rgba(0, 0, 0, .38);
}

body {
  background:
    linear-gradient(115deg, rgba(45, 212, 191, .18) 0 9%, transparent 9% 31%, rgba(242, 184, 75, .1) 31% 35%, transparent 35% 70%, rgba(240, 68, 82, .13) 70% 74%, transparent 74%),
    linear-gradient(180deg, #08111a 0%, var(--bg) 46%, #090d13 100%);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
}

body::before {
  background:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(112deg, transparent 0 16%, rgba(45,212,191,.18) 16% 20%, transparent 20% 38%, rgba(242,184,75,.12) 38% 41%, transparent 41% 66%, rgba(240,68,82,.14) 66% 69%, transparent 69%);
  background-size: 72px 72px, 72px 72px, 100% 100%;
}

.sidebar {
  background:
    linear-gradient(160deg, rgba(45, 212, 191, .13), transparent 30%),
    linear-gradient(180deg, #0b111a, #0b1018 62%, #111815);
  box-shadow: 14px 0 45px rgba(0, 0, 0, .32);
}

.dashboardLink {
  margin-bottom: 4px;
  text-decoration: none;
}

.hero {
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255,255,255,.1), transparent 32%),
    linear-gradient(135deg, rgba(45,212,191,.18), transparent 32%),
    linear-gradient(135deg, #101722, #121820 58%, #1d1417);
}

.heroLine span,
.primary {
  background: linear-gradient(90deg, var(--accent), var(--blue), var(--warn));
}

.primary {
  border-color: rgba(255,255,255,.15);
}

.nav.active,
.nav:hover {
  background: rgba(45, 212, 191, .12);
}

.nav span,
.moduleTag {
  background: rgba(45, 212, 191, .14);
  color: var(--accent);
}

.metric,
.panel,
.moduleCard {
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(12px);
}

button,
.importBtn,
input,
select {
  border-radius: 10px;
}

.saveTopBtn {
  align-self: end;
  white-space: nowrap;
}

.cloudBox {
  display: grid;
  grid-template-columns: minmax(140px, auto) auto auto;
  gap: 8px;
  align-items: end;
}

.cloudPill,
.ghostAction {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, .07);
  font-size: 12px;
  font-weight: 900;
}

.cloudPill {
  display: grid;
  place-items: center;
  text-align: center;
}

.cloudPill.connected {
  color: #06120f;
  background: linear-gradient(135deg, var(--accent), #8bd8a2);
}

.cloudPill.warning {
  color: #1a1203;
  background: linear-gradient(135deg, var(--warn), #f7d47a);
}

.ghostAction {
  cursor: pointer;
}

.ghostAction:hover {
  border-color: rgba(45, 212, 191, .55);
  color: #fff;
}

.ghostAction:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.sidebarFooter [hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .cloudBox {
    grid-template-columns: 1fr;
  }
}
