/* =============================================================
   CosteMiCoche - estilos. Mobile-first. Sin fuentes externas.
   ============================================================= */

/* 1. Tokens */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f3f5;
  --ink: #14202b;
  --muted: #566573;
  --line: #dde3e8;
  --accent: #0b6e66;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3f1;
  --warn: #8a5a00;
  --warn-bg: #fff6e0;
  --bad: #b3261e;
  --good: #1b7a3a;
  --c-dep: #6d4fc2;
  --c-energy: #0b6e66;
  --c-ins: #2866c9;
  --c-maint: #c47a05;
  --c-fin: #c0392b;
  --c-other: #6b7a88;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 32, 43, .06), 0 4px 16px rgba(20, 32, 43, .05);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: clamp(16px, 4vw, 32px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f161c; --surface: #17212a; --surface-2: #1d2a35; --ink: #e8eef2; --muted: #9fb0bd;
    --line: #2a3945; --accent: #3cc2b4; --accent-ink: #06201d; --accent-soft: #14312f;
    --warn: #f0c36a; --warn-bg: #33290f; --bad: #ff8a80; --good: #6fd68b;
    --c-dep: #a58cf0; --c-energy: #3cc2b4; --c-ins: #6ea2ff; --c-maint: #f0a93a; --c-fin: #ff7d6e; --c-other: #98a8b5;
    --shadow: none;
  }
}

/* 2. Reset */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; font-family: var(--sans); font-size: 16px; line-height: 1.6; color: var(--ink); background: var(--bg); overflow-x: clip; }
img, svg { display: block; max-width: 100%; height: auto; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -.015em; text-wrap: balance; margin: 0 0 .5em; }
p { margin: 0 0 1em; text-wrap: pretty; }
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: fixed; top: -80px; left: 12px; background: var(--ink); color: var(--bg); padding: .5rem 1rem; border-radius: 8px; z-index: 100; }
.skip-link:focus { top: 12px; }

/* 3. Layout */
.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 var(--gutter); }
.narrow { max-width: 760px; }
main { padding-bottom: 48px; }
section { margin: 40px 0; }
h2 { font-size: clamp(1.4rem, 3.6vw, 1.9rem); margin-top: 0; }
h3 { font-size: 1.15rem; }
.lede { font-size: 1.1rem; color: var(--muted); max-width: 60ch; }

/* 4. Cabecera */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: relative; z-index: 20; }
.site-header .container { display: flex; align-items: center; justify-content: space-between; min-height: 60px; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.brand span b { color: var(--accent); }
.menu-btn { display: inline-flex; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px; padding: 8px 12px; }
.nav { display: none; position: absolute; left: 0; right: 0; top: 100%; background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px var(--gutter) 16px; }
.nav[data-open="true"] { display: block; }
.nav a { display: block; padding: 10px 0; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.nav a[aria-current="page"] { color: var(--accent); font-weight: 650; }
@media (min-width: 960px) {
  .menu-btn { display: none; }
  .nav, .nav[data-open] { display: flex; position: static; border: 0; padding: 0; gap: 4px; background: none; flex-wrap: wrap; justify-content: flex-end; }
  .nav a { border: 0; padding: 6px 8px; border-radius: 8px; font-size: .88rem; white-space: nowrap; }
  .nav a:hover { background: var(--surface-2); }
}
.crumbs { font-size: .88rem; color: var(--muted); padding-top: 14px; }
.crumbs a { color: var(--muted); }

/* 5. Hero */
.hero { padding-top: 28px; padding-bottom: 8px; }
.hero h1 { font-size: clamp(1.8rem, 5.5vw, 2.8rem); margin-bottom: .35em; }
.pill { display: inline-flex; gap: 6px; align-items: center; font-size: .85rem; background: var(--accent-soft); color: var(--accent); padding: 4px 12px; border-radius: 99px; margin-bottom: 12px; font-weight: 600; }

/* 6. Herramienta */
.tool { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(14px, 3vw, 28px); }
.tool__grid { display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) {
  .tool__grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; }
  .tool__results { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; padding-right: 4px; }
}
.tool h2 { font-size: 1.25rem; }
.fields { display: grid; gap: 14px 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 540px) { .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.fields--single { grid-template-columns: minmax(0, 1fr); margin-top: 14px; }
.field[hidden], [hidden] { display: none !important; }
.field label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: .92rem; font-weight: 600; margin-bottom: 4px; }
.badge { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.field[data-source="user"] .badge { background: var(--accent-soft); color: var(--accent); }
.field[data-source="preset"] .badge { background: var(--warn-bg); color: var(--warn); }
.field[data-source="estimate"] input { font-style: italic; color: var(--muted); }
.input-wrap { display: flex; align-items: stretch; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-wrap input { flex: 1; min-width: 0; border: 0; padding: 10px 12px; font: inherit; font-size: 1rem; background: transparent; color: var(--ink); }
.input-wrap input:focus { outline: none; }
.unit { padding: 0 12px; display: flex; align-items: center; background: var(--surface-2); color: var(--muted); font-size: .82rem; white-space: nowrap; }
select { width: 100%; padding: 10px 12px; font: inherit; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
input[aria-invalid="true"] { color: var(--bad); }
.field:has([aria-invalid="true"]) .input-wrap { border-color: var(--bad); }
.hint { font-size: .78rem; color: var(--muted); margin: 4px 0 0; }
.err { font-size: .84rem; color: var(--bad); margin: 4px 0 0; font-weight: 600; }
fieldset { border: 0; padding: 0; margin: 16px 0 0; min-width: 0; }
legend { font-weight: 600; font-size: .92rem; padding: 0; margin-bottom: 6px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: 8px 14px; border: 1.5px solid var(--line); border-radius: 99px; font-size: .92rem; background: var(--surface); }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
details.more { margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; }
details.more > summary { cursor: pointer; padding: 12px 0; font-weight: 600; }
details.more[open] { padding-bottom: 14px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; margin-bottom: 12px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.tool-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn { border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); padding: 9px 14px; border-radius: 10px; font-weight: 600; font-size: .9rem; }
.btn:hover { border-color: var(--accent); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.privacy { font-size: .85rem; color: var(--muted); margin: 14px 0 0; }

/* 7. Resultados */
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.card { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.card--hero { grid-column: 1 / -1; background: var(--accent); color: var(--accent-ink); }
.card__label { font-size: .8rem; font-weight: 600; opacity: .85; }
.card__value { font-size: clamp(1.4rem, 5vw, 1.9rem); font-weight: 750; line-height: 1.2; font-variant-numeric: tabular-nums; }
.card--hero .card__value { font-size: clamp(2rem, 8vw, 2.7rem); }
.card__sub { font-size: .78rem; opacity: .8; }
.rh { font-size: 1rem; margin: 18px 0 8px; }
.stack { display: flex; height: 18px; border-radius: 99px; overflow: hidden; background: var(--surface-2); margin-bottom: 10px; }
.stack span { display: block; height: 100%; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl thead th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tbl tbody th { font-weight: 500; }
.tbl .r { text-align: right; white-space: nowrap; }
.tbl .tot th, .tbl .tot td { font-weight: 750; border-top: 2px solid var(--ink); }
.tbl .sep th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.diff.good { color: var(--good); } .diff.bad { color: var(--bad); }
.verdict { font-size: 1.1rem; background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; }
.vsbars { margin: 14px 0; display: grid; gap: 6px; }
.vsbars div { display: flex; align-items: center; gap: 10px; font-size: .85rem; }
.vsbars span { width: 7.5em; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vsbars i { display: block; height: 14px; border-radius: 99px; background: var(--c-energy); }
.vsbars i.b { background: var(--c-ins); }
.note { font-size: .85rem; color: var(--muted); }
.note.est { border-left: 3px solid var(--line); padding-left: 10px; }
.warnings { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 14px 10px 30px; font-size: .88rem; margin: 0 0 12px; }
.result-error { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 14px 16px; }
.result-error ul { margin: 6px 0 0; padding-left: 20px; }
.finbox { background: var(--surface-2); border-radius: 12px; padding: 4px 14px 8px; margin-top: 14px; }
.finbox ul { margin: 0 0 8px; padding-left: 18px; }
.sumbar { display: none; }
@media (max-width: 959px) {
  .sumbar { display: flex; position: sticky; bottom: 0; margin: 14px calc(-1 * clamp(14px, 3vw, 28px)) calc(-1 * clamp(14px, 3vw, 28px)); padding: 10px 16px; gap: 16px; align-items: center; background: var(--accent); color: var(--accent-ink); border-radius: 0 0 var(--radius) var(--radius); justify-content: space-between; font-size: .95rem; z-index: 5; }
  .sumbar a { color: inherit; font-weight: 700; }
}

@media (max-width: 539px) { .hide-sm { display: none; } .tbl th, .tbl td { padding: 7px 4px; } .tbl { font-size: .88rem; } }

/* 8. Compartidos: comparador */
.veh { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--surface); }
.veh h3 { display: flex; align-items: center; gap: 8px; }
.veh__tag { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--c-energy); color: #fff; font-weight: 700; font-size: .85rem; }
.veh--b .veh__tag { background: var(--c-ins); }
.veh-name { width: 100%; margin-bottom: 12px; }
.veh-name input { width: 100%; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 10px; font: inherit; background: var(--surface); color: var(--ink); }
.cmp-forms { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .cmp-forms { grid-template-columns: repeat(2, minmax(0, 1fr)); } .veh .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.shared { border: 1px dashed var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.shared .fields { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.cmp-results { margin-top: 20px; }

/* 9. Contenido */
.prose { max-width: 760px; }
.prose h2 { margin-top: 1.6em; }
.prose h3 { margin-top: 1.3em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin-bottom: .4em; }
.formula { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 12px 16px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; overflow-x: auto; margin: 0 0 1em; }
.grid-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); padding: 0; list-style: none; }
.grid-cards li { margin: 0; }
.link-card { display: block; height: 100%; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--ink); }
.link-card:hover { border-color: var(--accent); }
.link-card strong { display: block; color: var(--accent); margin-bottom: 4px; }
.link-card span { font-size: .9rem; color: var(--muted); }
.expenses dt { font-weight: 700; margin-top: 14px; }
.expenses dd { margin: 2px 0 0; color: var(--ink); }
.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 16px; margin-bottom: 8px; }
.faq summary { cursor: pointer; font-weight: 650; padding: 14px 0; }
.faq details[open] { padding-bottom: 6px; }
.todo { background: var(--warn-bg); color: var(--warn); padding: 0 6px; border-radius: 4px; font-weight: 600; }
.callout { background: var(--accent-soft); border-radius: 12px; padding: 12px 16px; }
.data-table-wrap { overflow-x: auto; }

/* 10. Publicidad (solo marcadores) */
.ad { display: grid; place-items: center; text-align: center; background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 10px, var(--surface) 10px, var(--surface) 20px); border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: .72rem; letter-spacing: .12em; margin: 28px auto; width: 100%; }
.ad__label { font-weight: 700; }
.ad--banner { min-height: 100px; }
.ad--content { min-height: 280px; max-width: 336px; }
.ad--end { min-height: 250px; }
@media (min-width: 720px) { .ad--banner { min-height: 90px; } .ad--end { min-height: 120px; } .ad--content { max-width: 728px; min-height: 120px; } }
.ad--corner { display: none; }
@media (min-width: 1200px) {
  .ad--corner { display: grid; position: fixed; right: 16px; bottom: 16px; width: 220px; min-height: 120px; margin: 0; z-index: 30; background: var(--surface); box-shadow: 0 4px 24px rgba(0, 0, 0, .15); }
  .ad--corner[hidden] { display: none; }
  .ad__close { position: absolute; top: 2px; right: 4px; border: 0; background: none; color: var(--muted); font-size: 1.2rem; line-height: 1; padding: 4px 8px; }
}

/* 11. Pie */
.site-footer { background: var(--surface); border-top: 1px solid var(--line); padding: 32px 0 40px; font-size: .92rem; color: var(--muted); }
.footer-grid { display: grid; gap: 20px; }
@media (min-width: 720px) { .footer-grid { grid-template-columns: 2fr 1fr 1fr; } }
.site-footer h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink); }
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { margin-bottom: 6px; }
.site-footer a { color: var(--muted); }
.noscript { background: var(--warn-bg); color: var(--warn); padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; }

/* Consentimiento de cookies */
.consent { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 60; max-width: 640px; margin: 0 auto; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0, 0, 0, .25); padding: 14px 16px; }
.consent__t { font-weight: 700; margin: 0 0 4px; }
.consent__d { font-size: .88rem; color: var(--muted); margin: 0 0 10px; }
.consent__b { display: flex; gap: 8px; justify-content: flex-end; }
.linklike { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; font: inherit; cursor: pointer; }
@media print { .consent { display: none !important; } }

/* 12. Impresión */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .site-header, .site-footer, .ad, .crumbs, .hero, .tool-actions, .tool__form, .sumbar, .no-print, section:not(.tool-section), .privacy, .cmp-forms, .shared, .btn-row { display: none !important; }
  .tool-section { display: block !important; margin: 0; }
  .tool { border: 0; box-shadow: none; padding: 0; }
  .tool__grid { display: block; }
  .tool__results { position: static; max-height: none; overflow: visible; }
  .print-only { display: block; font-size: .8rem; margin-bottom: 8px; }
  .card--hero { background: #eee; color: #000; }
  details.more > *:not(summary) { display: block; }
}
