:root {
  --bg: #07142a;
  --bg-2: #0a1c38;
  --panel: #0f2647;
  --panel-2: #123057;
  --border: #1d3b66;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --text: #eaf1fb;
  --muted: #93a9cc;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(2, 10, 25, 0.55);
}

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

body {
  font-family: "Inter", system-ui, sans-serif;
  background: radial-gradient(1200px 700px at 80% -10%, #103163 0%, var(--bg) 55%) fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.bg-grid {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(59,130,246,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,130,246,0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(800px 500px at 70% 0%, #000 0%, transparent 80%);
}

/* ---------- Header ---------- */
.site-header {
  position: relative; z-index: 1;
  max-width: 1180px; margin: 0 auto; padding: 38px 24px 10px;
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 13px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px; letter-spacing: 0.5px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
}
.brand-text h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.brand-text h1 span { color: var(--accent); }
.byline { color: var(--muted); font-size: 14px; font-weight: 500; }
.tagline { margin-top: 16px; color: var(--muted); font-size: 16px; max-width: 640px; }

/* ---------- Layout ---------- */
.layout {
  position: relative; z-index: 1;
  max-width: 1180px; margin: 0 auto; padding: 22px 24px 40px;
  display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 22px;
  align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.results { position: sticky; top: 18px; }
@media (max-width: 900px) { .results { position: static; } }

/* ---------- Segmented ---------- */
.seg-group { margin-bottom: 18px; }
.seg-label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 7px; font-weight: 600; }
.segmented {
  display: flex; background: var(--bg); border: 1px solid var(--border);
  border-radius: 11px; padding: 4px; gap: 4px;
}
.seg {
  flex: 1; padding: 10px 12px; border: none; cursor: pointer;
  background: transparent; color: var(--muted); font-weight: 600; font-size: 14px;
  border-radius: 8px; font-family: inherit; transition: all .18s ease;
}
.seg:hover { color: var(--text); }
.seg.active {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff; box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

/* ---------- Fields ---------- */
.field-block { border: none; margin-top: 8px; padding: 14px 0 4px; border-top: 1px solid var(--border); }
.field-block legend { font-size: 13px; font-weight: 700; color: var(--text); padding-bottom: 10px; letter-spacing: 0.2px; }
.field-block.highlight { border-top: 1px solid var(--accent); }
.field-block.highlight legend { color: var(--accent); }
.field-hint { font-size: 12px; color: var(--muted); margin: -2px 0 12px; line-height: 1.4; }
.field-hint strong { color: var(--text); font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
/* Reserva la misma altura para las 3 etiquetas → las cajas quedan alineadas */
.grid-3 .field > span:first-child { min-height: 3em; }
@media (max-width: 480px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-3 .field > span:first-child { min-height: 0; }
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--muted); font-weight: 500; }
.field span i { color: #5c7299; font-style: normal; font-size: 11px; }
.field input, .field select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 11px 12px; font-size: 15px; font-family: inherit;
  font-weight: 600; outline: none; transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field select { cursor: pointer; }

.tc-live { display: flex; align-items: center; gap: 7px; font-size: 11px !important; color: var(--muted) !important; margin-top: 2px; }
.tc-live #tcRefresh {
  background: var(--bg); border: 1px solid var(--border); color: var(--accent);
  width: 22px; height: 22px; border-radius: 6px; cursor: pointer; font-size: 13px;
  line-height: 1; padding: 0; flex-shrink: 0; transition: transform .3s, background .15s;
}
.tc-live #tcRefresh:hover { background: var(--accent-soft); }
.tc-live #tcRefresh.spin { transform: rotate(360deg); }
.tc-live.ok #tcLiveText { color: var(--green); }
.tc-live.err #tcLiveText { color: var(--amber); }
.tc-live .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-right: 3px; animation: pulse-dot 2s infinite; }
@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------- Results ---------- */
.result-hero {
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  background: var(--accent-soft); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
}
.hero-label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.hero-value { display: block; font-size: 34px; font-weight: 800; letter-spacing: -1px; margin-top: 4px; }
.hero-sub { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }

.gauge {
  width: 116px; height: 116px; border-radius: 50%;
  display: grid; place-items: center; text-align: center;
  background: conic-gradient(var(--green) 0deg, var(--green) 0deg, var(--bg) 0deg);
  transition: background .4s ease;
}
.gauge::before {
  content: ""; position: absolute; width: 92px; height: 92px; border-radius: 50%; background: var(--bg-2);
}
.gauge-value, .gauge-label { position: relative; z-index: 1; }
.gauge-value { font-size: 24px; font-weight: 800; }
.gauge-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.kpi { background: var(--bg); border: 1px solid var(--border); border-radius: 11px; padding: 14px; }
.kpi-label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { display: block; font-size: 19px; font-weight: 700; margin-top: 5px; }

.breakeven { margin-top: 18px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.breakeven h3 { font-size: 14px; font-weight: 700; margin-bottom: 12px; }
.be-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.be { background: var(--panel-2); border-radius: 9px; padding: 12px; }
.be-label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.be-value { display: block; font-size: 22px; font-weight: 800; margin-top: 4px; color: var(--accent); }
.be-hint { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.desglose { margin-top: 16px; border: 1px solid var(--border); border-radius: 11px; overflow: hidden; }
.desglose summary { cursor: pointer; padding: 13px 16px; font-weight: 700; font-size: 14px; background: var(--bg); user-select: none; }
.desglose table { width: 100%; border-collapse: collapse; }
.desglose td { padding: 10px 16px; font-size: 14px; border-top: 1px solid var(--border); }
.desglose td:last-child { text-align: right; font-weight: 600; }
.desglose tr.total td { font-weight: 800; background: var(--accent-soft); }
.desglose tr.neg td:last-child { color: var(--amber); }

/* ---------- Lead ---------- */
.lead-card { margin-top: 18px; background: linear-gradient(135deg, var(--accent-2) 0%, #1e3a8a 100%); border-radius: 12px; padding: 20px; }
.lead-card h3 { font-size: 17px; font-weight: 800; }
.lead-card > p { font-size: 14px; color: #cfe0ff; margin-top: 4px; }
.lead-form { display: grid; gap: 10px; margin-top: 14px; }
.lead-form input {
  background: rgba(255,255,255,0.96); border: none; border-radius: 9px;
  padding: 12px 14px; font-size: 14px; font-family: inherit; color: #0b1f3a; font-weight: 500; outline: none;
}
.lead-form input:focus { box-shadow: 0 0 0 3px rgba(255,255,255,0.35); }
.lead-form button {
  background: #07142a; color: #fff; border: none; border-radius: 9px;
  padding: 13px; font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit;
  transition: transform .12s, background .15s;
}
.lead-form button:hover { background: #000; transform: translateY(-1px); }
.lead-status { margin-top: 12px; font-weight: 700; font-size: 14px; }
.lead-status.ok { color: #bbf7d0; }
.lead-status.err { color: #fecaca; }
.lead-fineprint { margin-top: 10px; font-size: 11px; color: #aac4ef; }

/* ---------- Footer ---------- */
.site-footer { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; padding: 10px 24px 50px; text-align: center; color: var(--muted); }
.site-footer strong { color: var(--text); }
.disclaimer { font-size: 12px; margin-top: 8px; opacity: 0.8; }

/* visibility helpers toggled by JS */
.ri-only, .mono-only { display: none; }
body[data-fiscal="ri"] .ri-only { display: flex; }
body[data-fiscal="ri"] .kpi.ri-only { display: block; }
body[data-fiscal="mono"] .mono-only { display: flex; }
