/* ── tokens ─────────────────────────────────────────────────────── */
:root {
  --bg:            #08090b;
  --panel:         #0f1013;
  --panel-2:       #14161b;
  --border:        #1e2028;
  --border-strong: #2a2d38;
  --accent:        #c8ff3a;
  --accent-hover:  #d4ff5a;
  --accent-ink:    #080a04;
  --ink:           #f0ede8;
  --ink-dim:       #7b7a74;
  --ink-faint:     #3e3d3a;
  --warn:          #f5c842;
  --danger:        #ff7a6b;
  --radius:        10px;
  --radius-sm:     6px;
  --radius-md:     8px;
  --radius-lg:     14px;
  --radius-xl:     16px;
  --radius-pill:   99px;
  --font: 'Plus Jakarta Sans', system-ui, sans-serif;
}

/* ── keyframes ───────────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) scale(0.97) } to { opacity: 1; transform: translateY(0) scale(1) } }
@keyframes screenIn{ from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }

/* ── reset / base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  margin: 0;
  padding: 0;
  min-height: 100%;
}

input, textarea, button, select { font-family: var(--font); }

::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

/* ── layout raiz ─────────────────────────────────────────────────── */
body {
  position: relative;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 60% 50% at 50% 0%, rgba(200,255,58,0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── header ──────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.header-inner {
  display: flex;
  align-items: baseline;
  gap: 14px;
  max-width: 1200px;
  margin: 0 auto;
}

.logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--ink);
  line-height: 1;
}

.accent-dot { color: var(--accent); }

.header-sub {
  font-size: 12px;
  color: var(--ink-faint);
  font-weight: 400;
}

/* ── main ────────────────────────────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── section label ───────────────────────────────────────────────── */
.section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  text-transform: uppercase;
  margin-bottom: 16px;
}

/* ── global section ──────────────────────────────────────────────── */
.global-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}

.global-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* ── field group ─────────────────────────────────────────────────── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  text-transform: uppercase;
  display: block;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ── inputs ──────────────────────────────────────────────────────── */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-affix {
  font-size: 13px;
  color: var(--ink-dim);
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  position: absolute;
}

.prefix-wrap .input-affix { left: 13px; }
.prefix-wrap input         { padding-left: 36px !important; }
.suffix-wrap .input-affix  { right: 13px; }
.suffix-wrap input         { padding-right: 52px !important; }

input[type="number"],
input[type="text"],
select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--ink);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  caret-color: var(--accent);
  -webkit-appearance: none;
  appearance: none;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

input::placeholder { color: var(--ink-faint); font-style: normal; }

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200,255,58,0.08);
}

select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237b7a74' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  background-color: var(--bg);
  padding-right: 36px;
}

select option {
  background: var(--panel-2);
  color: var(--ink);
}

/* ── period field com toggle ─────────────────────────────────────── */
.period-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.period-field input {
  flex: 1;
  min-width: 0;
}

.unit-toggle {
  display: flex;
  flex-shrink: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}

.unit-btn {
  background: none;
  border: none;
  border-radius: var(--radius-pill);
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  cursor: pointer;
  font-family: var(--font);
  line-height: 1;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}

.unit-btn:hover { color: var(--ink-dim); }

.unit-btn.active {
  background: var(--border-strong);
  color: var(--ink);
}

/* ── ir hint ─────────────────────────────────────────────────────── */
.ir-hint {
  font-size: 12px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 18px;
}

.ir-hint .aliq {
  font-weight: 700;
  font-size: 13px;
}

.ir-hint .aliq.aliq-danger { color: var(--danger); }
.ir-hint .aliq.aliq-warn   { color: var(--warn); }
.ir-hint .aliq.aliq-dim    { color: var(--ink-dim); }
.ir-hint .aliq.aliq-accent { color: var(--accent); }
.ir-hint .aliq.aliq-exempt { color: var(--accent); }

/* ── investment panels ───────────────────────────────────────────── */
.investments-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.investment-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.investment-panel.winner {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(200,255,58,0.3), 0 0 32px rgba(200,255,58,0.04);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.panel-index {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  text-transform: uppercase;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.name-input {
  background: none !important;
  border: none !important;
  border-bottom: 1px solid transparent !important;
  border-radius: 0 !important;
  padding: 0 !important;
  font-size: 16px !important;
  font-weight: 600 !important;
  color: var(--ink) !important;
  box-shadow: none !important;
  outline: none !important;
  width: 100%;
  transition: border-color 0.15s !important;
}

.name-input:focus {
  border-bottom-color: var(--accent) !important;
  box-shadow: none !important;
}

.panel-fields {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── panel results ───────────────────────────────────────────────── */
.panel-results {
  border-top: 1px solid var(--border);
  padding: 20px;
  animation: screenIn 0.3s ease;
}

.panel-results.hidden { display: none; }

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.metric-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.metric-card.span-2 {
  grid-column: 1 / -1;
}

.metric-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  text-transform: uppercase;
  margin-bottom: 5px;
}

.metric-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.metric-value.big    { font-size: 26px; }
.metric-value.accent { color: var(--accent); }
.metric-value.warn   { color: var(--warn); }
.metric-value.danger { color: var(--danger); opacity: 0.85; }
.metric-value.dim    { color: var(--ink-dim); font-weight: 500; font-size: 15px; }

/* ── history toggle ──────────────────────────────────────────────── */
.history-toggle {
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--ink-dim);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  justify-content: center;
}

.history-toggle:hover {
  border-color: var(--ink-dim);
  color: var(--ink);
}

.history-toggle svg {
  transition: transform 0.15s;
  flex-shrink: 0;
}

.history-toggle.open svg { transform: rotate(180deg); }

/* ── history table ───────────────────────────────────────────────── */
.history-wrap {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
}

.history-wrap.hidden { display: none; }

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 420px;
}

.history-table thead th {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  text-transform: uppercase;
  text-align: right;
  padding: 9px 10px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.history-table thead th:first-child { text-align: left; }

.history-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.history-table tbody tr:last-child { border-bottom: none; }
.history-table tbody tr:hover      { background: #181a20; }

.history-table tbody td {
  padding: 8px 10px;
  text-align: right;
  color: var(--ink-dim);
  white-space: nowrap;
}

.history-table tbody td:first-child {
  text-align: left;
  color: var(--ink-faint);
  font-weight: 600;
}

.td-final  { color: var(--ink) !important; font-weight: 600 !important; }
.td-ir     { color: var(--danger) !important; opacity: 0.75; }
.td-exempt { color: var(--ink-faint) !important; }
.td-partial{
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--warn) !important;
  text-transform: uppercase;
  vertical-align: middle;
  padding-left: 6px !important;
}

/* ── calcular button ─────────────────────────────────────────────── */
.calc-row {
  display: flex;
  justify-content: center;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius);
  padding: 14px 56px;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font);
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
}

.btn-primary:hover  { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }

/* ── IR reference table ──────────────────────────────────────────── */
.ir-table-details {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.ir-table-summary {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  text-transform: uppercase;
  padding: 14px 20px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: color 0.12s;
  user-select: none;
}

.ir-table-summary:hover { color: var(--ink-dim); }
.ir-table-summary::-webkit-details-marker { display: none; }
.ir-table-summary::before {
  content: '';
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%233e3d3a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  transition: transform 0.15s;
  flex-shrink: 0;
}

details[open] .ir-table-summary::before { transform: rotate(180deg); }

.ir-table-body {
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ir-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.ir-range { color: var(--ink-dim); }

.ir-rate {
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.ir-rate.danger { color: var(--danger); }
.ir-rate.warn   { color: var(--warn); }
.ir-rate.dim    { color: var(--ink-dim); }
.ir-rate.accent { color: var(--accent); }

/* ── comparison section ──────────────────────────────────────────── */
.comparison-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  animation: screenIn 0.35s ease;
}

.comparison-section.hidden { display: none; }

.comparison-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.comparison-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.winner-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(200,255,58,0.08);
  border: 1px solid rgba(200,255,58,0.25);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

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

.comparison-table thead th {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  text-transform: uppercase;
  text-align: right;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

.comparison-table thead th:first-child { text-align: left; }

.comparison-table tbody tr { border-bottom: 1px solid var(--border); }
.comparison-table tbody tr:last-child { border-bottom: none; }

.comparison-table tbody td {
  padding: 12px 16px;
  text-align: right;
  color: var(--ink-dim);
  font-size: 14px;
}

.comparison-table tbody td:first-child {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.td-winner   { color: var(--ink) !important; font-weight: 700 !important; }
.td-pos      { color: var(--accent) !important; font-weight: 700 !important; }
.td-neg      { color: var(--danger) !important; opacity: 0.75; }
.td-ir-lower { color: var(--accent) !important; font-weight: 700 !important; }
.td-ir-higher{ color: var(--danger) !important; opacity: 0.75; }

/* ── spread field (tesouro selic) ────────────────────────────────── */
.spread-field { display: none; }
.spread-field.visible { display: flex; }

/* ── responsive ──────────────────────────────────────────────────── */
@media (max-width: 800px) {
  main { padding: 20px 16px; }
  header { padding: 14px 20px; }
  .global-grid { grid-template-columns: 1fr; }
  .investments-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .comparison-header { flex-direction: column; }
  .comparison-section { padding: 16px; }
  .winner-badge { white-space: normal; }
  .two-col { grid-template-columns: 1fr; }

  /* tabela comparativa: layout em cards no mobile */
  .comparison-table { display: block; }
  .comparison-table thead { display: none; }
  .comparison-table tbody { display: block; }
  .comparison-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
    gap: 4px 10px;
  }
  .comparison-table tbody tr:last-child { border-bottom: none; }
  .comparison-table tbody td {
    padding: 0;
    font-size: 13px;
  }
  .comparison-table tbody td:first-child {
    grid-column: 1 / -1;
    padding: 0 0 4px;
    font-size: 10px;
    text-align: left;
  }
  .comparison-table tbody td:nth-child(2),
  .comparison-table tbody td:nth-child(3) {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    text-align: center;
  }
  .comparison-table tbody td:nth-child(2)::before {
    content: "A";
    display: block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    text-transform: uppercase;
    margin-bottom: 3px;
  }
  .comparison-table tbody td:nth-child(3)::before {
    content: "B";
    display: block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    text-transform: uppercase;
    margin-bottom: 3px;
  }
}
