:root {
  --ink: #181a1f;
  --muted: #707782;
  --soft: #9ba3ad;
  --line: #e6e8eb;
  --paper: #f7f8fa;
  --panel: #ffffff;
  --panel-soft: #f1f4f6;
  --brand: #176b5c;
  --brand-strong: #0f4c41;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #c24135;
  --green: #16845f;
  --shadow: 0 16px 34px rgba(24, 26, 31, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(23, 107, 92, 0.09), transparent 32rem),
    linear-gradient(180deg, #fbfcfd 0%, var(--paper) 100%);
  color: var(--ink);
  font-family: Geist, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 180ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 82px minmax(0, 1fr);
}

.sidebar {
  background: rgba(255, 255, 255, 0.86);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.brand-copy,
.nav-label {
  transition: opacity 140ms ease, transform 140ms ease;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-width: 48px;
  height: 38px;
  padding: 0 8px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  padding: 10px;
  text-align: left;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.nav-item:hover,
.nav-item.active {
  background: var(--panel-soft);
  color: var(--ink);
}

.nav-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: #eef1f3;
  color: var(--brand-strong);
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
}

.nav-item.active .nav-icon {
  background: var(--brand);
  color: #fff;
}

.panel-label,
.eyebrow {
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-shell.sidebar-collapsed .brand {
  grid-template-columns: 42px;
  justify-items: center;
}

.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .nav-label {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-8px);
  position: absolute;
}

.app-shell.sidebar-collapsed .icon-button {
  opacity: 1;
  pointer-events: auto;
  transform: none;
  position: static;
}

.app-shell.sidebar-collapsed .nav-item {
  justify-content: center;
}

.workspace {
  padding: 24px;
  min-width: 0;
}

.topbar,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.1;
}

h1 {
  font-size: 34px;
  font-weight: 800;
}

h2 {
  font-size: 24px;
  font-weight: 800;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

input,
select {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 11px;
  min-height: 40px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:focus,
select:focus {
  border-color: rgba(23, 107, 92, 0.55);
  box-shadow: 0 0 0 4px rgba(23, 107, 92, 0.1);
}

#global-search {
  min-width: 310px;
}

.ghost-button,
.primary-button,
.danger-button,
.small-button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  min-height: 40px;
  padding: 9px 13px;
}

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

.primary-button {
  background: var(--brand);
  color: #fff;
}

.danger-button {
  background: #f8e6e4;
  color: var(--red);
}

.small-button {
  min-height: 34px;
  padding: 7px 10px;
  background: #e7f3ef;
  color: var(--brand-strong);
}

.view {
  display: none;
}

.active-view {
  display: block;
}

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

.kpi-card,
.panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
}

.kpi-card {
  padding: 16px;
}

.kpi-card span,
.summary-row span,
label {
  color: var(--muted);
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.split-grid,
.order-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.75fr);
  gap: 16px;
}

.panel {
  padding: 16px;
}

.accent-panel {
  background: #111827;
  color: #fff;
}

.accent-panel p {
  color: #d1d5db;
  line-height: 1.55;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  background: #eef1f3;
}

.status.processato,
.status.pagato {
  background: #e2f4ed;
  color: var(--green);
}

.status.in_corso {
  background: #fff3d9;
  color: var(--amber);
}

.status.annullato,
.status.non_pagato {
  background: #f9e5e2;
  color: var(--red);
}

.inline-select {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 13px;
}

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

.stock-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.stock-card h3 {
  margin: 0 0 12px;
}

.stock-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.stock-row.out {
  color: var(--red);
  font-weight: 800;
}

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

.form-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 7px;
}

.form-grid .primary-button {
  align-self: end;
}

.line-builder {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.product-results {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.product-choice {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  display: grid;
  gap: 8px;
  box-shadow: 0 10px 22px rgba(24, 26, 31, 0.06);
}

.product-choice-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.product-choice-header span,
.mini-stock {
  color: var(--muted);
  font-size: 12px;
}

.warehouse-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.warehouse-chip {
  border: 1px solid var(--line);
  background: #edf7f3;
  border-radius: 999px;
  padding: 8px 10px;
  font-weight: 800;
  font-size: 12px;
}

.warehouse-chip.out {
  background: #f8e6e4;
  color: var(--red);
  cursor: not-allowed;
}

.warehouse-summary {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-stock {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 7px;
  background: #fff;
}

.mini-stock.out {
  color: var(--red);
  background: #fbefed;
}

.muted-cell {
  color: var(--muted);
}

.order-summary {
  align-self: start;
  display: grid;
  gap: 16px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.summary-row strong {
  font-size: 20px;
}

.positive strong {
  color: var(--green);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  transform: translateY(140%);
  transition: transform 180ms ease;
  max-width: min(360px, calc(100vw - 40px));
  z-index: 10;
}

.toast.show {
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.36);
  display: none;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.modal-backdrop.open {
  display: grid;
}

.modal {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(24, 26, 31, 0.18);
  padding: 18px;
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.modal-form {
  display: grid;
  gap: 14px;
}

@media (max-width: 1060px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .brand {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .icon-button {
    display: none;
  }

  .app-shell.sidebar-collapsed .brand-copy,
  .app-shell.sidebar-collapsed .nav-label {
    opacity: 1;
    pointer-events: auto;
    transform: none;
    position: static;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .kpi-grid,
  .stock-grid,
  .split-grid,
  .order-layout,
  .form-grid,
  .form-grid.compact {
    grid-template-columns: 1fr;
  }

  .topbar,
  .topbar-actions,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  #global-search {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 16px;
  }

  h1 {
    font-size: 30px;
  }

  h2 {
    font-size: 22px;
  }

  .nav {
    grid-template-columns: 1fr 1fr;
  }
}
