/* =============================================================
   1. Tokens — suite cripto de Kalcula (portfolio, impuestos,
   precio medio, movimientos). Mismo acento en las 4 páginas: es
   una sola suite con navegación interna, no 4 sitios distintos.
   ============================================================= */
:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --text: #1a1d1f;
  --text-muted: #5b6166;
  --border: #e4e1da;
  --accent: #ca8a04;
  --accent-contrast: #1f1503;
  --gain: #2f8f4e;
  --loss: #c0392b;
  --warn-bg: #fff8e6;
  --warn-text: #7a5b00;
  --radius: 14px;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --display: "Manrope", var(--sans);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --surface: #1b2124;
    --text: #eef1f0;
    --text-muted: #a3aaad;
    --border: #2c3336;
    --accent: #eab308;
    --accent-contrast: #1f1503;
    --gain: #4cb571;
    --loss: #e05c4d;
    --warn-bg: #2a2210;
    --warn-text: #f0d27a;
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
p { text-wrap: pretty; }
h1, h2, h3 { text-wrap: balance; line-height: 1.1; font-family: var(--display); letter-spacing: -0.01em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--border); padding: .1em .35em; border-radius: 5px; font-size: .9em; }
::selection { background: var(--accent); color: var(--accent-contrast); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
input, select { accent-color: var(--accent); }

/* =============================================================
   3. Utilities
   ============================================================= */
.container { width: 100%; max-width: 780px; margin-inline: auto; padding-inline: 1.25rem; }
.muted { color: var(--text-muted); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .6rem 1rem; background: var(--surface); color: var(--text);
  z-index: 9999; border-radius: 8px; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.skip-link:focus { top: 1rem; }

/* =============================================================
   4. Header / Footer
   ============================================================= */
.site-header { border-bottom: 1px solid var(--border); }
.header-row { display: flex; align-items: center; justify-content: space-between; padding-block: 1rem; }
.logo { font-family: var(--display); font-weight: 800; font-size: 1.15rem; color: var(--accent); }
.header-row nav a { font-size: .9rem; font-weight: 600; }

.site-footer { border-top: 1px solid var(--border); margin-top: 3rem; padding-block: 1.5rem; }
.footer-row { display: flex; flex-wrap: wrap; gap: .75rem 1.5rem; align-items: center; justify-content: space-between; color: var(--text-muted); font-size: .875rem; }
.footer-row nav { display: flex; gap: 1rem; }

/* =============================================================
   5. Hero + subnav de la suite cripto
   ============================================================= */
.hero { padding-block: 2.25rem 1rem; text-align: center; }
.hero h1 { font-size: clamp(1.7rem, 4.4vw, 2.5rem); max-width: 26ch; margin-inline: auto; }
.hero-sub { color: var(--text-muted); max-width: 52ch; margin: .75rem auto 1.5rem; font-size: 1.02rem; }

.cripto-subnav {
  display: flex; gap: .35rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: .3rem; margin: 0 auto 1.5rem; max-width: 620px;
}
.cripto-subnav a {
  flex: 1 1 auto; text-align: center; padding: .55rem .6rem; border-radius: 8px;
  font-size: .85rem; font-weight: 600; color: var(--text-muted);
  transition: background .15s var(--ease-out), color .15s var(--ease-out);
}
.cripto-subnav a:hover { text-decoration: none; background: var(--bg); }
.cripto-subnav a[aria-current="page"] { background: var(--accent); color: var(--accent-contrast); }

/* =============================================================
   6. Tool card, campos, tabs de tipo
   ============================================================= */
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: left;
  box-shadow: 0 1px 3px rgba(0,0,0,.04), 0 12px 32px -16px rgba(0,0,0,.12);
}
.tool-card + .tool-card { margin-top: 1.5rem; }

.section-title { font-size: 1.05rem; margin: 0 0 .9rem; }

.mode-tabs { display: flex; gap: .4rem; margin-bottom: 1.1rem; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: .25rem; }
.mode-tabs button {
  flex: 1 1 0; padding: .55rem .5rem; border-radius: 8px; font-weight: 600; font-size: .85rem;
  color: var(--text-muted); transition: background .15s var(--ease-out), color .15s var(--ease-out);
}
.mode-tabs button.is-active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .9rem; }
.field-row { display: flex; gap: .75rem; margin-bottom: .9rem; }
.field-row .field { flex: 1 1 0; min-width: 0; margin-bottom: 0; }
.field-narrow { flex: 0 1 45%; }
.field label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  font: inherit; font-size: 1rem; padding: .65rem .75rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field-hint { font-size: .78rem; color: var(--text-muted); margin-top: -.4rem; margin-bottom: .9rem; }

.btn-primary {
  width: 100%; margin-top: .4rem;
  background: var(--accent); color: var(--accent-contrast);
  font-weight: 700; font-size: 1.02rem;
  padding: .85rem 1rem; border-radius: 10px;
  transition: transform .2s var(--ease-out), filter .2s var(--ease-out);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: scale(.98); }
.btn-primary.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

.btn-text { font-weight: 600; color: var(--accent); font-size: .9rem; }
.btn-text.btn-danger { color: var(--loss); }

.tool-error { display: none; color: var(--loss); font-weight: 600; margin-top: .75rem; }
.tool-error.is-visible { display: block; }

/* =============================================================
   7. Filas dinámicas (compras/ventas)
   ============================================================= */
.filas-header, .op-row {
  display: grid; grid-template-columns: 1fr 1fr 1.2fr auto; gap: .5rem; align-items: center;
}
.filas-header {
  font-size: .78rem; font-weight: 600; color: var(--text-muted); padding-inline: .1rem;
  margin-bottom: .4rem;
}
.op-row { margin-bottom: .5rem; }
.op-row input, .op-row select {
  font: inherit; font-size: .92rem; padding: .6rem .6rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); width: 100%; min-width: 0;
}
.op-row input:focus, .op-row select:focus { border-color: var(--accent); }
.btn-remove-row {
  width: 32px; height: 32px; border-radius: 8px; font-size: 1.1rem; line-height: 1;
  color: var(--text-muted); background: var(--bg); border: 1px solid var(--border);
  transition: color .15s var(--ease-out), border-color .15s var(--ease-out);
}
.btn-remove-row:hover { color: var(--loss); border-color: var(--loss); }

/* =============================================================
   8. Tablas (movimientos, posiciones, detalle FIFO)
   ============================================================= */
.chart-title { font-size: 1rem; margin: 1.5rem 0 .75rem; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; margin-bottom: .5rem; }
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; white-space: nowrap; }
.data-table th, .data-table td { padding: .55rem .7rem; text-align: right; }
.data-table th:first-child, .data-table td:first-child,
.data-table th:nth-child(2), .data-table td:nth-child(2) { text-align: left; }
.data-table thead th { background: var(--bg); color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.data-table tbody tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
.data-table .row-actions { display: flex; gap: .4rem; justify-content: flex-end; }
.data-table .row-actions button { font-size: .78rem; font-weight: 600; color: var(--accent); }
.data-table .row-actions button.btn-danger { color: var(--loss); }
.gain-positive { color: var(--gain); }
.gain-negative { color: var(--loss); }

/* =============================================================
   9. Resultado / resumen
   ============================================================= */
.result-headline { display: flex; flex-direction: column; gap: .15rem; margin-bottom: 1rem; }
.result-label { font-size: .85rem; color: var(--text-muted); font-weight: 600; }
.result-value { font-family: var(--display); font-size: 2.1rem; font-weight: 800; color: var(--accent); }

.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1rem; margin-bottom: 1.5rem; }
.result-grid > div { display: flex; flex-direction: column; gap: .15rem; }
.result-grid dt { font-size: .78rem; color: var(--text-muted); }
.result-grid dd { font-weight: 700; font-size: 1.05rem; }

.loss-note, .warn-note {
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: 10px; padding: .75rem 1rem; font-size: .88rem;
  margin-bottom: 1rem; line-height: 1.5;
}

/* =============================================================
   10. Gráfico canvas (barras horizontales, portfolio)
   ============================================================= */
.bar-chart-wrap { margin-top: .5rem; }
canvas[data-bar-chart] { width: 100%; height: auto; display: block; }

/* =============================================================
   11. Empty state / CTA a movimientos
   ============================================================= */
.empty-state {
  text-align: center; padding: 2rem 1.25rem;
  color: var(--text-muted); font-size: .95rem;
  background: var(--bg); border: 1px dashed var(--border); border-radius: 10px;
}
.empty-state .btn-primary { width: auto; display: inline-block; margin-top: 1rem; padding-inline: 1.5rem; }

/* =============================================================
   12. Backup (exportar / importar)
   ============================================================= */
.backup-row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }
.backup-row input[type="file"] { display: none; }

/* =============================================================
   13. Misc
   ============================================================= */
.privacy-badge { margin-top: 1.25rem; font-size: .85rem; color: var(--text-muted); text-align: center; }
.limits-note { margin-top: .4rem; font-size: .78rem; color: var(--text-muted); text-align: center; }
.js-off-note { padding: 1rem 1.25rem; background: #fff3cd; color: #664d03; border-radius: 10px; margin: 1rem auto; }

.ad-slot {
  min-height: 90px; margin-block: 2rem;
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--border); border-radius: 10px;
  color: var(--text-muted); font-size: .8rem; letter-spacing: .04em; text-transform: uppercase;
}

.content-block { padding-block: 1.75rem; }
.content-block h2 { font-size: 1.35rem; margin-bottom: .75rem; }
.content-block p { margin-bottom: 1rem; color: var(--text); }
.content-block + .content-block { border-top: 1px solid var(--border); }

.steps { padding-left: 1.2rem; display: flex; flex-direction: column; gap: .6rem; }

.faq-list { display: flex; flex-direction: column; gap: .5rem; }
.faq-item { border: 1px solid var(--border); border-radius: 10px; padding: .2rem .9rem; background: var(--surface); }
.faq-item summary { cursor: pointer; font-weight: 600; padding-block: .75rem; }
.faq-item p { color: var(--text-muted); padding-bottom: .85rem; margin: 0; }

.tools-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.tools-list a { font-weight: 600; color: var(--accent); }

/* =============================================================
   14. Responsive
   ============================================================= */
@media (min-width: 720px) {
  .hero { padding-block: 3.5rem 1.5rem; }
}
@media (max-width: 559px) {
  .filas-header { display: none; }
  .op-row { grid-template-columns: 1fr 1fr; row-gap: .4rem; }
  .op-row input.input-precio, .op-row select.input-tipo { grid-column: 1 / 2; }
  .op-row .btn-remove-row { grid-column: 2 / 3; justify-self: end; }
  .data-table { font-size: .78rem; }
}

/* =============================================================
   15. Reduced motion
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  .btn-primary { transition: none; }
}
