/* =============================================================================
   STR4TUM DESIGN SYSTEM — COMPONENTS
   Reusable UI patterns for dashboard applications.
   Depends on: tokens.css
   ============================================================================= */

/* =============================================================================
   LAYOUT — Page shell
   ============================================================================= */
.page {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-6);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: 0;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.page-title {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
}

.page-subtitle {
  margin-top: var(--space-2);
  font-size: var(--fs-base);
  color: var(--text-muted);
  font-weight: var(--fw-regular);
}

.page-meta {
  margin-top: var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.page-meta strong {
  color: var(--accent-info);
  font-weight: var(--fw-medium);
}

/* Toolbar cluster (top-right: theme toggle, Anonymity, PDF) */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* =============================================================================
   NAVIGATION — Numbered section cards
   Variants: .nav-sections (numbered), .nav-tabs (text only)
   ============================================================================= */
.nav-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-8);
}

.nav-section {
  padding: var(--space-4) var(--space-5);
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
  position: relative;
}

.nav-section:hover {
  border-color: var(--border-strong);
  background: var(--bg-panel-elevated);
}

.nav-section[data-active="true"] {
  border-color: var(--accent-success);
}
.nav-section[data-active="true"]::after {
  content: '';
  position: absolute;
  left: var(--space-5);
  right: var(--space-5);
  bottom: -1px;
  height: 2px;
  background: var(--accent-success);
}

.nav-section-number {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  letter-spacing: var(--tracking-wider);
}

.nav-section-title {
  margin-top: var(--space-2);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
}
.nav-section[data-active="true"] .nav-section-title {
  color: var(--accent-success);
}

.nav-section-meta {
  margin-top: var(--space-1);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* --- Nav tabs (alternative — horizontal underline style) --- */
.nav-tabs {
  display: flex;
  gap: var(--space-6);
  padding-bottom: 0;
  margin-bottom: var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tab {
  /* Reset stili nativi del <button>: se la nav-tab è un button, il browser
     applica background grigio chiaro (visibile soprattutto in light mode)
     e border lieve. Trasformarla in elemento puramente testuale. */
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  padding: var(--space-3) 0;
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-out);
}
.nav-tab:hover { color: var(--text-secondary); }
.nav-tab:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}
.nav-tab[data-active="true"] {
  color: var(--accent-info);
  border-bottom-color: var(--accent-info);
}

/* =============================================================================
   KPI CARDS — Unified style
   Minimal base + optional semantic accent badge
   ============================================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-8);
}

.kpi {
  padding: var(--space-5);
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
}

.kpi-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  margin-bottom: var(--space-3);
}

.kpi-value {
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
}

.kpi-meta {
  margin-top: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* Semantic value colors — copertura completa del tone-set DS */
.kpi-value[data-tone="info"]      { color: var(--accent-info); }
.kpi-value[data-tone="success"]   { color: var(--accent-success); }
.kpi-value[data-tone="danger"]    { color: var(--accent-danger); }
.kpi-value[data-tone="warning"]   { color: var(--accent-warning); }
.kpi-value[data-tone="header"]    { color: var(--accent-header); }
.kpi-value[data-tone="secondary"] { color: var(--accent-secondary); }

/* =============================================================================
   STATO PROGETTO — THE signature panel
   Purple-bordered panel with semantic rows: LETTURA / VA / NON VA / RISCHIO / PROSSIMI
   This is the most recognizable pattern — keep it consistent everywhere.
   ============================================================================= */
.stato-progetto {
  position: relative;
  padding: var(--space-6);
  background: var(--bg-panel);
  border: 1px solid var(--accent-header);
  border-radius: var(--radius-xl);
  margin-bottom: var(--space-8);
  overflow: hidden;
}

/* Subtle purple glow wash at top-left — atmospheric depth */
.stato-progetto::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    ellipse at top left,
    var(--accent-header-dim),
    transparent 60%
  );
  pointer-events: none;
}

.stato-progetto > * { position: relative; }

.stato-progetto-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.stato-progetto-title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--accent-header);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
}

.stato-progetto-meta {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.stato-progetto-meta strong {
  color: var(--accent-info);
  font-weight: var(--fw-medium);
}

/* Rows: grid with left label + content */
.stato-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: var(--space-5);
  padding: var(--space-4) 0;
  border-bottom: 1px dashed var(--border-subtle);
  align-items: start;
}
.stato-row:last-child { border-bottom: none; }

.stato-row-label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  padding-top: 2px;
}

/* Semantic row variants (symbol + color) */
.stato-row-label[data-kind="lettura"]::before  { content: ''; color: var(--accent-info); }
.stato-row-label[data-kind="va"]::before       { content: '✓ '; color: var(--accent-success); }
.stato-row-label[data-kind="non-va"]::before   { content: '✗ '; color: var(--accent-danger); }
.stato-row-label[data-kind="rischio"]::before  { content: '⚠ '; color: var(--accent-warning); }
.stato-row-label[data-kind="prossimi"]::before { content: '→ '; color: var(--accent-info); }

.stato-row-label[data-kind="lettura"]  { color: var(--accent-info); }
.stato-row-label[data-kind="va"]       { color: var(--accent-success); }
.stato-row-label[data-kind="non-va"]   { color: var(--accent-danger); }
.stato-row-label[data-kind="rischio"]  { color: var(--accent-warning); }
.stato-row-label[data-kind="prossimi"] { color: var(--accent-info); }

.stato-row-content {
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text-secondary);
}

.stato-row-content strong {
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
}

/* Highlighted inline numbers / dates — utility globale (theme-agnostic).
   Uso: <span class="num">119.451 €</span>  ·  <span class="date">2026-05-09</span>
   Funziona ovunque, non solo dentro .stato-row-content. */
.num,
.date {
  color: var(--accent-info);
  font-weight: var(--fw-medium);
}

.stato-row-content ul {
  margin: 0;
  padding-left: var(--space-4);
}
.stato-row-content li { margin-bottom: var(--space-2); }
.stato-row-content li::marker { color: var(--accent-info); }

/* =============================================================================
   BADGES / TAGS — Small semantic pills
   ============================================================================= */
/* .tag — pure typographic, no chip / no pill / no background.
   Regola Anthropic style guide: "metadata labels are pure text".
   Hit area minima 32x32 (WCAG 2.5.5) anche senza background visibile. */
.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 32px;
  padding: 0 var(--space-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* .tag[data-tone] color-only — pure typographic per regola "no chip" Anthropic.
   Background/border/padding sono già azzerati globalmente (.tag), qui passiamo
   solo il color tone-aware. */
.tag[data-tone="info"]      { color: var(--accent-info); }
.tag[data-tone="success"]   { color: var(--accent-success); }
.tag[data-tone="danger"]    { color: var(--accent-danger); }
.tag[data-tone="warning"]   { color: var(--accent-warning); }
.tag[data-tone="header"]    { color: var(--accent-header); }
.tag[data-tone="secondary"] { color: var(--accent-secondary); }

/* Pulse dot (live status) — usa il token success per pulse, così resta
   coerente al theme switch senza hex hardcoded. */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-success);
  box-shadow: 0 0 0 0 var(--accent-success);
  animation: pulse-dot 2s infinite var(--ease-out);
}
@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 var(--accent-success-dim); }
  70%  { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* =============================================================================
   BUTTONS
   Minimal, bordered, monospace. Three variants: default, primary, ghost.
   ============================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-wide);
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}
.btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-panel-elevated);
}
/* Focus state (WCAG 2.4.7) — ring esplicito su tutti i .btn */
.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* .btn[data-variant="primary"] è ridefinito sotto nella sezione
   "Pattern-level adjustments" (.btn primary su anthropic-style con inversione
   cromatica light/dark). Qui niente: il blocco precedente con hardcoded
   verde rgba(16,185,129) era dead code post-rebrand v1.2. */

.btn[data-variant="ghost"] {
  border-color: transparent;
  color: var(--text-muted);
}
.btn[data-variant="ghost"]:hover {
  color: var(--text-primary);
  background: var(--bg-panel-elevated);
}

/* Toggle button group */
.toggle-group {
  display: inline-flex;
  padding: 2px;
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  gap: 2px;
}

.toggle-btn {
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}
.toggle-btn:hover { color: var(--text-primary); }
.toggle-btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}
.toggle-btn[data-active="true"] {
  color: var(--accent-info);
  background: var(--accent-info-dim);
}

/* =============================================================================
   TABLES — Minimal, no heavy borders (from Crypto Portfolio style)
   ============================================================================= */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}

.table thead th {
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  text-align: left;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-default);
}

.table tbody td {
  padding: var(--space-3) var(--space-4);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

.table tbody tr:hover td {
  background: var(--bg-panel-elevated);
}

.table tbody td strong {
  color: var(--text-primary);
  font-weight: var(--fw-medium);
}

/* First column priority dot */
.table .priority-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.table .priority-dot[data-level="high"]   { background: var(--accent-danger); }
.table .priority-dot[data-level="medium"] { background: var(--accent-warning); }
.table .priority-dot[data-level="low"]    { background: var(--accent-info); }

/* =============================================================================
   PROGRESS BARS — Thin, semantic. Supports stacked variant.
   ============================================================================= */
.progress {
  display: block;
  width: 100%;
  height: 4px;
  background: var(--border-subtle);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  display: block;
  height: 100%;
  background: var(--accent-success);
  transition: width var(--duration-slow) var(--ease-out);
}
.progress-fill[data-tone="info"]    { background: var(--accent-info); }
.progress-fill[data-tone="warning"] { background: var(--accent-warning); }
.progress-fill[data-tone="danger"]  { background: var(--accent-danger); }

/* Stacked progress (for layered values: completed + in-progress + planned) */
.progress-stacked {
  display: flex;
  width: 100%;
  height: 6px;
  background: var(--border-subtle);
  border-radius: 3px;
  overflow: hidden;
}

.progress-segment {
  height: 100%;
  transition: width var(--duration-slow) var(--ease-out);
}
.progress-segment[data-tone="success"] { background: var(--accent-success); }
.progress-segment[data-tone="header"]  { background: var(--accent-header); }
.progress-segment[data-tone="secondary"]  { background: var(--accent-secondary); }
.progress-segment[data-tone="info"]    { background: var(--accent-info); }

.progress-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.progress-legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.progress-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.progress-legend-item strong {
  color: var(--text-primary);
  font-weight: var(--fw-medium);
}

/* =============================================================================
   FORM CONTROLS — Inputs, sliders
   ============================================================================= */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
}

.input {
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  transition: border-color var(--duration-fast) var(--ease-out);
}
.input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.select {
  padding: var(--space-2) calc(var(--space-3) + 16px) var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  color: var(--text-primary);
  background-color: var(--bg-input);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) 50%, calc(100% - 7px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out);
}
.select:focus {
  outline: none;
  border-color: var(--border-focus);
}
.select:hover {
  border-color: var(--border-strong, var(--text-muted));
}

/* Range slider — minimal track */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: var(--border-default);
  border-radius: 1px;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out);
}
.slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}
.slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  border: none;
  cursor: pointer;
}

/* =============================================================================
   PANELS — Generic container (extra capitolato pattern, info boxes)
   ============================================================================= */
.panel {
  padding: var(--panel-padding);
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-6);
}

.panel-compact { padding: var(--panel-padding-sm); }

.panel[data-tone="info"]    { border-color: var(--accent-info);    background: var(--accent-info-dim); }
.panel[data-tone="warning"] { border-color: var(--accent-warning); background: var(--accent-warning-dim); }
.panel[data-tone="success"] { border-color: var(--accent-success); background: var(--accent-success-dim); }
.panel[data-tone="danger"]  { border-color: var(--accent-danger);  background: var(--accent-danger-dim); }

.panel-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  margin-bottom: var(--space-3);
}
.panel[data-tone="warning"] .panel-header { color: var(--accent-warning); }
.panel[data-tone="info"]    .panel-header { color: var(--accent-info); }
.panel[data-tone="success"] .panel-header { color: var(--accent-success); }
.panel[data-tone="danger"]  .panel-header { color: var(--accent-danger); }

/* =============================================================================
   ANONYMITY MODE
   Toggle via [data-anonymity="true"] on <html>.
   Opt-in: only elements with class .sensitive are blurred.
   Use for screen-sharing, screenshots, or any context where private values
   (amounts, names, IDs, IBAN, etc.) must be hidden on demand.
   ============================================================================= */
.sensitive {
  transition: filter var(--duration-normal) var(--ease-out);
}

:root[data-anonymity="true"] .sensitive,
html[data-anonymity="true"] .sensitive {
  filter: blur(8px);
  user-select: none;
  cursor: help;
}

/* Optional per-element reveal on hover — add data-reveal-on-hover */
:root[data-anonymity="true"] .sensitive[data-reveal-on-hover]:hover,
html[data-anonymity="true"] .sensitive[data-reveal-on-hover]:hover {
  filter: blur(0);
}

/* Active-state indicator on the Anonymity toggle button */
.btn[data-anonymity-active="true"] {
  color: var(--accent-header);
  border-color: var(--accent-header);
  background: var(--accent-header-dim);
}

/* =============================================================================
   UTILITY CLASSES
   ============================================================================= */
.text-muted     { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-info      { color: var(--accent-info); }
.text-success   { color: var(--accent-success); }
.text-danger    { color: var(--accent-danger); }
.text-warning   { color: var(--accent-warning); }
.text-header    { color: var(--accent-header); }

.text-sm  { font-size: var(--fs-sm); }
.text-xs  { font-size: var(--fs-xs); }
.text-lg  { font-size: var(--fs-lg); }

.uppercase   { text-transform: uppercase; letter-spacing: var(--tracking-wider); }
.mono-bold   { font-weight: var(--fw-semibold); }

.flex        { display: flex; }
.flex-col    { display: flex; flex-direction: column; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

/* =============================================================================
   SELECT PILL — <select> che sembra un .tag[data-tone]
   Per stato editabile inline (stato preventivo, voce capitolato, contratto,
   fornitore). Eredita i data-tone semantici del pattern .tag.
   Introdotto in v1.1 (2026-04-24).
   ============================================================================= */
.select-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-5) 2px var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-code);
  color: var(--text-secondary);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  /* Freccia chevron ▾ costruita con due linear-gradient triangolari */
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 10px) 55%,
    calc(100% - 6px) 55%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}
.select-pill:hover { filter: brightness(1.15); }
.select-pill:focus { outline: none; border-color: var(--border-focus); }
.select-pill:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.select-pill[data-tone="info"]      { color: var(--accent-info);      border-color: var(--accent-info);      background-color: var(--accent-info-dim); }
.select-pill[data-tone="success"]   { color: var(--accent-success);   border-color: var(--accent-success);   background-color: var(--accent-success-dim); }
.select-pill[data-tone="danger"]    { color: var(--accent-danger);    border-color: var(--accent-danger);    background-color: var(--accent-danger-dim); }
.select-pill[data-tone="warning"]   { color: var(--accent-warning);   border-color: var(--accent-warning);   background-color: var(--accent-warning-dim); }
.select-pill[data-tone="header"]    { color: var(--accent-header);    border-color: var(--accent-header);    background-color: var(--accent-header-dim); }
.select-pill[data-tone="secondary"] { color: var(--accent-secondary); border-color: var(--accent-secondary); background-color: var(--accent-secondary-dim); }

/* =============================================================================
   ENTITY CARD — Pattern card generico per record operativi
   Usato per contratti, preventivi, fornitori, piante, documenti.
   Struttura: header (titolo + azioni/meta), body (contenuto), footer (meta/link).
   .entity-card-grid è il wrapper responsive opzionale.
   Introdotto in v1.1 (2026-04-24).
   ============================================================================= */
.entity-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-4);
}

.entity-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
}
.entity-card:hover { border-color: var(--border-strong); }

/* Variante accent bar sinistra: 3px verticale per comunicare stato/tono.
   Implementata via ::before pseudo-element invece di border-left: 3px per
   evitare sfasatura visiva sul corner radius (border non uniforme su container
   con border-radius produce un artifact in alto a sinistra). */
.entity-card[data-accent] { position: relative; }
.entity-card[data-accent]::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 3px;
  background: var(--entity-accent-color, transparent);
  border-top-left-radius: inherit;
  border-bottom-left-radius: inherit;
}
.entity-card[data-accent="info"]      { --entity-accent-color: var(--accent-info); }
.entity-card[data-accent="success"]   { --entity-accent-color: var(--accent-success); }
.entity-card[data-accent="danger"]    { --entity-accent-color: var(--accent-danger); }
.entity-card[data-accent="warning"]   { --entity-accent-color: var(--accent-warning); }
.entity-card[data-accent="header"]    { --entity-accent-color: var(--accent-header); }
.entity-card[data-accent="secondary"] { --entity-accent-color: var(--accent-secondary); }

.entity-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.entity-card-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  line-height: var(--lh-tight);
}

.entity-card-subtitle {
  margin-top: var(--space-1);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.entity-card-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-shrink: 0;
}

.entity-card-body {
  padding: var(--space-4) var(--space-5);
  flex: 1;
  font-size: var(--fs-base);
  color: var(--text-secondary);
}

.entity-card-footer {
  padding: var(--space-3) var(--space-5);
  background: var(--bg-panel-elevated);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* =============================================================================
   ACCORDION — Gruppo collassabile (HTML nativo <details>/<summary>)
   Usato per liste raggruppate (voci capitolato per categoria, FAQ, ecc.).
   Accessibile by default grazie ai tag nativi HTML.
   Introdotto in v1.1 (2026-04-24).
   ============================================================================= */
.accordion {
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  overflow: hidden;
}

.accordion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  cursor: pointer;
  list-style: none; /* rimuove marker default di <summary> */
  user-select: none;
  transition: background var(--duration-fast) var(--ease-out);
}
.accordion-header::-webkit-details-marker { display: none; }
.accordion-header:hover { background: var(--bg-panel-elevated); }

/* Chevron ▸ / ▾ ruotato via attributo open del <details> */
.accordion-header::before {
  content: '▸';
  display: inline-block;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  transition: transform var(--duration-fast) var(--ease-out);
  margin-right: var(--space-2);
  flex-shrink: 0;
}
.accordion[open] > .accordion-header::before { transform: rotate(90deg); }

.accordion-title {
  flex: 1;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
}

.accordion-meta {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.accordion-body {
  padding: var(--space-3) var(--space-5) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--fs-base);
  color: var(--text-secondary);
}

/* =============================================================================
   COMPARATOR — Tabella comparativa con evidenza winner
   Per confrontare preventivi, fornitori, opzioni. La riga selezionata ha
   bordo sinistro verde (success) e sfondo success-dim.
   Introdotto in v1.1 (2026-04-24).
   ============================================================================= */
.comparator {
  background: var(--bg-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-4);
}

.comparator-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.comparator-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}

.comparator-meta {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.comparator-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}

.comparator-table thead th {
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  text-align: left;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-default);
  background: var(--bg-panel-elevated);
}
.comparator-table thead th.num,
.comparator-table tbody td.num { text-align: right; }

.comparator-table tbody td {
  padding: var(--space-3) var(--space-4);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
}
.comparator-table tbody tr:last-child td { border-bottom: none; }

/* Riga vincente: evidenziata in verde sia sul bordo sinistro che sul background */
.comparator-table tbody tr[data-winner="true"] td {
  background: var(--accent-success-dim);
}
.comparator-table tbody tr[data-winner="true"] td:first-child {
  border-left: 3px solid var(--accent-success);
  font-weight: var(--fw-semibold);
  color: var(--accent-success);
}

.comparator-table tbody tr:hover td {
  background: var(--bg-panel-elevated);
}
.comparator-table tbody tr[data-winner="true"]:hover td {
  background: var(--accent-success-dim);
}

/* Cella valore rispetto a baseline */
.comparator-cell-over  { color: var(--accent-danger);  font-weight: var(--fw-medium); } /* sopra baseline */
.comparator-cell-under { color: var(--accent-success); font-weight: var(--fw-medium); } /* sotto baseline (risparmio) */
.comparator-cell-inline{ color: var(--text-primary);   font-weight: var(--fw-medium); } /* in linea */

/* =============================================================================
   MODAL DIALOG — built on native <dialog> element
   Use for forms / focused actions that interrupt the page flow.
   Open: dialog.showModal()  ·  Close: dialog.close()
   Esc and backdrop click closing handled in JS (cancel event + click target check).
   ============================================================================= */
.modal {
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-family: var(--font-mono);
  max-width: 720px;
  width: calc(100vw - var(--space-8));
  max-height: calc(100vh - var(--space-8));
  overflow: hidden;
}

/* .modal::backdrop è definito sotto nella sezione "Pattern-level adjustments"
   (slate alpha 0.55, no blur — coerente con regola "no blur fx" Anthropic).
   Il vecchio block con backdrop-filter: blur(4px) era dead code post-rebrand. */

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-md);
  font-family: var(--font-mono);
  cursor: pointer;
  /* min hit area 32x32 (WCAG 2.5.5 minimum), centrato sul glifo */
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: all var(--duration-fast) var(--ease-out);
}
.modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-panel-elevated);
}
.modal-close:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  max-height: calc(100vh - 220px);
}

.modal-footer {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-panel-elevated);
  flex-wrap: wrap;
  justify-content: flex-end;
}


/* =============================================================================
   STR4TUM — Pattern-level adjustments coerenti con i token (no chip su tag,
   inversione cromatica del primary button in dark, modal backdrop senza blur).
   ============================================================================= */

/* (rimosso 2026-05-10) override .tag — assorbito nella definizione base.
   Il pattern "pure typographic / no chip" è ora il default del .tag globale. */

/* Primary button — light: ivory bg + slate text/border (Primary Nav CTA).
   In dark: invertito (ivory bg + slate text + ivory border, "Continue-Reading
   style"). L'asymmetric radius "signature" è opt-in via data-asym="true". */
.btn[data-variant="primary"] {
  background: var(--bg-base);
  color: var(--text-primary);
  border-color: var(--text-primary);
}
[data-theme="dark"] .btn[data-variant="primary"] {
  background: var(--text-primary);   /* ivory inversa */
  color: var(--bg-base);             /* slate-dark */
  border-color: var(--text-primary);
}
.btn[data-variant="primary"]:hover {
  filter: brightness(0.95);
}
.btn[data-asym="true"] {
  border-radius: var(--radius-cta-asym);
}

/* Modal backdrop — no blur, slate-dark con alpha (regola "no blur fx") */
.modal::backdrop {
  background: rgba(20, 20, 19, 0.55);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* =============================================================================
   UTILITY — Underline emphasis
   Thick underline replaces color/weight as the emphasis mechanism in
   display-scale headlines. Use sparingly — only on selected keywords within
   hero / heading-lg sized text.
   ============================================================================= */
.emphasis {
  text-decoration: underline;
  text-decoration-thickness: 4px;
  text-underline-offset: 8px;
  text-decoration-skip-ink: none;
}
