:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --surface-muted: #eef3fb;
  --text: #172033;
  --muted: #667085;
  --border: #d8e1ef;
  --border-strong: #c8d5ea;
  --primary: #1f6feb;
  --primary-strong: #1458c5;
  --primary-soft: #e8f1ff;
  --success: #16803c;
  --success-soft: #e4f6ea;
  --danger: #b42318;
  --danger-soft: #fde8e7;
  --warning: #b45309;
  --warning-soft: #fff1db;
  --sidebar: #121a2c;
  --sidebar-soft: #1d2740;
  --sidebar-text: #dce5f6;
  --shadow-sm: 0 6px 16px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 16px 36px rgba(15, 23, 42, 0.10);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f7f9fd 0%, var(--bg) 100%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: 100vh;
  padding: 22px 16px;
  background: linear-gradient(180deg, var(--sidebar) 0%, #162139 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: grid;
  gap: 4px;
  padding: 4px 6px 8px;
}

.brand .eyebrow {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #94a7d0;
}

.brand .title {
  font-size: 28px;
  font-weight: 700;
  color: #ffffff;
}

.brand .subtitle {
  font-size: 13px;
  color: #9fb3d9;
}

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

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  background: transparent;
  color: #d8e2f3;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
}

.nav-link.active {
  background: linear-gradient(180deg, #233353 0%, #1d2a44 100%);
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.logout {
  justify-content: center;
}

.userbox {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
}

.userrole {
  font-size: 12px;
  color: #9fb3d9;
}

.username {
  font-weight: 700;
  color: #ffffff;
}

.main,
.login-main {
  width: 100%;
  padding: 28px;
}

.main {
  max-width: 1640px;
}

.login-body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top left, rgba(31, 111, 235, 0.10), transparent 34%),
    radial-gradient(circle at bottom right, rgba(18, 26, 44, 0.14), transparent 38%),
    linear-gradient(180deg, #f8faff 0%, #eef3fb 100%);
}

.login-main {
  width: 100%;
  max-width: 960px;
  padding: 28px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-head h1,
.login-card h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.05;
}

.page-head p,
.login-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

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

.actions form {
  margin: 0;
  display: inline-flex;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi,
.panel,
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.kpi {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.kpi span {
  font-size: 13px;
  color: var(--muted);
}

.kpi strong {
  font-size: 28px;
  line-height: 1.1;
}

.panel {
  padding: 18px;
  overflow: auto;
}

.form-panel {
  overflow: visible;
  position: relative;
  z-index: 1;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

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

th,
td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  z-index: 1;
}

tbody tr:hover {
  background: var(--surface-soft);
}

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

.filters {
  margin-bottom: 18px;
}

.form-grid {
  margin: 0;
}

.form-grid.single {
  grid-template-columns: 1fr;
}

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

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span,
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

input,
select,
button,
.button-link,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font: inherit;
}

input,
select,
textarea {
  background: #ffffff;
  color: var(--text);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #8bb4ff;
  box-shadow: 0 0 0 4px rgba(31, 111, 235, 0.12);
}

input[readonly] {
  background: var(--surface-muted);
  color: var(--muted);
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #ffffff;
  border: none;
  cursor: pointer;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}

button:hover,
.button-link:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

button:active,
.button-link:active {
  transform: translateY(0);
}

.button-link.secondary,
.secondary-btn,
.small-btn.secondary-btn {
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.small-btn {
  min-height: 36px;
  padding: 0 12px;
}

.danger-btn {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f1b9b4;
}

.stack-form {
  display: grid;
  gap: 20px;
}

.dynamic-box {
  display: block;
}

.subhead {
  margin: 2px 0 0;
  font-size: 18px;
}

.helper-box,
.total-box {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 13px;
}

.total-box {
  color: var(--text);
  font-weight: 700;
}

.search-status {
  margin-top: 6px;
  min-height: 18px;
  font-size: 13px;
  color: var(--muted);
}

.product-grid {
  grid-template-columns: minmax(180px, 0.9fr) minmax(360px, 1.8fr) minmax(140px, 0.7fr) minmax(160px, 0.8fr) minmax(150px, 0.8fr) auto;
  align-items: end;
}

.product-picker {
  display: grid;
  gap: 6px;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.product-picker-wide {
  grid-column: span 1;
}

.search-combobox {
  position: relative;
  overflow: visible;
  z-index: 1;
}

.product-picker.search-open,
.search-combobox.search-open {
  z-index: 4000;
}

.search-combobox input {
  padding-right: 14px;
}

.selected-product {
  min-height: 60px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px dashed var(--border-strong);
  background: var(--surface-soft);
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.selected-product strong,
.selected-product span,
.selected-product small {
  display: block;
  white-space: normal;
}

.selected-product small {
  color: var(--muted);
}

.selected-product-active {
  border-style: solid;
  border-color: #b9cef5;
  background: var(--primary-soft);
  color: var(--text);
}

.results-panel {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.floating-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 4500;
  box-shadow: var(--shadow-md);
}

.hidden-results {
  display: none;
}

.result-item {
  width: 100%;
  min-height: 76px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
  display: grid;
  gap: 6px;
  white-space: normal;
  line-height: 1.35;
}

.result-item strong,
.result-item span,
.result-item small {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.result-item strong {
  font-size: 13px;
}

.result-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.result-name {
  font-size: 14px;
  font-weight: 600;
}

.result-price {
  flex-shrink: 0;
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 700;
}

.result-item small {
  color: var(--muted);
}

.active-result,
.result-item:hover {
  background: var(--primary-soft);
  border-color: #a6c3f7;
}

.align-end {
  align-items: end;
}

.inner-panel {
  padding: 0;
}

.login-card {
  width: 100%;
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(320px, 520px);
  align-items: stretch;
  gap: 20px;
}

.login-intro {
  display: grid;
  gap: 18px;
  padding: 28px;
  border-radius: 8px;
  background: linear-gradient(180deg, #16233a 0%, #1e3050 100%);
  color: #ffffff;
  box-shadow: var(--shadow-md);
}

.login-brand-mark {
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 24px;
  font-weight: 700;
}

.login-brand-text {
  display: grid;
  gap: 8px;
}

.login-eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a9bfeb;
}

.login-intro h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.05;
}

.login-intro p {
  margin: 0;
  font-size: 17px;
  color: #dbe6fb;
}

.login-card-head {
  display: grid;
  gap: 6px;
  margin-bottom: 20px;
}

.login-card-head h2 {
  margin: 0;
  font-size: 24px;
}

.login-card-head p {
  margin: 0;
  color: var(--muted);
}

.alert,
.success {
  margin: 0 0 18px;
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
}

.alert {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f4b4ae;
}

.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: #b5e2c3;
}

@media (max-width: 1280px) {
  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .product-picker-wide {
    grid-column: span 2;
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: auto;
    gap: 12px;
    padding: 14px;
  }

  .main,
  .login-main {
    padding: 18px;
  }

  .page-head,
  .grid-2,
  .filters,
  .form-grid,
  .compact-2,
  .product-grid,
  .login-shell {
    grid-template-columns: 1fr;
  }

  .page-head {
    display: grid;
  }

  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav-link {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .userbox {
    margin-top: 0;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
  }

  .logout {
    width: auto;
    min-width: 92px;
  }

  .product-picker-wide {
    grid-column: span 1;
  }

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

  th,
  td {
    white-space: normal;
  }
}

@media (max-width: 740px) {
  .main,
  .login-main {
    padding: 14px;
  }

  .sidebar {
    padding: 12px;
  }

  .brand .title {
    font-size: 24px;
  }

  .page-head h1,
  .login-card h1 {
    font-size: 26px;
  }

  .page-head p,
  .login-card p,
  .login-intro p {
    font-size: 14px;
  }

  .panel,
  .login-card,
  .login-intro {
    padding: 14px;
  }

  .actions,
  .actions form {
    width: 100%;
  }

  .actions > *,
  .actions form > * {
    flex: 1 1 100%;
  }

  .helper-box,
  .total-box {
    width: 100%;
    justify-content: center;
    border-radius: 8px;
  }

  .results-panel {
    max-height: 44vh;
    padding: 6px;
  }

  .result-item {
    min-height: auto;
    padding: 11px 12px;
  }

  .result-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .selected-product {
    min-height: 72px;
  }

  .login-shell {
    grid-template-columns: 1fr;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tbody tr {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }

  .responsive-table td {
    padding: 8px 0;
    border-bottom: none;
    display: grid;
    grid-template-columns: minmax(92px, 110px) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
  }

  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .responsive-table td[data-label="Azioni"] {
    grid-template-columns: 1fr;
  }

  .responsive-table td[data-label="Azioni"]::before {
    margin-bottom: 2px;
  }
}

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

  .page-head {
    gap: 12px;
  }
}
