/* ============================================================================
   ReachTAF — Design System
   Tokens espliciti per entrambi i temi. Tipografia Inter + JetBrains Mono.
   Contrasti validati WCAG AA+ per comfort prolungato di lettura.
   ========================================================================= */

:root {
  /* --- Tipografia ---------------------------------------------------------- */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 12px; --fs-sm: 13.5px; --fs-md: 14.5px; --fs-lg: 16px; --fs-xl: 19px; --fs-2xl: 26px; --fs-3xl: 34px;
  --lh-tight: 1.25; --lh-normal: 1.5;

  /* --- Spacing ------------------------------------------------------------- */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

  /* --- Radii --------------------------------------------------------------- */
  --r-xs: 4px; --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px;

  /* --- Animation ----------------------------------------------------------- */
  --t-fast: 120ms cubic-bezier(.4,0,.2,1);
  --t-med: 220ms cubic-bezier(.4,0,.2,1);

  /* --- Accent (ottimizzato contrasto) ------------------------------------- */
  --accent:        #0E8F7F;
  --accent-2:      #10A391;
  --accent-ink:    #FFFFFF;
  --accent-soft:   #0E8F7F20;

  /* --- Semantic (shared fallback, overridden per-theme) ------------------- */
  --clr-rilievo:   #B07E00;
  --clr-cad:       #1F7A33;
  --clr-cost:      #6D46D1;
  --clr-del:       #C1272F;
  --clr-warn:      #B8860B;
}

/* ============================================================================
   LIGHT THEME — paper / warm-neutral
   ========================================================================= */
:root,
:root[data-theme="light"] {
  --bg:            #F5F4EF;
  --bg-elev:       #FFFFFF;
  --bg-sunken:     #EEEDE5;
  --bg-hover:      #ECEBE2;
  --bg-selected:   #D0ECE6;

  --border:        #E0DDD3;
  --border-strong: #C8C4B7;
  --divider:       #E8E6DD;

  --text:          #1A1A18;
  --text-muted:    #53524E;
  --text-subtle:   #78766F;

  /* Semantic tuned per contrasto su bg light */
  --clr-rilievo:   #B07E00;    /* ~5.1:1 su #FCFBF7 */
  --clr-cad:       #1F7A33;    /* ~6.3:1 */
  --clr-cost:      #6D46D1;    /* ~6.0:1 */
  --clr-del:       #C1272F;    /* ~6.2:1 */

  --canvas-bg:     #FCFBF7;
  --canvas-grid:   rgba(60, 52, 32, 0.085);
  --canvas-grid-strong: rgba(60, 52, 32, 0.15);
  --canvas-axis:   rgba(14, 143, 127, 0.55);

  --shadow-sm: 0 1px 2px rgba(30, 28, 20, 0.05);
  --shadow-md: 0 2px 6px rgba(30, 28, 20, 0.07), 0 1px 2px rgba(30, 28, 20, 0.05);
  --shadow-lg: 0 10px 32px rgba(30, 28, 20, 0.08), 0 2px 6px rgba(30, 28, 20, 0.05);
  --shadow-focus: 0 0 0 3px rgba(14, 143, 127, 0.22);

  --success-bg: #E2F5EA; --success-fg: #0B6B2E;
  --warn-bg:    #FBF0D9; --warn-fg:    #7A5C00;
  --danger-bg:  #FCE3E3; --danger-fg:  #9A1D28;
  --info-bg:    #DEF0EE; --info-fg:    #0B5F54;
}

/* ============================================================================
   DARK THEME — deep slate teal (no pure black)
   ========================================================================= */
:root[data-theme="dark"] {
  --bg:            #0F1418;
  --bg-elev:       #161D22;
  --bg-sunken:     #0A1014;
  --bg-hover:      #20282F;
  --bg-selected:   #103830;

  --border:        #2A333B;
  --border-strong: #3D4A56;
  --divider:       #1F272E;

  --text:          #E8EAEC;
  --text-muted:    #B0B6BC;
  --text-subtle:   #868C93;

  --canvas-bg:     #0C1216;
  --canvas-grid:   rgba(255, 255, 255, 0.045);
  --canvas-grid-strong: rgba(255, 255, 255, 0.08);
  --canvas-axis:   rgba(45, 212, 196, 0.5);

  --accent:        #2ED3C2;
  --accent-2:      #4EE3D0;
  --accent-ink:    #0A1410;
  --accent-soft:   #2ED3C224;

  --clr-rilievo:   #F0C040;
  --clr-cad:       #3FB950;
  --clr-cost:      #A78BFA;
  --clr-del:       #F85149;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-focus: 0 0 0 3px rgba(46, 211, 194, 0.3);

  --success-bg: #0E2E1B; --success-fg: #5BD88C;
  --warn-bg:    #2C230A; --warn-fg:    #E8B948;
  --danger-bg:  #2E0F13; --danger-fg:  #FF7A82;
  --info-bg:    #0A2B29; --info-fg:    #5BE1CE;
}

/* ============================================================================
   RESET & BASE
   ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv05" 1, "cv11" 1, "ss01" 1;
  min-height: 100vh;
  transition: background-color var(--t-med), color var(--t-med);
}
h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; letter-spacing: -0.01em; line-height: var(--lh-tight); }
p { margin: 0; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

.mt-8  { margin-top: 8px !important; }
.mt-12 { margin-top: 12px !important; }
.mt-16 { margin-top: 16px !important; }
.mb-8  { margin-bottom: 8px !important; }
.fullw { width: 100%; }

/* ============================================================================
   HEADER
   ========================================================================= */
.header {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px; padding: 0 var(--sp-5);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: var(--sp-3); }
.logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border-radius: var(--r-md);
  font-weight: 700; font-size: 18px;
  box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; justify-content: center; line-height: 1.2; }
.brand-name { font-size: var(--fs-lg); font-weight: 600; }
.brand-sub { font-size: var(--fs-xs); color: var(--text-subtle); letter-spacing: 0.01em; }
.header-right { display: flex; align-items: center; gap: var(--sp-2); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 500;
  color: var(--accent); background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: 999px;
}

.autosave {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px;
  font-size: var(--fs-xs); font-weight: 500;
  color: var(--text-muted); background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.autosave-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-subtle);
  transition: background var(--t-fast), box-shadow var(--t-fast);
}
.autosave[data-state="saving"] { color: var(--clr-rilievo); border-color: color-mix(in srgb, var(--clr-rilievo) 35%, transparent); }
.autosave[data-state="saving"] .autosave-dot {
  background: var(--clr-rilievo);
  animation: autosave-pulse 1s ease-in-out infinite;
}
.autosave[data-state="saved"] { color: var(--clr-cad); border-color: color-mix(in srgb, var(--clr-cad) 30%, transparent); }
.autosave[data-state="saved"] .autosave-dot {
  background: var(--clr-cad);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--clr-cad) 18%, transparent);
}
.autosave[data-state="error"] { color: var(--clr-del); border-color: color-mix(in srgb, var(--clr-del) 40%, transparent); }
.autosave[data-state="error"] .autosave-dot { background: var(--clr-del); }
@keyframes autosave-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.8); }
}

/* ============================================================================
   BUTTONS
   ========================================================================= */
.btn-primary, .btn-secondary, .btn-tertiary, .btn-ghost, .btn-icon {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: var(--r-sm);
  font-size: var(--fs-md); font-weight: 500;
  border: 1px solid transparent;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
  text-decoration: none; white-space: nowrap;
  user-select: none;
}
.btn-primary, .btn-secondary, .btn-tertiary, .btn-ghost {
  padding: 8px 14px; min-height: 36px;
}
.btn-primary:focus-visible, .btn-secondary:focus-visible, .btn-tertiary:focus-visible, .btn-ghost:focus-visible, .btn-icon:focus-visible {
  outline: none; box-shadow: var(--shadow-focus);
}
.btn-primary:disabled, .btn-secondary:disabled, .btn-tertiary:disabled {
  opacity: 0.5; cursor: not-allowed;
}

.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }

.btn-secondary {
  background: var(--bg-elev); color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: color-mix(in srgb, var(--accent) 50%, var(--border-strong)); }
.btn-secondary:active:not(:disabled) { transform: translateY(1px); }

.btn-tertiary {
  background: transparent; color: var(--text-muted);
  border-color: var(--border);
}
.btn-tertiary:hover:not(:disabled) { background: var(--bg-sunken); color: var(--text); }

.btn-ghost {
  background: transparent; color: var(--text-muted);
  border-color: transparent;
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-icon {
  width: 34px; height: 34px; padding: 0;
  background: transparent; color: var(--text-muted);
  border-radius: var(--r-sm);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

.btn-tiny {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; font-size: 11.5px; font-weight: 500;
  background: var(--bg-elev); color: var(--text-muted);
  border: 1px solid var(--border-strong); border-radius: var(--r-xs);
  transition: all var(--t-fast);
}
.btn-tiny:hover { background: var(--bg-hover); color: var(--text); border-color: var(--accent); }
.btn-tiny.danger { color: var(--clr-del); border-color: color-mix(in srgb, var(--clr-del) 40%, var(--border-strong)); }
.btn-tiny.danger:hover { background: var(--danger-bg); }

/* ============================================================================
   FORM CONTROLS
   ========================================================================= */
.label {
  display: block;
  font-size: var(--fs-xs); font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 5px;
}
.input, select.input, input[type="text"].input, input[type="number"].input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-sunken);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: var(--fs-md);
  font-variant-numeric: tabular-nums;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.input:hover { border-color: var(--border-strong); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
  background: var(--bg-elev);
}
select.input {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 30px;
}

.segmented {
  display: flex; padding: 3px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  gap: 2px;
}
.segmented .seg {
  flex: 1; padding: 6px 10px;
  background: transparent; color: var(--text-muted);
  border: none; border-radius: var(--r-xs);
  font-size: var(--fs-sm); font-weight: 500;
  transition: all var(--t-fast);
}
.segmented .seg.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented .seg:hover:not(.active) { color: var(--text); }

/* ============================================================================
   MAIN LAYOUT
   ========================================================================= */
#main {
  max-width: 1480px; margin: 0 auto;
  padding: var(--sp-5);
}
.screen { animation: fadeIn var(--t-med); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============================================================================
   HOME
   ========================================================================= */
.home-hero {
  max-width: 640px; margin: var(--sp-10) auto var(--sp-8); text-align: center;
}
.home-title {
  font-size: var(--fs-3xl); font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, var(--text) 0%, var(--text-muted) 140%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.home-lead {
  margin-top: var(--sp-3);
  color: var(--text-muted); font-size: var(--fs-lg);
  line-height: 1.6;
}

.dropzone {
  max-width: 640px; margin: 0 auto;
  padding: var(--sp-10) var(--sp-6);
  background: var(--bg-elev);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-xl);
  text-align: center;
  transition: all var(--t-med);
  box-shadow: var(--shadow-sm);
}
.dropzone:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
.dropzone.dragover {
  border-color: var(--accent); background: var(--accent-soft);
  transform: scale(1.01);
  box-shadow: var(--shadow-lg);
}
.dropzone-icon {
  width: 72px; height: 72px; margin: 0 auto var(--sp-4);
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 50%;
}
.dropzone-title {
  font-size: var(--fs-xl); font-weight: 600; margin-bottom: var(--sp-2);
}
.dropzone-sub {
  color: var(--text-muted); font-size: var(--fs-md); line-height: 1.6;
  max-width: 460px; margin: 0 auto;
}
.dropzone-sub strong { color: var(--text); font-weight: 600; }

/* ============================================================================
   TABBAR
   ========================================================================= */
.tabbar {
  display: flex; gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 4px;
  margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-sm);
}
.tab {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 14px;
  background: transparent; color: var(--text-muted);
  border: none; border-radius: var(--r-sm);
  font-size: var(--fs-md); font-weight: 500;
  transition: all var(--t-fast);
  position: relative;
}
.tab:hover:not(.tab-disabled):not(.active) { background: var(--bg-hover); color: var(--text); }
.tab.active {
  background: var(--accent); color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}
.tab.tab-disabled {
  opacity: 0.45; cursor: not-allowed;
}
.tab-num {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  background: var(--bg-sunken); color: var(--text-subtle);
  border-radius: 50%;
  flex-shrink: 0;
}
.tab.active .tab-num { background: rgba(255,255,255,0.2); color: var(--accent-ink); }
.tab-lbl { white-space: nowrap; }
.tab-badge {
  display: inline-grid; place-items: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  background: var(--clr-cad); color: #fff;
  border-radius: 999px;
  line-height: 1;
  margin-left: 2px;
}
.tab.active .tab-badge { background: rgba(255,255,255,0.28); color: var(--accent-ink); }

.tab-panel {
  animation: fadeIn var(--t-med);
}

/* ============================================================================
   SPLIT LAYOUT
   ========================================================================= */
.split {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: var(--sp-4);
  align-items: start;
}
@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
}
.split-main { min-width: 0; }
.split-side { display: flex; flex-direction: column; gap: var(--sp-4); }

/* ============================================================================
   PANEL & CARD
   ========================================================================= */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--divider);
  gap: var(--sp-3); flex-wrap: wrap;
}
.panel-header h3 {
  font-size: var(--fs-lg); font-weight: 600;
}
.panel-meta {
  font-size: var(--fs-sm); color: var(--text-muted);
  display: inline-flex; align-items: center; gap: var(--sp-3);
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-subtle);
  border-bottom: 1px solid var(--divider);
  background: var(--bg-sunken);
}
.card-body { padding: var(--sp-4); }
.card-note {
  font-size: var(--fs-sm); color: var(--text-muted);
  line-height: 1.55;
}

.summary-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--sp-3);
}
.summary-grid-2 { grid-template-columns: 1fr 1fr; }
.summary-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.summary-cell {
  padding: var(--sp-3);
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  text-align: center;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.summary-cell-wide { grid-column: 1 / -1; }
.summary-section-title {
  grid-column: 1 / -1;
  font-size: 10px; font-weight: 600;
  color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: var(--sp-2) 0 0;
  border-top: 1px solid var(--border);
  margin-top: var(--sp-1);
}
.summary-label {
  font-size: 10px; font-weight: 500;
  color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.summary-value {
  font-family: var(--font-mono); font-size: var(--fs-lg); font-weight: 600;
  color: var(--text); font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.summary-value-mono { font-size: 11px; letter-spacing: 0; }
.summary-cell-tight { padding-left: var(--sp-1); padding-right: var(--sp-1); }
.meta-form {
  display: grid; grid-template-columns: 2fr 1fr; gap: var(--sp-3);
}
.meta-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.meta-field .label { margin: 0; }
.meta-field .input { width: 100%; }

/* Key-value list per il riepilogo: etichetta a sinistra, valore a destra,
   righe con separatore sottile. Robusto a qualunque larghezza di sidebar. */
.kv-list {
  display: flex; flex-direction: column;
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.kv-row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: var(--sp-3);
  padding: 8px var(--sp-3);
  border-top: 1px solid var(--border-subtle, rgba(0,0,0,0.06));
  min-width: 0;
}
.kv-row:first-child { border-top: none; }
.kv-k {
  font-size: 11px; font-weight: 500;
  color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: 0.04em;
  flex-shrink: 0;
}
.kv-v {
  font-family: var(--font-mono); font-size: 13px; font-weight: 600;
  color: var(--text); font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kv-list-mono .kv-v { font-size: 12px; }
.kv-section {
  font-size: 10px; font-weight: 600;
  color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin: var(--sp-3) 0 6px;
}
.summary-add { color: var(--clr-cad); }
.summary-del { color: var(--clr-del); }

/* ============================================================================
   TABLE
   ========================================================================= */
.table-wrap {
  max-height: 320px; overflow: auto;
  border-bottom: 1px solid var(--divider);
  scrollbar-width: thin;
  /* indicatore visivo che c'è ancora contenuto sotto lo scroll */
  background:
    linear-gradient(var(--bg-elev) 30%, transparent),
    linear-gradient(transparent, var(--bg-elev) 70%) 0 100%,
    radial-gradient(farthest-side at 50% 0, rgba(0,0,0,0.08), transparent),
    radial-gradient(farthest-side at 50% 100%, rgba(0,0,0,0.08), transparent) 0 100%;
  background-repeat: no-repeat;
  background-size: 100% 24px, 100% 24px, 100% 8px, 100% 8px;
  background-attachment: local, local, scroll, scroll;
}
.table-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: 5px;
  border: 2px solid var(--bg-elev);
}
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: var(--fs-sm);
}
thead th {
  position: sticky; top: 0; z-index: 1;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elev);
  font-weight: 600; font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-subtle);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.num { text-align: right; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th.sorted { color: var(--accent); }
tbody tr {
  transition: background var(--t-fast);
}
tbody tr:not(:last-child) td { border-bottom: 1px solid var(--divider); }
tbody tr:hover { background: var(--bg-hover); }
tbody td {
  padding: var(--sp-3) var(--sp-4);
  color: var(--text); vertical-align: middle;
}
tbody td.num {
  text-align: right; font-family: var(--font-mono);
  font-variant-numeric: tabular-nums; font-size: var(--fs-sm);
  line-height: 1.45;
}
tbody tr.selected-row { background: var(--bg-selected) !important; }
tbody tr.base-row td { font-weight: 600; }
tbody tr.cad-row td  { color: color-mix(in srgb, var(--clr-cad) 90%, var(--text)); }
tbody tr.cost-row td { color: color-mix(in srgb, var(--clr-cost) 90%, var(--text)); }
tbody tr.deleted-row td {
  text-decoration: line-through;
  color: color-mix(in srgb, var(--clr-del) 70%, var(--text-subtle));
  opacity: 0.8;
}
tbody tr.float-row td { color: var(--clr-warn); }
tbody tr.picked-row td {
  box-shadow: inset 3px 0 0 var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.cell-input {
  width: 100%;
  padding: 3px 6px;
  background: transparent; color: inherit;
  border: 1px solid transparent;
  border-radius: var(--r-xs);
  font: inherit;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.cell-input.num {
  text-align: right; font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.cell-input:hover { background: var(--bg-hover); border-color: var(--border); }
.cell-input:focus {
  background: var(--bg-elev); border-color: var(--accent);
  outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
tbody tr.deleted-row .cell-input,
tbody tr.base-row .cell-input { pointer-events: none; }

tbody tr.multi-selected td {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.batch-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3);
  padding: 8px 12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--bg-elev));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-2);
}
.batch-count strong { font-family: var(--font-mono); font-weight: 600; color: var(--accent); }
.batch-actions { display: flex; gap: 6px; }

.dirty-dot {
  display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--clr-rilievo);
  margin-right: 6px; vertical-align: middle;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--clr-rilievo) 22%, transparent);
}

/* badges */
.base-badge, .cad-badge, .cost-badge, .del-badge {
  display: inline-block;
  padding: 1px 7px;
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  border-radius: 3px;
  margin-right: 7px;
  vertical-align: 1px;
}
.base-badge { background: var(--accent-soft);  color: var(--accent); }
.cad-badge  { background: color-mix(in srgb, var(--clr-cad) 18%, transparent);  color: var(--clr-cad); }
.cost-badge { background: color-mix(in srgb, var(--clr-cost) 18%, transparent); color: var(--clr-cost); }
.del-badge  { background: color-mix(in srgb, var(--clr-del) 18%, transparent);  color: var(--clr-del); }

.input-inline {
  padding: 3px 7px;
  background: transparent; color: inherit;
  border: 1px solid transparent; border-radius: var(--r-xs);
  font: inherit; font-family: var(--font-mono); font-size: var(--fs-sm);
  min-width: 80px;
  transition: all var(--t-fast);
}
.input-inline:hover { border-color: var(--border); background: var(--bg-sunken); }
.input-inline:focus {
  outline: none; border-color: var(--accent);
  background: var(--bg-elev); box-shadow: var(--shadow-focus);
}

/* ============================================================================
   CANVAS
   ========================================================================= */
.canvas-wrap {
  position: relative;
  width: 100%; height: 420px;
  background: var(--canvas-bg);
  overflow: hidden;
}
.canvas-wrap canvas {
  width: 100%; height: 100%;
  display: block;
  cursor: grab;
}
.canvas-wrap canvas:active { cursor: grabbing; }

.canvas-toolbar {
  position: absolute; top: 10px; right: 10px;
  display: flex; gap: 4px;
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 3px;
  box-shadow: var(--shadow-md);
  z-index: 2;
}
.canvas-btn {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  background: transparent; color: var(--text-muted);
  border: none; border-radius: var(--r-xs);
  transition: all var(--t-fast);
}
.canvas-btn:hover { background: var(--bg-hover); color: var(--text); }
.canvas-btn:active { transform: scale(0.95); }

.canvas-placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: var(--sp-6); text-align: center;
  color: var(--text-subtle); font-size: var(--fs-md);
  pointer-events: none;
  background: var(--canvas-bg);
  z-index: 1;
}
.canvas-placeholder strong { color: var(--accent); font-weight: 600; }

/* ============================================================================
   FULLSCREEN
   ========================================================================= */
.canvas-wrap:fullscreen,
.canvas-wrap:-webkit-full-screen {
  width: 100vw; height: 100vh;
  background: var(--canvas-bg);
  padding: 0;
}
.canvas-wrap:fullscreen canvas,
.canvas-wrap:-webkit-full-screen canvas {
  width: 100vw; height: 100vh;
}
.canvas-wrap:fullscreen .canvas-toolbar,
.canvas-wrap:-webkit-full-screen .canvas-toolbar {
  top: 16px; right: 16px;
}

/* Overlay strumenti Tab 3 in fullscreen */
.fs-tools-overlay {
  position: fixed;
  top: 72px; right: 16px;
  width: 300px; max-height: calc(100vh - 96px);
  background: color-mix(in srgb, var(--bg-elev) 94%, transparent);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 2147483647;
  display: none;
  flex-direction: column;
  animation: fsOverlayIn var(--t-med);
}
.fs-tools-overlay.active { display: flex; }
@keyframes fsOverlayIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.fs-tools-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--divider);
  background: var(--bg-sunken);
}
.fs-tools-title {
  font-size: var(--fs-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-subtle);
}
.fs-tools-body {
  padding: 14px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.fs-tools-section {
  border-bottom: 1px solid var(--divider);
  padding-bottom: 12px;
}
.fs-tools-section:last-child { border-bottom: none; padding-bottom: 0; }
.fs-tools-section-title {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-subtle);
  margin-bottom: 8px;
}

/* ============================================================================
   INNER DROPZONE (tab 2)
   ========================================================================= */
.inner-dropzone {
  margin: var(--sp-5);
  padding: var(--sp-6) var(--sp-5);
  background: var(--bg-sunken);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  text-align: center;
  transition: all var(--t-med);
}
.inner-dropzone:hover { border-color: var(--accent); }
.inner-dropzone.dragover {
  border-color: var(--accent); background: var(--accent-soft);
}
.inner-dropzone-icon {
  width: 52px; height: 52px; margin: 0 auto var(--sp-3);
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: var(--r-md);
}
.inner-dropzone-title { font-size: var(--fs-lg); font-weight: 600; margin-bottom: var(--sp-1); }
.inner-dropzone-sub {
  color: var(--text-muted); font-size: var(--fs-sm); line-height: 1.55;
  max-width: 440px; margin: 0 auto;
}

/* ============================================================================
   LEGEND DOTS
   ========================================================================= */
.legend-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 4px; vertical-align: 1px;
}
.cad-dot  { background: var(--clr-cad); }
.del-dot  { background: var(--clr-del); }
.cost-dot { background: var(--clr-cost); }

/* ============================================================================
   BADGES / HINTS
   ========================================================================= */
.badge-info {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--info-bg); color: var(--info-fg);
  border-radius: var(--r-sm); font-size: var(--fs-sm);
}
.badge-info.warning { background: var(--warn-bg); color: var(--warn-fg); }
.badge-info .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}

.hint {
  padding: 8px 12px;
  background: var(--info-bg); color: var(--info-fg);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm); line-height: 1.5;
}
.hint.warning { background: var(--warn-bg); color: var(--warn-fg); }
.hint.danger  { background: var(--danger-bg); color: var(--danger-fg); }

/* ============================================================================
   TOAST
   ========================================================================= */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-md); font-weight: 500;
  min-width: 240px; max-width: 420px;
  z-index: 100;
  animation: toastIn var(--t-med);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast.success { border-left: 3px solid var(--clr-cad); }
.toast.danger  { border-left: 3px solid var(--clr-del); }
.toast-msg { flex: 1; }
.toast-close {
  background: transparent; border: none; color: var(--text-subtle);
  font-size: 14px; padding: 4px 6px; border-radius: var(--r-xs);
  line-height: 1;
}
.toast-close:hover { background: var(--bg-hover); color: var(--text); }

/* ============================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 700px) {
  .header { padding: 0 var(--sp-3); }
  .brand-sub { display: none; }
  .tab-lbl { display: none; }
  .tab { padding: 9px; }
  #main { padding: var(--sp-3); }
  .canvas-wrap { height: 320px; }
}

/* =========================================================================
   PUNTI FIDUCIALI — bottone tabella + modale
   ========================================================================= */
/* Checkbox PF custom — chiara, universale */
.pf-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}
.pf-check { position: relative; }
.pf-check input { position: absolute; inset: 0; opacity: 0; pointer-events: none; margin: 0; }
.pf-check-box {
  display: inline-block;
  width: 16px;
  height: 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 3px;
  transition: all 0.12s ease;
  position: relative;
}
.pf-check:hover .pf-check-box { border-color: var(--accent); }
.pf-check input:checked + .pf-check-box {
  background: var(--accent);
  border-color: var(--accent);
}
.pf-check input:checked + .pf-check-box::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.pf-row .input-inline {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  color: var(--accent);
  font-weight: 600;
}

.pf-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pf-modal.hidden { display: none; }
.pf-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}
.pf-modal-card {
  position: relative;
  width: min(520px, calc(100vw - 32px));
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  animation: pf-modal-in 0.18s ease-out;
}
@keyframes pf-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.pf-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.pf-modal-header h3 { margin: 0; font-size: 15px; }
.pf-modal-body { padding: var(--sp-4); }
.pf-form {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  margin: var(--sp-3) 0 var(--sp-3) 0;
}
.pf-field { display: flex; flex-direction: column; flex: 1 1 auto; }
.pf-field-narrow { flex: 0 0 64px; }
.pf-field .label { margin-bottom: 4px; font-size: 11px; }
.pf-input {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  text-align: center;
}
.pf-belfiore { text-transform: uppercase; }
.pf-sep {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 18px;
  color: var(--text-muted);
  padding-bottom: 8px;
}
.pf-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 8px;
}
.pf-preview-label { font-size: 12px; color: var(--text-muted); }
.pf-preview-code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.pf-error {
  margin-top: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: color-mix(in srgb, var(--clr-del) 10%, transparent);
  color: var(--clr-del);
  border-radius: 6px;
  font-size: 12px;
}
.pf-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 50%, transparent);
}
.pf-footer-actions { display: flex; gap: var(--sp-2); }

/* =========================================================================
   MANUALE — modal full-screen scrollabile
   ========================================================================= */
.help-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-modal.hidden { display: none; }
.help-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
}
.help-modal-card {
  position: relative;
  width: min(820px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  overflow: hidden;
  animation: pf-modal-in 0.18s ease;
}
.help-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.help-modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.help-modal-body {
  padding: var(--sp-4) var(--sp-5);
  overflow-y: auto;
  line-height: 1.55;
  color: var(--text);
  font-size: 14px;
}
.help-modal-body h4 {
  margin: var(--sp-5) 0 var(--sp-2);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--sp-1);
}
.help-modal-body h4:first-child { margin-top: 0; }
.help-modal-body h5 {
  margin: var(--sp-3) 0 var(--sp-1);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.help-modal-body p { margin: 0 0 var(--sp-2); }
.help-modal-body ul, .help-modal-body ol {
  margin: 0 0 var(--sp-2);
  padding-left: var(--sp-5);
}
.help-modal-body li { margin-bottom: var(--sp-1); }
.help-modal-body code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  padding: 1px 5px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  border-radius: 3px;
}
.help-modal-body strong { color: var(--text); }
.help-modal-body em { color: var(--text-muted); font-style: italic; }
.help-modal-body pre.help-code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  padding: var(--sp-2) var(--sp-3);
  margin: var(--sp-1) 0 var(--sp-2);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow-x: auto;
  white-space: pre;
}
.help-tldr {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text);
}
.help-callout {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 6px;
  padding: var(--sp-2) var(--sp-3);
  margin: var(--sp-3) 0;
  font-size: 13px;
  line-height: 1.5;
}
.help-callout-info {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--bg));
}
.help-callout-warn {
  border-left-color: #c48200;
  background: color-mix(in srgb, #c48200 8%, var(--bg));
}
/* Gate termini — modale di primo avvio */
.terms-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.terms-modal.hidden { display: none; }
.terms-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 18, 22, 0.72);
  backdrop-filter: blur(4px);
}
.terms-modal-card {
  position: relative;
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
  overflow: hidden;
  animation: pf-modal-in 0.22s ease;
}
.terms-modal-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.terms-modal-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.terms-modal-body {
  padding: var(--sp-4) var(--sp-5);
  overflow-y: auto;
  font-size: 13.5px;
  line-height: 1.55;
}
.terms-intro {
  margin: 0 0 var(--sp-3);
  color: var(--text);
}
.terms-section {
  background: var(--bg-elev);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-3);
}
.terms-section h5 {
  margin: 0 0 var(--sp-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}
.terms-section ul {
  margin: 0;
  padding-left: var(--sp-4);
}
.terms-section li { margin-bottom: 4px; }
.terms-consent {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}
.terms-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 12.5px;
  line-height: 1.5;
}
.terms-check:hover { border-color: var(--accent); }
.terms-check input[type="checkbox"] {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.terms-check input[type="checkbox"]:checked + span {
  color: var(--text);
}
.terms-check span {
  color: var(--text-muted);
}
.terms-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.terms-modal-footer .btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Footer legale permanente */
.legal-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--divider);
  background: var(--bg-elev);
  flex-wrap: wrap;
}
.legal-sep { opacity: 0.5; }
.legal-link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--divider);
  text-underline-offset: 2px;
}
.legal-link:hover { color: var(--accent); text-decoration-color: var(--accent); }
.legal-note { opacity: 0.8; }

.help-legal-footer {
  margin-top: var(--sp-3);
  padding-top: var(--sp-2);
  border-top: 1px dashed var(--divider);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* =========================================================================
   CSV MAPPING — modal conferma colonne
   ========================================================================= */
.csvmap-card { width: min(720px, calc(100vw - 32px)); }
.csvmap-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2) var(--sp-3);
  margin-top: var(--sp-2);
}
.csvmap-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.csvmap-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.csvmap-row .csvmap-badge {
  display: inline-block;
  padding: 1px 5px;
  font-size: 9px;
  font-weight: 700;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.csvmap-badge.req {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--accent);
}
.csvmap-badge.low {
  background: color-mix(in srgb, #e0a800 22%, transparent);
  color: #b07d00;
}
[data-theme="dark"] .csvmap-badge.low { color: #ffd76a; }
.csvmap-row select {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 13px;
}
.csvmap-row.warn select { border-color: color-mix(in srgb, #e0a800 60%, transparent); }
.csvmap-preview-wrap {
  max-height: 200px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: var(--sp-1);
}
.csvmap-preview {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
}
.csvmap-preview th, .csvmap-preview td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.csvmap-preview th {
  position: sticky;
  top: 0;
  background: var(--surface);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.csvmap-preview th.mapped {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.csvmap-validation {
  margin-top: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: color-mix(in srgb, #e0a800 12%, transparent);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
}
.csvmap-validation.danger {
  background: color-mix(in srgb, var(--clr-del) 12%, transparent);
  color: var(--clr-del);
}
