:root {
  --bg: var(--color-bg, #ffffff);
  --card: color-mix(in srgb, var(--color-surface, #ffffff) 92%, white 8%);
  --card-strong: var(--color-surface, #ffffff);
  --line: var(--color-border, #dcdce2);
  --ink: var(--color-text-primary, #111116);
  --muted: var(--color-text-secondary, #52525c);
  --primary: var(--color-brand-primary, #492775);
  --secondary: var(--color-secondary-lavanda, #9c75ad);
  --danger: var(--color-service-calculo, #ee3257);
  --shadow: var(--shadow-lg, 0 12px 32px rgba(0, 0, 0, 0.12));
  --radius: var(--radius-xl, 20px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body, "Instrument Sans", "Segoe UI", sans-serif);
  font-size: var(--text-base, 15px);
  line-height: var(--leading-normal, 1.5);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--color-secondary-lavanda, #9c75ad) 22%, transparent), transparent 34%),
    radial-gradient(circle at bottom right, color-mix(in srgb, var(--color-service-configurador, #72cbcd) 20%, transparent), transparent 36%),
    linear-gradient(180deg, var(--color-bg, #ffffff) 0%, var(--color-bg-subtle, #f8f8fa) 100%);
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(30px);
  opacity: 0.6;
  pointer-events: none;
}

.bg-shape-a {
  top: -80px;
  right: -80px;
  width: 280px;
  height: 280px;
  background: color-mix(in srgb, var(--color-brand-primary, #492775) 18%, transparent);
}

.bg-shape-b {
  bottom: -100px;
  left: -100px;
  width: 320px;
  height: 320px;
  background: color-mix(in srgb, var(--color-service-configurador, #72cbcd) 22%, transparent);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto;
}

.view,
.screen {
  display: none;
}

.view.active,
.screen.active {
  display: block;
}

.card {
  background: var(--card);
  border: 1px solid color-mix(in srgb, var(--line) 82%, white 18%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  padding: 20px;
}

.login-card {
  width: min(520px, 100%);
  margin: 10vh auto 0;
}

.login-language {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: var(--text-xs, 11px);
  font-weight: var(--font-weight-bold, 700);
  color: var(--secondary);
  margin-bottom: 8px;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display, "Bai Jamjuree", sans-serif);
  color: var(--color-text-primary, #111116);
  line-height: var(--leading-tight, 1.1);
}

h1 {
  font-size: var(--text-hero, clamp(1.75rem, 3vw, 2.75rem));
}

h2 {
  font-size: var(--text-3xl, clamp(1.625rem, 3vw, 2.25rem));
}

h3 {
  font-size: var(--text-2xl, clamp(1.375rem, 2.5vw, 1.75rem));
}

h4 {
  font-size: var(--text-xl, 1.25rem);
}

.lead,
.muted {
  color: var(--muted);
}

.lead {
  font-size: 0.96rem;
}

.stack,
.stack-lg {
  display: grid;
  gap: 16px;
}

.stack-lg {
  gap: 24px;
}

label {
  display: grid;
  gap: 6px;
  font-size: var(--text-sm, 13px);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  padding: 10px 12px;
  background: color-mix(in srgb, var(--color-surface, #ffffff) 96%, var(--color-bg-subtle, #f8f8fa) 4%);
  color: var(--ink);
}

button {
  border: 0;
  border-radius: var(--radius-full, 9999px);
  padding: 10px 16px;
  font-size: var(--text-sm, 13px);
  font-weight: var(--font-weight-semibold, 600);
  cursor: pointer;
  transition: transform var(--transition-fast, 150ms ease), box-shadow var(--transition-fast, 150ms ease), background var(--transition-fast, 150ms ease);
}

button.primary {
  background: var(--primary);
  color: var(--color-text-inverse, white);
  box-shadow: var(--shadow-brand, 0 8px 24px rgba(73, 39, 117, 0.25));
}

button.secondary {
  background: var(--color-service-configurador, #72cbcd);
  color: var(--color-text-primary, #111116);
}

button.ghost {
  background: color-mix(in srgb, var(--color-surface, #ffffff) 88%, var(--color-bg-subtle, #f8f8fa) 12%);
  color: var(--ink);
  border: 1px solid var(--line);
}

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

button.danger {
  background: color-mix(in srgb, var(--danger) 12%, white 88%);
  color: var(--danger);
}

td button + button {
  margin-left: 8px;
}

.form-error {
  min-height: 20px;
  color: var(--danger);
}

.login-hint {
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
}

.topbar,
.toolbar,
.toolbar.compact,
.toolbar-actions,
.topbar-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.topbar {
  margin-bottom: 20px;
}

.toolbar {
  margin-bottom: 18px;
}

.simulation-filters {
  margin-bottom: 18px;
}

.general-card {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.general-card > h4 {
  order: 0;
}

.general-card > .grid.grid-3 {
  order: 1;
  margin-top: 8px;
}

.project-type-row {
  margin-top: 16px;
  order: 2;
}

.user-badge {
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--card-strong);
  border: 1px solid var(--line);
  color: var(--muted);
}

.language-picker {
  display: grid;
  gap: 6px;
  min-width: 88px;
}

.language-picker span {
  font-size: 12px;
  color: var(--muted);
}

.language-picker select {
  min-width: 68px;
  background: white;
  font-weight: 600;
  text-align: center;
}

.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;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.rates-panel {
  margin-top: 18px;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(114, 203, 205, 0.12), rgba(156, 117, 173, 0.05));
  border: 1px solid rgba(114, 203, 205, 0.24);
  order: 4;
}

.rates-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 14px;
}

.rates-header h4 {
  margin-bottom: 0;
}

.rates-grid {
  gap: 14px;
}

.rate-field {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(156, 117, 173, 0.18);
}

.rate-field span {
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(220, 228, 237, 0.9);
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.module-name {
  font-weight: 600;
}

.totals-card {
  background: linear-gradient(135deg, rgba(73, 39, 117, 0.97), rgba(116, 81, 163, 0.94));
  color: white;
  box-shadow: 0 18px 40px rgba(73, 39, 117, 0.24);
}

.totals-card h4 {
  color: white;
}

.totals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}

.totals-grid .muted {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  margin-bottom: 8px;
}

.totals-grid strong {
  font-size: 1.08rem;
  line-height: 1.25;
}

.totals-grid .accent {
  padding: 14px;
  border-radius: 18px;
  background: rgba(220, 228, 237, 0.16);
}

.totals-total-row {
  margin-top: 10px;
}

.totals-total-row.with-separator {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.78);
}

.rd-tax-card {
  color: var(--ink);
}

.rd-tax-card h4,
.rd-tax-card label,
.rd-tax-card .export-checkbox-row span {
  color: var(--ink);
}

.rd-tax-summary .muted {
  color: var(--muted);
}

.rd-tax-summary strong {
  color: var(--primary);
}

.module-dialog {
  width: min(1040px, calc(100vw - 20px));
  border: 0;
  border-radius: 24px;
  padding: 0;
  background: transparent;
}

.module-dialog::backdrop {
  background: rgba(17, 17, 22, 0.34);
}

.module-dialog form {
  background: var(--card-strong);
  padding: 0;
  border-radius: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 920px);
  overflow: hidden;
}

.module-dialog-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
}

.module-dialog-header {
  margin: 0 -20px 18px;
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 8px 16px rgba(73, 39, 117, 0.08);
  padding: 16px 20px 12px;
  border-bottom: 1px solid rgba(220, 228, 237, 0.92);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
}

.module-section {
  padding: 16px;
  margin-bottom: 16px;
}

.module-section h4 {
  margin-bottom: 16px;
}

.section-description {
  margin-bottom: 14px;
  font-size: 0.88rem;
}

.module-inline-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(220, 228, 237, 0.38);
  border: 1px solid rgba(114, 203, 205, 0.28);
}

.module-inline-total-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.total-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.total-toggle input {
  width: auto;
  margin: 0;
}

.module-inline-total strong {
  font-size: 1rem;
  color: var(--primary);
}

.module-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.summary-single {
  grid-template-columns: 1fr;
}

.module-summary-card {
  padding: 14px;
  border-radius: 14px;
  background: rgba(245, 248, 252, 0.92);
  border: 1px solid rgba(220, 228, 237, 0.95);
}

.module-summary-heading {
  margin-bottom: 10px;
  text-align: center;
  color: var(--primary);
  font-family: var(--font-display, "Bai Jamjuree", sans-serif);
  font-size: 0.96rem;
}

.module-summary-line {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid rgba(220, 228, 237, 0.9);
  text-align: center;
}

.module-summary-line:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.module-summary-line span {
  color: var(--muted);
  font-size: 0.85rem;
}

.module-summary-line strong {
  text-align: center;
  color: #173724;
}

.collapsible-section {
  overflow: hidden;
}

.section-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: transparent;
  color: var(--primary);
  border: 0;
  padding: 2px 0;
  border-radius: 0;
  font-family: var(--font-display, "Bai Jamjuree", sans-serif);
  font-size: 1rem;
  cursor: pointer;
}

.module-section-toolbar {
  align-items: center;
  margin-bottom: 10px;
}

.section-body {
  padding-top: 14px;
}

.section-chevron {
  color: var(--secondary);
  font-size: 0.9rem;
  transition: transform 0.2s ease;
}

.collapsible-section.is-collapsed .section-body {
  display: none;
}

.collapsible-section.is-collapsed .section-chevron {
  transform: rotate(-90deg);
}

.module-dialog-footer {
  position: sticky;
  bottom: 0;
  z-index: 4;
  background: linear-gradient(180deg, rgba(248, 250, 253, 0.92), rgba(255, 255, 255, 1));
  border-top: 1px solid rgba(220, 228, 237, 0.92);
  padding: 14px 20px 18px;
}

.export-checkbox {
  display: grid;
  align-content: start;
}

.export-checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 12px);
  background: color-mix(in srgb, var(--color-surface, #ffffff) 96%, var(--color-bg-subtle, #f8f8fa) 4%);
}

.export-checkbox-row input {
  width: auto;
  margin: 0;
}

.module-cost-table {
  overflow-x: hidden;
}

.module-cost-table table {
  table-layout: fixed;
}

.module-cost-table th,
.module-cost-table td {
  vertical-align: top;
}

.module-cost-table th:nth-child(2),
.module-cost-table th:nth-child(4) {
  text-align: center;
}

.module-cost-table th:nth-child(1),
.module-cost-table td:nth-child(1) {
  width: 25%;
}

.module-cost-table th:nth-child(2),
.module-cost-table td:nth-child(2),
.module-cost-table th:nth-child(4),
.module-cost-table td:nth-child(4) {
  width: 20%;
}

.module-cost-table th:nth-child(3),
.module-cost-table td:nth-child(3),
.module-cost-table th:nth-child(5),
.module-cost-table td:nth-child(5) {
  width: 10%;
}

.module-cost-table th:last-child,
.module-cost-table td:last-child {
  width: 15%;
}

.module-cost-table table input,
.module-cost-table table select {
  min-width: 0;
  width: 100%;
  padding: 9px 10px;
}

.time-input-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
  align-items: start;
}

.time-unit-select,
.employee-type-select {
  min-width: 0;
}

.module-cost-table td:last-child button {
  width: 100%;
}

.reference-hourly-cost {
  margin-top: 12px;
}

.project-pricing {
  margin: 18px 0 0;
  background: linear-gradient(180deg, rgba(156, 117, 173, 0.1), rgba(114, 203, 205, 0.04));
  border: 1px solid rgba(156, 117, 173, 0.22);
  order: 3;
}

.general-card > label:last-child {
  order: 5;
}

.hidden {
  display: none !important;
}

.module-product-years-field {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
}

.module-product-years-field > span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.module-product-years-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 12px;
}

.module-product-year-item {
  display: grid;
  gap: 6px;
}

.module-product-year-item span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.module-impact-breakdown {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(220, 228, 237, 0.92);
  border-radius: 16px;
  background: rgba(242, 247, 255, 0.92);
}

.impact-volume-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.impact-volume-list li {
  margin: 0 0 4px;
}

#tokensPerYearField {
  order: 2;
}

#moduleTokenCountField.hidden {
  display: none !important;
}

#moduleTokensAppliedYearField.hidden {
  display: none !important;
}

#moduleTokenCountField {
  order: 4;
}

#moduleTokensAppliedYearField {
  order: 5;
}

#moduleClientUserTypeField {
  order: 6;
}

#moduleClientHoursField {
  order: 7;
}

#tokensAppliedYearSelect.single-option-lock {
  pointer-events: none;
  background: rgba(236, 242, 248, 0.98);
  color: var(--muted);
}

.simple-metrics-table table {
  table-layout: fixed;
}

.simple-metrics-table th:nth-child(1),
.simple-metrics-table td:nth-child(1) {
  width: 54%;
}

.simple-metrics-table th:nth-child(2),
.simple-metrics-table td:nth-child(2),
.simple-metrics-table th:nth-child(3),
.simple-metrics-table td:nth-child(3) {
  width: 23%;
}

.simple-metrics-table td:first-child {
  font-weight: 600;
  color: var(--primary);
}

.simple-metrics-table input {
  width: 100%;
}

.reinvestment-table {
  margin-top: 16px;
}

.reinvestment-header {
  margin-top: 18px;
}

.reinvestment-header h5 {
  margin: 0 0 8px;
  color: var(--primary);
  font-family: var(--font-display, "Bai Jamjuree", sans-serif);
  font-size: 0.98rem;
}

.reinvestment-table table {
  table-layout: fixed;
}

.reinvestment-table th,
.reinvestment-table td {
  width: 25%;
}

.reinvestment-table td:first-child {
  font-weight: 700;
  color: var(--primary);
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .grid-3,
  .grid-2,
  .totals-grid,
  .module-product-years-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .toolbar,
  .toolbar.compact,
  .toolbar-actions,
  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    width: 100%;
  }

  .app-shell {
    width: min(100vw - 16px, 1180px);
    margin: 12px auto;
  }

  .card {
    padding: 16px;
  }

  .module-dialog {
    width: calc(100vw - 10px);
  }

  .module-inline-total,
  .module-summary-line {
    flex-direction: column;
    align-items: flex-start;
  }

  .module-summary-grid {
    grid-template-columns: 1fr;
  }

  .module-dialog-body,
  .module-dialog-footer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .module-cost-table table,
  .module-cost-table thead,
  .module-cost-table tbody,
  .module-cost-table tr,
  .module-cost-table th,
  .module-cost-table td,
  .reinvestment-table table,
  .reinvestment-table thead,
  .reinvestment-table tbody,
  .reinvestment-table tr,
  .reinvestment-table th,
  .reinvestment-table td,
  .simple-metrics-table table,
  .simple-metrics-table thead,
  .simple-metrics-table tbody,
  .simple-metrics-table tr,
  .simple-metrics-table th,
  .simple-metrics-table td {
    display: block;
    width: 100%;
  }

  .module-cost-table thead,
  .reinvestment-table thead,
  .simple-metrics-table thead {
    display: none;
  }

  .module-cost-table tr,
  .reinvestment-table tr,
  .simple-metrics-table tr {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid rgba(220, 228, 237, 0.92);
    border-radius: 14px;
    background: rgba(245, 248, 252, 0.92);
  }

  .module-cost-table td,
  .reinvestment-table td,
  .simple-metrics-table td {
    border: 0;
    padding: 0 0 10px;
  }

  .module-cost-table td::before,
  .reinvestment-table td::before,
  .simple-metrics-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .simple-metrics-table td:first-child {
    padding-top: 0;
  }
}
