:root {
  --bg-deep: #07090f;
  --bg-base: #0c1017;
  --bg-card: #131820;
  --bg-card-hover: #171d27;
  --bg-elevated: #1a2030;
  --bg-input: #0f141c;
  --border: #1e2738;
  --border-focus: #c9a44c;
  --border-subtle: #161d2a;
  --gold: #c9a44c;
  --gold-dim: #a17e32;
  --gold-glow: rgba(201, 164, 76, 0.15);
  --gold-bright: #e4c76b;
  --text-primary: #e8e6e1;
  --text-secondary: #8a8d95;
  --text-muted: #555964;
  --text-on-gold: #0c1017;
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.08);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.08);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.08);
  --chart-blue: #6b8cce;
  --chart-blue-light: #94aede;
  --chart-dark: #3d5a8a;
  --chart-red: #8b3a3a;
  --chart-purple: #7a6b9a;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.3), 0 4px 20px rgba(0,0,0,0.2);
  --shadow-elevated: 0 8px 40px rgba(0,0,0,0.4);
  --font-ui: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition-fast: 150ms ease;
  --transition-med: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: 62.5%;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-ui);
  font-size: 1.4rem;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-deep);
  min-height: 100vh;
  overflow-x: hidden;
}

.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 200px;
}

header {
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-deep) 100%);
  border-bottom: 1px solid var(--border);
  padding: 2.4rem 3.2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(20px);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.6rem;
}

.logo-mark {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}

.logo-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.subtitle {
  font-size: 1.3rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 0.1rem;
}

.app-layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 2.4rem 3.2rem;
  display: grid;
  grid-template-columns: 1fr 440px;
  gap: 2.4rem;
  align-items: start;
}

.inputs-column {
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}

.results-column { position: relative; }

.results-sticky {
  position: sticky;
  top: 90px;
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 1.2rem 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.step-dot {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 1.2rem;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.step-dot:hover { background: var(--bg-elevated); }

.step-num {
  width: 2.8rem;
  height: 2.8rem;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all var(--transition-med);
  flex-shrink: 0;
}

.step-dot.active .step-num {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--text-on-gold);
}

.step-dot.completed .step-num {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.step-label {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: color var(--transition-fast);
  white-space: nowrap;
}

.step-dot.active .step-label { color: var(--gold); }
.step-dot.completed .step-label { color: var(--success); }

.step-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  min-width: 1.6rem;
  transition: background var(--transition-med);
}

.step-line.active { background: var(--gold-dim); }

.steps-container { position: relative; min-height: 420px; }

.step-panel {
  display: none;
  animation: stepFadeIn 0.35s ease both;
}

.step-panel.active { display: block; }

@keyframes stepFadeIn {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

.step-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 0;
}

.step-indicator {
  font-size: 1.2rem;
  color: var(--text-muted);
  font-weight: 500;
}

.btn {
  padding: 1rem 2.4rem;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 1.3rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--gold);
  color: var(--text-on-gold);
}

.btn-primary:hover:not(:disabled) {
  background: var(--gold-bright);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.card-header {
  padding: 1.6rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.card-header h2 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.section-total {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--gold);
  background: var(--gold-glow);
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-sm);
}

.card-body {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.field label {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.field input,
.field select {
  width: 100%;
  padding: 1rem 1.2rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 500;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.field input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--gold-glow);
  background: var(--bg-elevated);
}

.field input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.field input.computed-field {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-style: dashed;
  cursor: default;
}

.field input.computed-field:not([readonly]) {
  cursor: text;
  border-style: solid;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}

.linked-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: help;
  font-style: italic;
  flex-shrink: 0;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.info-icon:hover {
  color: var(--gold);
  border-color: var(--gold-dim);
}

.tooltip {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.2rem;
  font-size: 1.2rem;
  color: var(--text-secondary);
  max-width: 280px;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  box-shadow: var(--shadow-elevated);
  line-height: 1.4;
}

.tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.radio-group {
  display: flex;
  gap: 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}

.radio-label {
  flex: 1;
  padding: 0.8rem 1rem;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--bg-input);
  border-right: 1px solid var(--border);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.radio-label:last-child { border-right: none; }
.radio-label:hover { color: var(--text-secondary); background: var(--bg-elevated); }

.radio-label.active {
  background: var(--gold-glow);
  color: var(--gold);
  font-weight: 600;
}

.radio-label input { display: none; }

.results-card {
  border-color: var(--gold-dim);
  background: linear-gradient(135deg, var(--bg-card) 0%, #15192480 100%);
}

.results-header { cursor: default; border-bottom-color: rgba(201, 164, 76, 0.15); }

.results-header h2 {
  color: var(--gold);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.result-table { display: flex; flex-direction: column; }

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition-fast);
}

.result-row:last-child { border-bottom: none; }
.result-row.highlight-row { background: rgba(201, 164, 76, 0.04); }

.result-label {
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.result-value {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: color var(--transition-fast);
}

.result-value.positive { color: var(--success); }
.result-value.negative { color: var(--danger); }

.viability-badge {
  margin-top: 1.2rem;
  padding: 1.4rem 1.6rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 1.2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: all var(--transition-med);
}

.viability-badge.viavel { background: var(--success-bg); border-color: rgba(52, 211, 153, 0.3); }
.viability-badge.atencao { background: var(--warning-bg); border-color: rgba(251, 191, 36, 0.3); }
.viability-badge.inviavel { background: var(--danger-bg); border-color: rgba(248, 113, 113, 0.3); }

.badge-icon { font-size: 2.2rem; line-height: 1; flex-shrink: 0; }

.badge-text { font-size: 1.3rem; font-weight: 600; color: var(--text-secondary); }

.viability-badge.viavel .badge-text { color: var(--success); }
.viability-badge.atencao .badge-text { color: var(--warning); }
.viability-badge.inviavel .badge-text { color: var(--danger); }

.card-gap-top { margin-top: 1.6rem; }

.chart-card .card-header { cursor: default; }

.chart-body { padding: 1.6rem; height: 320px; }
.chart-body canvas { width: 100% !important; height: 100% !important; }

footer {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
  font-size: 1.2rem;
  border-top: 1px solid var(--border-subtle);
  margin-top: 2rem;
}

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 0.3; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.results-card { animation: fadeIn 0.5s ease 0.1s both; }
.chart-card { animation: fadeIn 0.5s ease 0.2s both; }

@media (max-width: 1200px) {
  .app-layout {
    grid-template-columns: 1fr 380px;
    padding: 2rem;
    gap: 2rem;
  }

  .results-sticky { top: 80px; }

  .step-dot { padding: 0.6rem 0.8rem; }
  .step-label { font-size: 1.1rem; }
}

@media (max-width: 1024px) {
  .app-layout {
    grid-template-columns: 1fr;
    padding: 1.6rem;
    gap: 1.6rem;
  }

  .results-sticky { position: static; }

  .results-column { order: 2; }
  .inputs-column { order: 1; }

  header {
    position: sticky;
    padding: 1.8rem 1.6rem;
  }

  .stepper { padding: 1rem 1.4rem; }
  .step-dot { padding: 0.6rem 1rem; }
}

@media (max-width: 768px) {
  header {
    padding: 1.4rem 1.2rem;
  }

  header h1 { font-size: 1.7rem; }
  .subtitle { font-size: 1.15rem; }

  .logo-mark { width: 38px; height: 38px; }

  .app-layout {
    padding: 1.2rem;
    gap: 1.2rem;
  }

  .stepper {
    padding: 0.8rem 1rem;
    gap: 0;
  }

  .step-dot {
    padding: 0.6rem 0.8rem;
    gap: 0.5rem;
  }

  .step-label { font-size: 1rem; }

  .step-num {
    width: 2.4rem;
    height: 2.4rem;
    font-size: 1.1rem;
  }

  .step-line { min-width: 1rem; }

  .card-header { padding: 1.3rem 1.4rem; }
  .card-header h2 { font-size: 1.4rem; }
  .card-body { padding: 1.4rem; gap: 1.2rem; }

  .field input,
  .field select {
    padding: 1.2rem 1.2rem;
    font-size: 1.6rem;
    min-height: 48px;
  }

  .field label { font-size: 1.2rem; }

  .btn {
    padding: 1.2rem 2rem;
    font-size: 1.4rem;
    min-height: 48px;
  }

  .step-nav {
    padding: 1rem 0;
    position: sticky;
    bottom: 0;
    background: var(--bg-deep);
    z-index: 50;
    margin: 0 -1.2rem;
    padding: 1.2rem;
    border-top: 1px solid var(--border);
  }

  .result-row { padding: 1rem 1.2rem; }
  .result-label { font-size: 1.2rem; }
  .result-value { font-size: 1.35rem; }

  .results-header h2 { font-size: 1.5rem; }

  .viability-badge {
    padding: 1.2rem;
    gap: 1rem;
  }

  .badge-icon { font-size: 1.8rem; }
  .badge-text { font-size: 1.2rem; }

  .steps-container { min-height: auto; }

  .chart-body { height: 280px; padding: 1.2rem; }

  .section-total { font-size: 1.15rem; padding: 0.2rem 0.6rem; }

  .radio-label {
    padding: 1rem 0.8rem;
    font-size: 1.15rem;
    min-height: 44px;
  }

  .tooltip { max-width: 240px; font-size: 1.15rem; }

  footer { padding: 2rem 1.2rem; font-size: 1.1rem; }
}

@media (max-width: 520px) {
  header h1 { font-size: 1.5rem; }
  .subtitle { font-size: 1.05rem; }
  .logo-mark { width: 34px; height: 34px; }
  .header-inner { gap: 1.2rem; }

  .app-layout { padding: 1rem; gap: 1rem; }

  .stepper { padding: 0.6rem 0.6rem; }

  .step-dot {
    padding: 0.5rem 0.5rem;
    gap: 0;
  }

  .step-label { display: none; }

  .step-num {
    width: 3.2rem;
    height: 3.2rem;
    font-size: 1.3rem;
  }

  .step-line { min-width: 0.6rem; }

  .field-row,
  .linked-row {
    grid-template-columns: 1fr;
    gap: 1.2rem;
  }

  .radio-group { flex-direction: column; }
  .radio-label {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .radio-label:last-child { border-bottom: none; }

  .card-header { padding: 1.2rem; }
  .card-header h2 { font-size: 1.35rem; gap: 0.4rem; }
  .card-body { padding: 1.2rem; gap: 1.2rem; }

  .field input,
  .field select {
    padding: 1.4rem 1.2rem;
    font-size: 1.6rem;
    min-height: 52px;
    border-radius: var(--radius-md);
  }

  .step-nav {
    margin: 0 -1rem;
    padding: 1rem;
  }

  .chart-body { height: 240px; padding: 0.8rem; }

  .result-row { padding: 0.9rem 1rem; }

  .info-icon {
    width: 1.8rem;
    height: 1.8rem;
    font-size: 1.05rem;
  }
}

@media (max-width: 380px) {
  html { font-size: 56%; }

  header { padding: 1.2rem 1rem; }
  header h1 { font-size: 1.45rem; }

  .app-layout { padding: 0.8rem; gap: 0.8rem; }

  .card { border-radius: var(--radius-md); }

  .field input,
  .field select {
    font-size: 1.6rem;
    min-height: 52px;
  }

  .btn {
    padding: 1.2rem 1.6rem;
    min-height: 52px;
    font-size: 1.4rem;
    flex: 1;
  }

  .step-nav { gap: 0.8rem; }
  .step-indicator { font-size: 1.1rem; }

  .chart-body { height: 220px; }
}

@media (hover: none) and (pointer: coarse) {
  .field input,
  .field select {
    min-height: 48px;
    font-size: 1.6rem;
  }

  .btn { min-height: 48px; }
  .radio-label { min-height: 48px; }

  .info-icon {
    width: 2rem;
    height: 2rem;
    font-size: 1.1rem;
  }

  .step-dot { padding: 0.8rem; }

  .step-num {
    width: 3rem;
    height: 3rem;
  }
}
