:root {
  color-scheme: light;
  --t-orange: #ee6420;
  --t-orange-soft: #ffe9dc;
  --t-magenta: #e91e63;
  --t-magenta-soft: #fce4ec;
  --t-purple: #7b2d8e;
  --t-purple-soft: #f1e4f5;
  --bg: #fafaf7;
  --bg-elev: #ffffff;
  --bg-sunk: #f4f3ee;
  --line: #e8e6df;
  --line-strong: #d8d5cb;
  --ink: #0f1115;
  --ink-2: #30343a;
  --ink-3: #63666d;
  --ink-4: #8c8f96;
  --ink-5: #b6b8bd;
  --ok: #1f8a52;
  --ok-soft: #e0f1e7;
  --warn: #b7791f;
  --warn-soft: #fbf1d6;
  --danger: #c7321b;
  --danger-soft: #fbe2dc;
  --info: #2563a8;
  --info-soft: #ddebf7;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 17, 21, 0.05);
  --shadow-md: 0 12px 28px rgba(15, 17, 21, 0.07);
  --shadow-lg: 0 22px 54px rgba(15, 17, 21, 0.11);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.drawer-locked {
  overflow: hidden;
}

button,
pre {
  font: inherit;
}

a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

a:hover {
  color: var(--t-orange);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.hidden {
  display: none;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  width: 248px;
  height: 100vh;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 16px 14px;
  border-right: 1px solid var(--line);
  background: var(--bg-elev);
  box-shadow: var(--shadow-sm);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 8px;
}

.avatar {
  display: inline-flex;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--t-orange), var(--t-magenta));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  box-shadow: var(--shadow-sm);
}

.brand-name {
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-subtitle {
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 500;
}

.nav-section {
  margin-top: 8px;
  color: var(--ink-4);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

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

.nav-item {
  display: flex;
  min-height: 34px;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--bg-sunk);
  color: var(--ink);
  text-decoration: none;
}

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

.status-block {
  display: grid;
  gap: 8px;
}

.pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-sunk);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.pill.ok {
  border-color: transparent;
  background: var(--ok-soft);
  color: var(--ok);
}

.pill.run {
  border-color: transparent;
  background: var(--info-soft);
  color: var(--info);
}

.pill.error {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
}

.sidebar-config {
  min-height: 66px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-sunk);
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.45;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--bg-elev);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--ink);
  background: var(--bg-sunk);
  box-shadow: var(--shadow-sm);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--t-orange);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  border-color: var(--ink-2);
  background: var(--ink-2);
  color: #fff;
}

.btn--brand {
  border-color: var(--t-orange);
  background: var(--t-orange);
  color: #fff;
}

.btn--brand:hover:not(:disabled) {
  border-color: var(--t-magenta);
  background: var(--t-magenta);
  color: #fff;
}

.warning {
  padding: 10px;
  border: 1px solid rgba(183, 121, 31, 0.25);
  border-radius: var(--r-md);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12px;
  font-weight: 600;
}

pre {
  min-height: 220px;
  max-height: none;
  flex: 1;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-sunk);
  color: var(--ink-2);
  font-family: "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  padding: 10px;
}

.drawer-backdrop {
  display: none;
}

.workspace {
  min-height: 100vh;
  margin-left: 248px;
  padding: 18px;
}

.workspace-head {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: -18px -18px 18px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 250, 247, 0.92);
  backdrop-filter: blur(10px);
}

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

.menu-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.eyebrow {
  color: var(--ink-4);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-transform: uppercase;
}

h1 {
  margin: 3px 0 0;
  color: var(--ink);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.12;
}

.head-tag {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.layout {
  display: grid;
  max-width: 1440px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
  margin: 0 auto;
}

.panel {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--bg-elev);
  box-shadow: var(--shadow-sm);
}

.progress-panel {
  grid-column: 1 / -1;
}

.reports-panel {
  grid-column: 1 / -1;
}

.manual-panel {
  grid-column: 1 / -1;
}

.mail-panel {
  grid-column: 1 / -1;
}

.fetch-panel {
  grid-column: 1 / -1;
}

.saved-panel {
  grid-column: 1 / -1;
}

.section-title {
  margin: -14px -14px 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.section-title--split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-meta {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-sunk);
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.section-meta.is-warn {
  border-color: transparent;
  background: var(--warn-soft);
  color: var(--warn);
}

.step-panel {
  box-shadow: var(--shadow-md);
}

.step-panel .section-title {
  font-size: 16px;
}

.progress-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

#phase {
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0;
}

.progress-text {
  max-width: min(560px, 58vw);
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 500;
  text-align: right;
}

.progress-track {
  height: 9px;
  margin: 14px 0;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-sunk);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--t-orange);
  transition: width 180ms ease;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
}

.metric,
.fetch-card,
.summary-card {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-sunk);
}

.metric strong,
.fetch-card strong,
.summary-card strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.metric span,
.fetch-card span,
.summary-card span {
  display: block;
  margin-top: 4px;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.summary-card.is-ok {
  border-color: rgba(31, 138, 82, 0.18);
  background: var(--ok-soft);
}

.summary-card.is-warn {
  border-color: rgba(183, 121, 31, 0.22);
  background: var(--warn-soft);
}

.summary-card.is-danger {
  border-color: rgba(199, 50, 27, 0.18);
  background: var(--danger-soft);
}

.summary-card.is-info {
  border-color: rgba(37, 99, 168, 0.18);
  background: var(--info-soft);
}

.summary-card.is-ok strong,
.summary-card.is-ok span {
  color: var(--ok);
}

.summary-card.is-warn strong,
.summary-card.is-warn span {
  color: var(--warn);
}

.summary-card.is-danger strong,
.summary-card.is-danger span {
  color: var(--danger);
}

.summary-card.is-info strong,
.summary-card.is-info span {
  color: var(--info);
}

.fetch-summary {
  margin-bottom: 10px;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 500;
}

.fetch-cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(92px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.mail-cards {
  display: grid;
  grid-template-columns: repeat(5, minmax(112px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.step-cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(112px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.table-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-elev);
}

.step-result-wrap {
  max-height: 360px;
}

.manual-result-wrap {
  max-height: 300px;
}

.mail-result-wrap {
  max-height: 320px;
}

.mail-files-title {
  margin: 12px 0 8px;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mail-files-wrap {
  max-height: 180px;
}

.fetch-result-wrap {
  max-height: 410px;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-sunk);
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

td {
  color: var(--ink-2);
  font-size: 13px;
}

tbody tr:hover td {
  background: rgba(244, 243, 238, 0.62);
}

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

.status-cell,
.used-cell {
  font-weight: 700;
}

.status-cell.errore {
  color: var(--danger);
}

.status-cell.creata,
.status-cell.modificata,
.status-cell.processabile,
.used-cell.yes {
  color: var(--ok);
}

.status-cell.controllare,
.status-cell.saltata,
.used-cell.no {
  color: var(--warn);
}

.status-cell.processata,
.status-cell.registrata {
  color: var(--ok);
}

.status-cell.esistente {
  color: var(--ink);
}

.manual-panel .table-wrap {
  border-color: rgba(183, 121, 31, 0.22);
}

.manual-panel th {
  background: var(--warn-soft);
}

.mail-panel .table-wrap {
  border-color: rgba(37, 99, 168, 0.18);
}

.mail-panel th {
  background: var(--info-soft);
}

.source-tag {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-sunk);
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1180px) {
  .fetch-panel,
  .reports-panel,
  .manual-panel,
  .mail-panel,
  .saved-panel {
    grid-column: 1 / -1;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(86px, 1fr));
  }

  .fetch-cards {
    grid-template-columns: repeat(3, minmax(92px, 1fr));
  }

  .mail-cards {
    grid-template-columns: repeat(3, minmax(112px, 1fr));
  }

  .step-cards {
    grid-template-columns: repeat(3, minmax(112px, 1fr));
  }
}

@media (max-width: 880px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .app-shell.is-drawer-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .app-shell.is-drawer-open .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: block;
    background: rgba(15, 17, 21, 0.28);
  }

  .workspace {
    margin-left: 0;
    padding: 14px;
  }

  .workspace-head {
    margin: -14px -14px 14px;
    padding: 12px 14px;
  }

  .menu-toggle {
    display: inline-flex;
    flex-direction: column;
  }

  h1 {
    font-size: 22px;
  }

  .head-tag {
    display: none;
  }

  .layout {
    gap: 12px;
  }

  .progress-text {
    max-width: none;
    text-align: left;
  }
}

@media (max-width: 620px) {
  .workspace-head {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .progress-head {
    flex-direction: column;
    gap: 6px;
  }

  .metrics,
  .fetch-cards,
  .mail-cards,
  .step-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-title--split {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .section-meta {
    max-width: 100%;
    justify-content: flex-start;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .panel {
    padding: 12px;
  }

  .section-title {
    margin: -12px -12px 12px;
    padding: 11px 12px;
  }
}
