:root {
  --bg-1: #f3efe5;
  --bg-2: #dfe8d2;
  --ink: #1e2d24;
  --muted: #66766d;
  --panel: rgba(255, 252, 246, 0.86);
  --accent: #0f9d6c;
  --accent-soft: #d8f5ea;
  --danger-soft: #fde3de;
  --line: rgba(30, 45, 36, 0.08);
}

[x-cloak] { display: none !important; }

body.app-shell {
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 157, 108, 0.18), transparent 30%),
    radial-gradient(circle at top right, rgba(210, 159, 76, 0.22), transparent 28%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2));
  font-family: "Space Grotesk", sans-serif;
}

.topbar {
  padding: 1.25rem 0;
  background: #111118;
  backdrop-filter: blur(20px);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.topbar-inner,
.workspace-grid,
.summary-strip,
.facts-grid,
.chart-grid {
  display: grid;
  gap: 1rem;
}

.topbar-inner {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.eyebrow {
  margin: 0 0 .25rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: .72rem;
  color: var(--muted);
}

.brand-title,
.hero-copy h2,
.dashboard-head h2 {
  margin: 0;
  font-weight: 700;
}

.hero-panel {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 1.5rem;
  align-items: stretch;
}

.hero-copy,
.selection-card,
.dashboard-block,
.glossy-card,
.upload-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 24px 64px rgba(44, 61, 51, 0.08);
}

.hero-copy {
  padding: 2rem;
}

.selection-card .card-body,
.glossy-card .card-body,
.upload-card .card-body,
.chart-card .card-body,
.offer-notes .card-body,
.empty-state .card-body {
  padding: 1.5rem;
}

.selection-form,
.stack-form,
.dashboard-panel,
.warning-stack,
.scenario-accordion,
.flash-stack {
  display: grid;
  gap: 1rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
}

.segmented label {
  padding: .9rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  text-align: center;
  font-weight: 600;
}

.segmented label.active {
  background: #10211a;
  color: #fff;
}

.segmented input { display: none; }

.selection-notes {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.password-field {
  position: relative;
}

.password-field .form-control {
  padding-right: 3rem;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: .65rem;
  transform: translateY(-50%);
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.password-toggle:hover {
  background: rgba(16, 33, 26, 0.06);
  color: var(--ink);
}

.note-chip {
  padding: .55rem .85rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #0b6646;
  font-size: .82rem;
}

.step-hint {
  padding: .9rem 1rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.56);
  font-size: .92rem;
  color: var(--ink);
}

.step-hint strong {
  margin-right: .35rem;
}

.resume-box,
.report-box {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.report-title {
  margin: 0 0 .75rem;
  font-size: 1rem;
}

.report-log {
  display: grid;
  gap: .55rem;
  margin-bottom: .85rem;
}

.report-step,
.report-error {
  padding: .7rem .85rem;
  border-radius: 14px;
  font-size: .9rem;
}

.report-step {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

.report-error {
  margin-bottom: .75rem;
  background: var(--danger-soft);
  border: 1px solid rgba(170, 62, 32, 0.12);
  color: #8d3b23;
}

.mini-warning {
  padding: .55rem .75rem;
  border-radius: 14px;
  background: rgba(255, 240, 210, 0.72);
  font-size: .86rem;
}

.busy-indicator {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .85rem;
  align-items: start;
  padding: .95rem 1rem;
  border-radius: 18px;
  border: 1px solid rgba(15, 157, 108, 0.15);
  background: rgba(216, 245, 234, 0.7);
}

.busy-indicator p {
  margin: .2rem 0 0;
  color: var(--muted);
  font-size: .9rem;
}

.busy-spinner {
  width: 1.1rem;
  height: 1.1rem;
  margin-top: .15rem;
  border: 2px solid rgba(15, 157, 108, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.workspace-grid {
  grid-template-columns: 320px 1fr;
  align-items: start;
}

.workspace-shell,
.upload-grid {
  display: grid;
  gap: 1rem;
}

.workspace-hero-body {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 1rem;
  align-items: center;
}

.workspace-hero-actions {
  display: grid;
  gap: .85rem;
  justify-items: end;
}

.upload-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.control-panel {
  display: grid;
  gap: 1rem;
}

.dashboard-block {
  padding: 1.25rem;
}

.dashboard-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1rem;
}

.dashboard-actions {
  display: flex;
  gap: .65rem;
}

.tab-toggle {
  padding: .75rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.64);
  font-weight: 600;
}

.tab-toggle.active,
.summary-card.primary {
  background: #10211a;
  color: #fff;
}

.dropzone {
  position: relative;
  border: 2px dashed rgba(15, 157, 108, 0.35);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(216, 245, 234, 0.55), rgba(255, 255, 255, 0.82));
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
  cursor: pointer;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  box-shadow: 0 16px 36px rgba(15, 157, 108, 0.12);
  transform: translateY(-1px);
}

.dropzone-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone-body {
  min-height: 150px;
  padding: 1.25rem;
  display: grid;
  place-items: center;
  text-align: center;
  gap: .35rem;
}

.dropzone-body strong {
  font-size: 1.05rem;
}

.dropzone-body span,
.dropzone-summary {
  color: var(--muted);
}

.dashboard-full {
  width: 100%;
}

.facts-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.fact-card,
.summary-card {
  padding: 1rem 1.1rem;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.fact-card span,
.summary-card span {
  display: block;
  color: var(--muted);
  font-size: .82rem;
}

.fact-card strong,
.summary-card strong {
  display: block;
  font-size: 1.22rem;
  margin-top: .35rem;
}

.summary-card small {
  display: block;
  margin-top: .35rem;
  color: var(--muted);
  font-size: .78rem;
}

.summary-strip {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.warning-card p,
.scenario-body p,
.chart-head p {
  margin: .4rem 0 0;
}

.scenario-item {
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  overflow: hidden;
}

.scenario-item summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  font-weight: 600;
}

.scenario-body {
  padding: 0 1.1rem 1rem;
}

.column-switches {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.comparison-table-wrap {
  overflow-x: auto;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
}

.comparison-table {
  margin-bottom: 0;
  width: 100%;
  table-layout: fixed;
}

.comparison-table thead th {
  white-space: nowrap;
  background: rgba(16, 33, 26, 0.06);
  width: 180px;
}

.comparison-table thead th:first-child {
  width: 300px;
}

.offer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.offer-head span {
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.offer-remove {
  width: 1.7rem;
  height: 1.7rem;
  border: 1px solid rgba(30, 45, 36, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: #8b1e1e;
  line-height: 1;
  font-weight: 700;
}

.offer-remove:hover {
  background: rgba(255, 235, 235, 0.9);
}

.section-row td {
  font-weight: 700;
  background: rgba(16, 33, 26, 0.08);
}

.label-cell {
  min-width: 300px;
  width: 300px;
}

.comparison-cell {
  min-width: 160px;
  width: 180px;
  vertical-align: top;
}

.cell-main {
  font-weight: 600;
}

.cell-note {
  margin-top: .28rem;
  font-size: .75rem;
  line-height: 1.25;
  color: #5f6e66;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: help;
}

.winner-current {
  background: linear-gradient(180deg, rgba(213, 249, 229, 0.96), rgba(192, 239, 214, 0.96));
  color: #0f6b49;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(15, 107, 73, 0.12);
}

.winner-offer {
  background: linear-gradient(180deg, rgba(201, 255, 227, 0.98), rgba(173, 241, 204, 0.98));
  color: #0d7e55;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(13, 126, 85, 0.14);
}

.chart-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.chart-card,
.offer-notes {
  border-radius: 24px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
}

.offer-notes-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.offer-notes-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.plotly-chart {
  min-height: 320px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1024px) {
  .hero-panel,
  .workspace-grid,
  .workspace-hero-body {
    grid-template-columns: 1fr;
  }

  .dashboard-head {
    flex-direction: column;
    align-items: start;
  }

  .workspace-hero-actions {
    justify-items: start;
  }
}

/* ---------- marchio, menu utente, elenco analisi, accesso ---------- */
.topbar { position: relative; z-index: 50; padding: .85rem 0; padding-top: max(.85rem, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: .75rem; color: #fff; text-decoration: none; min-width: 0; }
.brand:hover { color: #fff; text-decoration: none; }
.brand img { flex: none; border-radius: 12px; }
.brand > span { display: grid; min-width: 0; }
.brand .brand-title { font-size: 1.2rem; line-height: 1.2; }
.brand-sub { font-size: .78rem; color: rgba(255, 255, 255, .62); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: .55rem; cursor: pointer; color: #fff; padding: .3rem .4rem; border-radius: 999px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: rgba(255, 255, 255, .08); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #FFB703; color: #111118; font-weight: 700; }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + .4rem); z-index: 30; min-width: 220px; background: #fff; color: var(--ink); border-radius: 16px; box-shadow: 0 18px 48px rgba(0, 0, 0, .22); padding: .4rem; display: grid; }
.user-menu-head { display: grid; padding: .6rem .75rem; border-bottom: 1px solid var(--line); margin-bottom: .3rem; }
.user-menu-head small { color: var(--muted); }
.user-menu-panel a, .user-menu-panel button { display: block; width: 100%; text-align: left; padding: .6rem .75rem; border: 0; background: none; border-radius: 10px; color: inherit; font: inherit; text-decoration: none; cursor: pointer; }
.user-menu-panel a:hover, .user-menu-panel button:hover { background: #f1f3f1; }

.ws-list { display: grid; gap: .35rem; }
.ws-row { display: flex; align-items: center; gap: .5rem; border-radius: 16px; padding: .25rem .25rem .25rem 0; }
.ws-row:hover { background: rgba(255, 255, 255, .6); }
.ws-main { flex: 1; min-width: 0; display: grid; padding: .6rem .8rem; color: inherit; text-decoration: none; }
.ws-main:hover { color: inherit; text-decoration: none; }
.ws-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-main small { color: var(--muted); }
.ws-delete { border: 0; background: none; color: var(--muted); padding: .5rem; border-radius: 10px; }
.ws-delete:hover { color: #c2453b; background: var(--danger-soft); }

.auth-wrap { display: grid; place-items: center; min-height: 60vh; }
.auth-card { width: min(420px, 100%); border-radius: 28px; border: 1px solid var(--line); background: var(--panel); box-shadow: 0 24px 64px rgba(44, 61, 51, .08); }
.auth-card.wide { width: min(640px, 100%); }
.auth-card .card-body { padding: 2rem; }
.auth-logo { display: block; margin-bottom: 1rem; border-radius: 18px; }
.inline-form { display: flex; gap: .5rem; }

@media (max-width: 640px) {
  .brand-sub, .user-name { display: none; }
  .auth-card .card-body { padding: 1.4rem; }
}
