:root {
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-soft: #f7f9fb;
  --field: #ffffff;
  --ink: #102031;
  --ink-soft: #4b5b6a;
  --accent: #0d4f8b;
  --accent-2: #0e6b5c;
  --warn: #ad6c00;
  --warning-bg: #fff0d2;
  --warning-ink: #563300;
  --err: #8f1f26;
  --line: #d0d8df;
  --shadow: 0 10px 30px rgba(16, 32, 49, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 10% 10%, #f8fbff, #e8eef3 45%, #dde5ed);
  color: var(--ink);
  font-family: "Cambria", "Palatino Linotype", Georgia, serif;
}

body[data-text-size="piccolo"] { font-size: 14px; }
body[data-text-size="medio"] { font-size: 16px; }
body[data-text-size="grande"] { font-size: 18px; }

body[data-theme="notte"] {
  --bg: #1a2129;
  --panel: #26323d;
  --panel-soft: #32404c;
  --field: #1c2731;
  --ink: #edf4f8;
  --ink-soft: #c5d0d8;
  --accent: #4da3df;
  --accent-2: #57bea8;
  --line: #52616d;
  --warning-bg: #5a4300;
  --warning-ink: #fff3c4;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  background: #1a2129;
}

body[data-theme="alto_contrasto"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-soft: #ffffff;
  --field: #ffffff;
  --ink: #000000;
  --ink-soft: #111111;
  --accent: #003c8f;
  --accent-2: #006b31;
  --line: #000000;
  --warning-bg: #fff2a8;
  --warning-ink: #000000;
  --shadow: none;
  background: #ffffff;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.layout {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #17324a, #0c2237);
  color: #d7e6f4;
  padding: 24px 16px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  margin: 0 0 20px;
  font-size: 22px;
  letter-spacing: 0.7px;
}

.brand small {
  display: block;
  font-size: 12px;
  opacity: 0.85;
  margin-top: 3px;
}

.brand-logo {
  display: block;
  width: 68px;
  height: 68px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  margin-bottom: 10px;
}

.brand-name {
  display: block;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: #d7e6f4;
  background: rgba(255, 255, 255, 0.04);
}

.menu a:hover,
.menu a.active {
  background: rgba(255, 255, 255, 0.14);
}

.main {
  padding: 20px;
  max-width: 1680px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.topbar h2 {
  margin: 0;
  font-size: 22px;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.section-heading h3 {
  margin: 0;
  font-size: 17px;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 10px 12px;
  min-height: 42px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}

.btn {
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(0.95);
}

.btn.secondary {
  background: var(--panel-soft);
  border-color: #687887;
  color: var(--ink);
}

.btn.success { background: #08795b; border-color: #08795b; }
.btn.warning { background: #b76e00; border-color: #b76e00; }

.btn.danger {
  background: #fff;
  border-color: #9f2b34;
  color: #9f2b34;
}

.btn.small {
  font-size: 12px;
  padding: 5px 8px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.detail-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin: 16px 0;
}

.detail-tab {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  padding: 9px 12px;
}

.detail-tab.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.detail-code {
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 400;
}

.catalog-modal-body {
  max-width: 1120px;
}

.agent-detail-modal {
  max-width: 1180px;
}

.catalog-choice-grid {
  max-height: 360px;
  overflow-y: auto;
}

.catalog-detail {
  display: grid;
  grid-template-columns: minmax(180px, 300px) 1fr;
  gap: 20px;
  padding: 12px 0 20px;
}

.catalog-detail img,
.catalog-detail .choice-placeholder {
  width: 100%;
  min-height: 180px;
  max-height: 300px;
  object-fit: contain;
}

.choice-search {
  width: 100%;
  margin: 0 0 14px;
}

@media (max-width: 680px) {
  .catalog-detail { grid-template-columns: 1fr; }
}

body[data-theme="notte"] .card,
body[data-theme="notte"] .modal-body,
body[data-theme="notte"] th { background: var(--panel-soft); color: var(--ink); }

body[data-theme="notte"] .btn.secondary { background: #d6e1e9; color: #16222c; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
  color: var(--ink);
}

th {
  background: var(--panel-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ink-soft);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.uniform-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.uniform-card {
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent-2);
  background: var(--panel-soft);
  padding: 14px;
  border-radius: 8px;
}

.uniform-card h4,
.uniform-card p {
  margin: 0 0 8px;
}

.uniform-detail-head {
  display: grid;
  grid-template-columns: minmax(220px, 360px) 1fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 18px;
}

.uniform-large-preview,
.uniform-large-placeholder {
  width: 100%;
  height: 320px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 8px;
}

.uniform-large-placeholder,
.component-image-placeholder {
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-size: 13px;
}

.uniform-components {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 10px;
}

.uniform-component {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.uniform-component img,
.component-image-placeholder {
  width: 88px;
  height: 88px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: var(--panel);
}

.uniform-component p {
  margin: 5px 0 0;
  font-size: 13px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff, #f5f8fb);
}

.card h4 {
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.card p {
  margin: 0;
  font-size: 30px;
  color: var(--accent);
}

.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: end;
}

.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: end;
}

.row-low {
  background: var(--warning-bg);
  color: var(--warning-ink);
}

.row-low td {
  color: var(--warning-ink);
}

.badge {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  border: 1px solid;
}

.badge.ok {
  background: #e8f7ef;
  color: #0c5f3f;
  border-color: #90d1ad;
}

.badge.warn {
  background: #fff6e8;
  color: #9a5f04;
  border-color: #efc27f;
}

.notify {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #0f6a59;
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 9999;
}

.notify.err {
  background: #8f1f26;
}

.notify.show {
  opacity: 1;
  transform: translateY(0);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 18, 30, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}

.modal.open {
  display: flex;
}

.modal-body {
  width: min(980px, 95vw);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 20px;
}

.modal-body h3 {
  margin-top: 0;
}

.image-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 72px;
}

.item-image-preview {
  display: none;
  width: 68px;
  height: 68px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 6px;
}

.compact-list {
  margin: 6px 0;
  padding-left: 18px;
}

.size-quantity-editor {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  padding: 14px;
  border-radius: 8px;
}

.size-quantity-editor .section-heading {
  margin-bottom: 8px;
  padding-bottom: 8px;
}

.size-quantity-editor h4 {
  margin: 0;
}

.helper-text {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 13px;
}

.size-quantity-rows {
  display: grid;
  gap: 8px;
}

.size-quantity-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(140px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.brand-logo-preview {
  min-height: 100px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--ink-soft);
}

.brand-logo-preview img {
  max-width: 180px;
  max-height: 100px;
  object-fit: contain;
}

.read-only-notice {
  border: 1px solid #b87911;
  border-left: 5px solid #b87911;
  background: #fff5d8;
  color: #4c3100;
  padding: 12px 14px;
  margin-bottom: 14px;
  border-radius: 8px;
  font-weight: 600;
}

.form-undo-actions {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.choice-summary {
  display: block;
  min-height: 22px;
  padding: 5px 0;
  color: var(--ink-soft);
  font-weight: 500;
}

.choice-modal-body {
  width: min(1160px, 96vw);
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  max-height: 62vh;
  overflow: auto;
  padding: 2px;
}

.choice-grid-text {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.choice-card {
  min-height: 190px;
  display: grid;
  grid-template-rows: 120px auto;
  text-align: left;
  padding: 0;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
}

.choice-card-text {
  min-height: 0;
  display: block;
}

.choice-card-text span:last-child {
  min-height: 72px;
  align-content: center;
}

.choice-card:hover,
.choice-card.selected {
  border-color: var(--accent-2);
  background: var(--panel);
}

.choice-card.selected {
  box-shadow: inset 0 0 0 2px var(--accent-2);
}

.choice-card img,
.choice-placeholder {
  width: 100%;
  height: 120px;
  object-fit: contain;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.choice-placeholder {
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-size: 13px;
}

.choice-card span:last-child {
  display: grid;
  gap: 5px;
  padding: 10px;
}

.choice-card small {
  color: var(--ink-soft);
  line-height: 1.35;
}

.search-results {
  max-height: 230px;
  overflow: auto;
}

.search-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #e6ebef;
  padding: 6px 0;
  font-size: 13px;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(530px, 95vw);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 12px;
    position: static;
    height: auto;
    overflow: visible;
  }

  .menu {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .grid2,
  .grid3 {
    grid-template-columns: 1fr;
  }

  .uniform-detail-head {
    grid-template-columns: 1fr;
  }

  .size-quantity-row {
    grid-template-columns: 1fr 1fr auto;
  }
}

@media (max-width: 620px) {
  .main { padding: 12px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-tools { width: 100%; flex-wrap: wrap; }
  .topbar-tools .btn { flex: 1 1 auto; }
  .panel { padding: 14px; }
  .choice-grid { grid-template-columns: 1fr 1fr; }
  .size-quantity-row { grid-template-columns: 1fr; }
}
