/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
  --c-border:         #d1d5db;
  --c-border-mid:     #e5e7eb;
  --c-border-light:   #f3f4f6;
  --c-text:           #1a1a1a;
  --c-text-secondary: #374151;
  --c-text-muted:     #4b5563;
  --c-text-subtle:    #6b7280;
  --c-bg-subtle:      #f9fafb;
  --c-accent:         #1a56db;
  --c-gain:           #10b981;
  --c-gain-text:      #059669;
  --c-loss-text:      #6b7280;
  --c-tax-text:       #1a1a1a;
  --c-error:          #dc2626;
  --c-error-bg:       #fef2f2;
  --c-error-border:   #fecaca;

  /* Cost-segment palette (ETF cost bar — TER, Bollo, Commissioni, Tasse) */
  --cost-segment-1:   #1a56db;
  --cost-segment-2:   #7c3aed;
  --cost-segment-3:   #0d9488;
  --cost-segment-4:   #475569;
}

/* ── Normalization ──────────────────────────────────────────────────────────── */
/* Honor [hidden] regardless of display rules set by class selectors.
   Without this, rules like .calc-control-group { display: flex } override
   the UA stylesheet's [hidden] { display: none }, breaking JS-toggled visibility. */
[hidden] { display: none !important; }

/* ── Base & layout ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.65;
  color: var(--c-text);
  background: #ffffff;
}

a            { color: var(--c-accent); }
a:visited    { color: #7e3af2; }
a:hover      { text-decoration: none; }

h1, h2, h3   { line-height: 1.25; margin-top: 0; }
p            { margin-top: 0; }

.site-wrapper {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
}

.site-header {
  padding: 1rem 0;
  border-bottom: 1px solid var(--c-border-mid);
}
.site-header__name {
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--c-text);
  letter-spacing: -0.01em;
}

.site-main {
  padding: 2rem 0 3rem;
}

.site-footer {
  padding: 1.5rem 0;
  border-top: 1px solid var(--c-border-mid);
  font-size: 0.875rem;
  color: var(--c-text-subtle);
}
.site-footer__nav {
  margin-bottom: 0.5rem;
}
.site-footer__nav a {
  margin-right: 1.25rem;
  color: var(--c-text-secondary);
  text-decoration: none;
}
.site-footer__nav a:hover {
  text-decoration: underline;
}
.site-footer__meta {
  margin-bottom: 0.5rem;
}
.site-footer__disclaimer {
  font-size: 0.8rem;
  color: var(--c-text-muted);
}

@media (max-width: 480px) {
  body { font-size: 1rem; }
  .site-main { padding: 1.25rem 0 2rem; }
}

/* ── Calculator widget ──────────────────────────────────────────────────────── */

.calc-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

@media (min-width: 560px) {
  .calc-controls         { flex-direction: row; flex-wrap: wrap; }
  .calc-control-group    { flex: 1 1 180px; }
}

.calc-control-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.calc-control-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--c-text-secondary);
}

.calc-control-group select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  font-size: 1rem;
  background: #fff;
  width: 100%;
}

/* Lot tables */
.lot-table-heading {
  font-size: 1rem;
  margin: 1.5rem 0 0.5rem;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.5rem;
}

.lot-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 440px;
  font-size: 0.875rem;
}

.lot-table th {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 2px solid var(--c-border-mid);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--c-text-muted);
  white-space: nowrap;
}

.lot-table td {
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--c-border-light);
  vertical-align: middle;
}

.lot-input {
  width: 100%;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--c-border);
  border-radius: 3px;
  font-size: 0.875rem;
  font-family: inherit;
}

.lot-input:focus {
  outline: 2px solid var(--c-accent);
  outline-offset: 1px;
}

.lot-input--fee { max-width: 90px; }

.lot-date { min-width: 130px; }
.lot-input[aria-invalid="true"] { border-color: var(--c-error); }

/* Add / remove row buttons */
.btn-add-row {
  background: none;
  border: 1px dashed var(--c-text-subtle);
  color: var(--c-text-secondary);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
}
.btn-add-row:hover {
  background: var(--c-bg-subtle);
  border-color: var(--c-text-muted);
}

.btn-remove-row {
  background: none;
  border: none;
  color: var(--c-text-subtle);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
}
.btn-remove-row:hover { color: var(--c-error); }

/* Disclaimer */
.calc-disclaimer {
  font-size: 0.8rem;
  color: var(--c-text-subtle);
  font-style: italic;
  margin: 1.25rem 0 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--c-border-light);
}

/* Result box */
.calc-result {
  margin-top: 0.25rem;
  min-height: 2.5rem;
}

.calc-result__placeholder {
  color: var(--c-text-subtle);
  font-size: 0.875rem;
  margin: 0;
}

.result-summary {
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border-mid);
  border-radius: 6px;
  padding: 1.1rem 1.25rem;
  border-left-width: 4px;
}
.result-summary--gain { border-left-color: var(--c-gain); }
.result-summary--loss { border-left-color: var(--c-text-subtle); }

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--c-border-light);
}
.result-row:last-child { border-bottom: none; }

.result-label {
  font-size: 0.875rem;
  color: var(--c-text-muted);
}
.result-value { font-weight: 700; }
.result-value--gain { color: var(--c-gain-text); }
.result-value--loss { color: var(--c-loss-text); }
.result-value--tax  { font-size: 1.15rem; color: var(--c-tax-text); }

/* Error */
.calc-error {
  color: var(--c-error);
  font-size: 0.875rem;
  padding: 0.6rem 0.8rem;
  background: var(--c-error-bg);
  border: 1px solid var(--c-error-border);
  border-radius: 4px;
  margin: 0;
}

/* Result notes */
.result-notes {
  margin: 0.75rem 0 0;
  padding-left: 1.25rem;
  font-size: 0.8rem;
  color: var(--c-text-muted);
}
.result-notes li { margin-bottom: 0.2rem; }

/* Lot breakdown */
.lot-breakdown {
  margin-top: 1rem;
  font-size: 0.875rem;
}
.lot-breakdown > summary {
  cursor: pointer;
  color: var(--c-text-secondary);
  user-select: none;
  margin-bottom: 0.5rem;
}
.lot-table--breakdown { min-width: 520px; }
.lot-table--breakdown th,
.lot-table--breakdown td { text-align: right; }
.lot-table--breakdown th:first-child,
.lot-table--breakdown td:first-child { text-align: left; }

.lot-cell-num       { text-align: right; font-variant-numeric: tabular-nums; }
.lot-gain-positive  { color: var(--c-gain-text); }
.lot-gain-negative  { color: var(--c-loss-text); }

/* ── FAQ ────────────────────────────────────────────────────────────────────── */

.faq-section { margin-top: 2.5rem; }

.faq-section h2 {
  font-size: 1.2rem;
  border-bottom: 2px solid var(--c-border-mid);
  padding-bottom: 0.4rem;
  margin-bottom: 0;
}

.faq-item {
  border-bottom: 1px solid var(--c-border-mid);
}

.faq-question {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.85rem 1.5rem 0.85rem 0;
  list-style: none;
  position: relative;
  color: var(--c-text);
}
.faq-question::-webkit-details-marker { display: none; }
.faq-question::after {
  content: '+';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: var(--c-text-subtle);
  font-weight: 400;
}
.faq-item[open] .faq-question::after { content: '−'; }

.faq-answer {
  padding: 0 0 1rem;
  color: var(--c-text-secondary);
  font-size: 0.9375rem;
}

/* ── Page template ──────────────────────────────────────────────────────────── */

.page-section-body { margin-bottom: 1.5rem; }

.page-last-updated {
  font-size: 0.875rem;
  color: var(--c-text-muted);
  margin-bottom: 2rem;
}

/* ── Prose sections ─────────────────────────────────────────────────────────── */

.prose-section { margin-top: 2.5rem; }

.prose-section h2 {
  font-size: 1.2rem;
  border-bottom: 2px solid var(--c-border-mid);
  padding-bottom: 0.4rem;
  margin-bottom: 1rem;
}

.prose-section ul  { padding-left: 1.5rem; }
.prose-section li  { margin-bottom: 0.3rem; }

/* ── Related ────────────────────────────────────────────────────────────────── */

.related-section { margin-top: 2.5rem; }

.related-section h2 {
  font-size: 1.2rem;
  border-bottom: 2px solid var(--c-border-mid);
  padding-bottom: 0.4rem;
  margin-bottom: 0.75rem;
}

.related-section ul { padding-left: 1.25rem; }

/* ── Info box ───────────────────────────────────────────────────────────────── */

.info-box {
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border-mid);
  border-left: 4px solid var(--c-accent);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-size: 0.9375rem;
}

.info-box p:last-child { margin-bottom: 0; }

.info-box__heading {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.info-box--fee {
  border-left-color: var(--c-text-muted);
  font-size: 0.875rem;
  color: var(--c-text-secondary);
  padding: 0.6rem 1rem;
}

/* ── CSV instructions ───────────────────────────────────────────────────────── */

.csv-instructions {
  margin: 1.5rem 0;
}

.csv-instructions__heading {
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.csv-instructions__cols {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}

.csv-instructions__cols li code {
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border-mid);
  border-radius: 3px;
  padding: 0.15rem 0.45rem;
  font-size: 0.8rem;
  font-family: monospace;
}

.csv-instructions__note {
  font-size: 0.8rem;
  color: var(--c-text-muted);
  margin-top: 0.4rem;
}

.csv-example {
  margin-top: 0.75rem;
}

.csv-example > summary {
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--c-text-secondary);
  user-select: none;
}

.csv-pre {
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border-mid);
  border-radius: 4px;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-family: monospace;
  overflow-x: auto;
  white-space: pre;
  margin: 0.5rem 0 0;
}

/* ── CSV textarea ───────────────────────────────────────────────────────────── */

.csv-input-area {
  margin-bottom: 1rem;
}

.csv-input-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--c-text-secondary);
  margin-bottom: 0.4rem;
}

.csv-textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: monospace;
  resize: vertical;
  line-height: 1.5;
  background: #fff;
  color: var(--c-text);
}

.csv-textarea:focus {
  outline: 2px solid var(--c-accent);
  outline-offset: 1px;
}

/* ── Method toggle + Calcola button row ──────────────────────────────────────── */

.calc-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.method-toggle {
  display: flex;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  overflow: hidden;
}

.method-btn {
  background: #fff;
  border: none;
  border-right: 1px solid var(--c-border);
  color: var(--c-text-secondary);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  line-height: 1;
}

.method-btn:last-child { border-right: none; }

.method-btn:hover { background: var(--c-bg-subtle); }

.method-btn--active {
  background: var(--c-accent);
  color: #fff;
}

.method-btn--active:hover { background: var(--c-accent); }

.btn-calcola {
  background: var(--c-accent);
  border: none;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 0.55rem 1.5rem;
}

.btn-calcola:hover { opacity: 0.9; }
.btn-calcola:focus { outline: 2px solid var(--c-accent); outline-offset: 2px; }

/* ── Cross-link box ─────────────────────────────────────────────────────────── */

.cross-link-box {
  margin: 2rem 0 1rem;
  padding: 0.9rem 1.25rem;
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border-mid);
  border-radius: 6px;
  font-size: 0.9375rem;
}

.cross-link-box a {
  font-weight: 600;
  white-space: nowrap;
}

/* ── Page disclaimer ────────────────────────────────────────────────────────── */

.page-disclaimer {
  font-size: 0.8rem;
  color: var(--c-text-muted);
  font-style: italic;
  margin-top: 0.5rem;
}

/* ── FIFO asset breakdown table ──────────────────────────────────────────────── */

.fifo-asset-table {
  margin-top: 1rem;
  min-width: 380px;
}

/* ── Warning banner ─────────────────────────────────────────────────────────── */

.calc-banner--warning {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-left: 4px solid #f59e0b;
  border-radius: 6px;
  padding: 0.75rem 1.25rem;
  margin: 1.5rem 0;
  font-size: 0.875rem;
  color: #78350f;
}

/* ── Rivalutazione badge ─────────────────────────────────────────────────────── */

.riv-badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.riv-badge--conviene     { background: #d1fae5; color: #065f46; }
.riv-badge--non-conviene { background: #fee2e2; color: #991b1b; }
.riv-badge--zona-grigia  { background: #fef3c7; color: #92400e; }

.result-summary--neutral { border-left-color: #f59e0b; }

/* ── Radio group ─────────────────────────────────────────────────────────────── */

.radio-group {
  display: flex;
  gap: 1.25rem;
  margin-top: 0.25rem;
  align-items: center;
}
.radio-group label {
  font-size: 0.9375rem;
  cursor: pointer;
  color: var(--c-text);
  font-weight: normal;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* ── Break-even and instalment plan ─────────────────────────────────────────── */

.result-breakeven {
  font-size: 0.8rem;
  color: var(--c-text-muted);
  margin: 0.5rem 0 0;
  padding-top: 0.5rem;
  border-top: 1px solid var(--c-border-light);
}

.riv-instalment {
  margin-top: 1.25rem;
}
.riv-instalment__heading {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--c-text-secondary);
  margin-bottom: 0.5rem;
}
.riv-instalment__total td { border-top: 2px solid var(--c-border-mid); }

/* ── Checkbox toggle row ─────────────────────────────────────────────────────── */

.calc-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9375rem;
  color: var(--c-text-secondary);
  cursor: pointer;
}
.calc-toggle-row input[type="checkbox"] { cursor: pointer; }

/* ── Broker comparison table ────────────────────────────────────────────────── */

.is-collapsed { display: none; }

.lot-table--broker { min-width: 580px; }
.lot-table--broker td { vertical-align: top; padding-top: 0.4rem; }
.broker-col-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.broker-toggle-btn {
  background: none;
  border: none;
  color: var(--c-accent);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.15rem 0 0 0.35rem;
  text-decoration: underline;
  text-decoration-style: dotted;
  vertical-align: middle;
  display: block;
}
.broker-toggle-btn:hover { text-decoration-style: solid; }

.broker-row--secondary td { background: var(--c-bg-subtle); }

.broker-note {
  font-size: 0.775rem;
  color: var(--c-text-muted);
  line-height: 1.4;
}
.broker-note-details > summary {
  cursor: pointer;
  list-style: none;
}
.broker-note-details > summary::-webkit-details-marker { display: none; }
.broker-note--full { display: none; }
details[open].broker-note-details .broker-note--short { display: none; }
details[open].broker-note-details .broker-note--full { display: inline; }

.broker-disclaimer {
  background: var(--c-bg-subtle);
  border: 1px solid var(--c-border-mid);
  border-left: 4px solid var(--c-text-muted);
  border-radius: 6px;
  padding: 0.65rem 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.8375rem;
  color: var(--c-text-secondary);
}

.page-meta {
  font-size: 0.8rem;
  color: var(--c-text-subtle);
  margin-top: -0.75rem;
  margin-bottom: 1.25rem;
}

/* ── Affiliate CTA ──────────────────────────────────────────────────────────── */

.affiliate-cta {
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-accent);
  border-radius: 6px;
  padding: 1.1rem 1.25rem;
  margin: 1.75rem 0;
  background: #fff;
}

.affiliate-cta__adv-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-muted);
  margin-bottom: 0.5rem;
}

.affiliate-cta__heading {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 0.4rem;
  color: var(--c-text);
}

.affiliate-cta__pitch {
  font-size: 0.9375rem;
  color: var(--c-text-secondary);
  margin-bottom: 0.85rem;
}

.affiliate-cta__btn {
  display: inline-block;
  background: var(--c-accent);
  color: #fff;
  padding: 0.55rem 1.4rem;
  border-radius: 4px;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 0.75rem;
}

.affiliate-cta__btn:hover   { opacity: 0.9; color: #fff; text-decoration: none; }
.affiliate-cta__btn:visited { color: #fff; }
.affiliate-cta__btn:focus   { outline: 2px solid var(--c-accent); outline-offset: 2px; }

.affiliate-cta__disclosure {
  display: block;
  font-size: 0.775rem;
  color: var(--c-text-muted);
  margin-top: 0.1rem;
}

@media (max-width: 480px) {
  .affiliate-cta { padding: 0.9rem 1rem; }
  .affiliate-cta__btn { width: 100%; text-align: center; box-sizing: border-box; }
}

/* ── Accessibility ──────────────────────────────────────────────────────────── */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Print: Quadro RW prospetto ─────────────────────────────────────────────── */
/* Shows only .prospetto-print; hides all other page chrome.                    */
/* Does not affect screen rendering.                                             */
@media print {
  body * { visibility: hidden; }
  .prospetto-print,
  .prospetto-print * { visibility: visible; }
  .prospetto-print {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1.5rem;
    box-sizing: border-box;
    background: #fff;
    color: #000;
    font-size: 11pt;
  }
  /* restore display for table elements hidden by visibility collapse */
  .prospetto-print table  { display: table;      width: 100%; }
  .prospetto-print thead  { display: table-header-group; }
  .prospetto-print tbody  { display: table-row-group; }
  .prospetto-print tr     { display: table-row; }
  .prospetto-print th,
  .prospetto-print td     { display: table-cell; border: 1px solid #ccc; padding: 4px 6px; }
  .prospetto-print h2     { font-size: 14pt; margin-bottom: 0.5rem; }
  .prospetto-print h3     { font-size: 11pt; margin: 0.75rem 0 0.25rem; }
  .prospetto-print .info-box { border: 1px solid #ccc; padding: 0.5rem; margin-top: 0.75rem; }
  .prospetto-print .table-scroll { overflow: visible; }
}
