/* Servidex Dólar · estilos v2 — mobile-first, sin dependencias externas */

:root {
  --bg: #eef2f8;
  --surface: #ffffff;
  --surface-2: #f5f8fc;
  --ink: #0c1b33;
  --muted: #566883;
  --line: #d9e1ee;
  --navy: #0b3a82;
  --navy-deep: #082f6b;
  --on-navy: #ffffff;
  --accent: #0b3a82;
  --gold: #f2c14e;
  --gold-ink: #7a5600;
  --up: #12733a;
  --up-bg: #dff3e6;
  --down: #b3261e;
  --down-bg: #fbe4e1;
  --flat: #566883;
  --focus: #1a6dff;
  --shadow-card: 0 18px 38px -22px rgb(8 47 107 / .6);
  --font: "Segoe UI Variable Display", "Segoe UI", ui-rounded, system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0a1220;
  --surface: #111d33;
  --surface-2: #16243e;
  --ink: #e9f0fb;
  --muted: #94a5c2;
  --line: #243350;
  --navy: #14407f;
  --navy-deep: #0f3470;
  --accent: #7fb0ff;
  --gold: #f2c14e;
  --gold-ink: #f2c14e;
  --up: #55d085;
  --up-bg: #12301f;
  --down: #ff8077;
  --down-bg: #3a1a18;
  --flat: #94a5c2;
  --focus: #7fb0ff;
  --shadow-card: 0 18px 38px -22px rgb(0 0 0 / .9);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1220;
    --surface: #111d33;
    --surface-2: #16243e;
    --ink: #e9f0fb;
    --muted: #94a5c2;
    --line: #243350;
    --navy: #14407f;
    --navy-deep: #0f3470;
    --accent: #7fb0ff;
    --gold-ink: #f2c14e;
    --up: #55d085;
    --up-bg: #12301f;
    --down: #ff8077;
    --down-bg: #3a1a18;
    --flat: #94a5c2;
    --focus: #7fb0ff;
    --shadow-card: 0 18px 38px -22px rgb(0 0 0 / .9);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums lining-nums;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 10px; text-decoration: none;
}
.skip:focus { top: calc(var(--safe-t) + 8px); }

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) calc(28px + var(--safe-b)) calc(16px + var(--safe-l));
}

/* ── Cabecera ─────────────────────────────────────────── */
.top { display: flex; align-items: center; gap: 12px; padding: 4px 0 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand img { width: 38px; height: 38px; border-radius: 11px; flex: none; }
.brand b { font-size: 1.12rem; letter-spacing: -.01em; white-space: nowrap; }
.brand span { display: block; font-size: .78rem; color: var(--muted); line-height: 1.1; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; color: var(--ink);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.icon-btn[hidden] { display: none; }

.push-toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%) translateY(6px);
  max-width: calc(100% - 32px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: .86rem; font-weight: 600; box-shadow: 0 10px 30px -10px rgb(0 0 0 / .4); opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 60; text-align: center;
}
.push-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.nav-link {
  align-self: center; text-decoration: none; font-weight: 600; font-size: .9rem; color: var(--ink);
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}

/* ── Franja del dólar BCV ────────────────────────────── */
.band { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin: 2px 2px 16px; }
.band h1 { margin: 0; font-size: 1rem; font-weight: 600; color: var(--muted); flex-basis: 100%; }
.band-price { font-size: clamp(2.1rem, 8vw, 2.9rem); font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.band-price small { font-size: .5em; font-weight: 700; color: var(--muted); margin-right: 6px; letter-spacing: 0; }
.band-meta { font-size: .86rem; color: var(--muted); }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: .8rem; font-weight: 700; background: var(--surface-2); color: var(--flat);
}
.chip.up { background: var(--up-bg); color: var(--up); }
.chip.down { background: var(--down-bg); color: var(--down); }

.notice {
  margin: 0 0 14px; padding: 11px 14px; border-radius: 14px; font-size: .9rem;
  background: #fff4d6; color: #5c4300; border: 1px solid #f0d58a;
}
:root[data-theme="dark"] .notice { background: #3a2f10; color: #ffe29a; border-color: #5d4a17; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .notice { background: #3a2f10; color: #ffe29a; border-color: #5d4a17; } }
.notice[hidden] { display: none; }

/* ── Rejilla principal ───────────────────────────────── */
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 16px; }
.card h2 { margin: 0 0 12px; font-size: 1.02rem; letter-spacing: -.005em; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; min-width: 0; }

@media (min-width: 880px) {
  .grid {
    grid-template-columns: minmax(0, 1.08fr) minmax(0, .92fr);
    grid-template-areas: "calc rates" "chart gap";
    align-items: start;
    gap: 18px;
  }
  #calc { grid-area: calc; }
  #rates { grid-area: rates; }
  #chart { grid-area: chart; }
  #gap { grid-area: gap; }
}

/* ── Calculadora ─────────────────────────────────────── */
.calc {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 22px; padding: 16px;
  box-shadow: 0 1px 2px rgb(8 47 107 / .06), 0 16px 32px -22px rgb(8 47 107 / .45);
}
.calc h2 { margin: 0 0 12px; font-size: .95rem; font-weight: 600; color: var(--muted); }

.panel {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.panel:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(26 109 255 / .16); }
.panel-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.panel .cap { font-size: .8rem; font-weight: 600; color: var(--muted); }

.amount {
  display: block; width: 100%; min-width: 0; background: transparent; border: 0; outline: 0; padding: 0;
  font-size: clamp(1.75rem, 8vw, 2.35rem); font-weight: 600; letter-spacing: -.02em; line-height: 1.2; color: var(--ink);
}
.amount::placeholder { color: var(--muted); opacity: .55; }

.panel.out { background: var(--navy-deep); border-color: var(--navy-deep); color: #fff; }
.panel.out .cap { color: rgb(255 255 255 / .72); }
.result {
  font-size: clamp(1.75rem, 8vw, 2.35rem); font-weight: 600; letter-spacing: -.02em; line-height: 1.2;
  overflow-wrap: anywhere; min-height: 1.2em;
}
.result .unit { font-size: .6em; font-weight: 600; color: var(--gold); margin-right: 6px; letter-spacing: 0; }

/* Selector de moneda: píldora compacta con insignia */
.cur { position: relative; display: inline-flex; align-items: center; color: var(--ink); }
.cur::after {
  content: ""; position: absolute; right: 13px; top: 50%; width: 6px; height: 6px; pointer-events: none; opacity: .7;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-70%) rotate(45deg);
}
.panel.out .cur { color: #fff; }
.cur-select {
  appearance: none; -webkit-appearance: none; height: 36px; min-width: 96px; padding: 0 30px 0 38px; border-radius: 999px;
  border: 1px solid var(--line); background-color: var(--surface); color: inherit; font-weight: 600; font-size: .92rem;
}
.panel.out .cur-select { background-color: rgb(255 255 255 / .12); border-color: rgb(255 255 255 / .28); }
.cur-select option { color: var(--ink); background: var(--surface); }
.cur-select:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.cur-badge {
  position: absolute; left: 5px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: .8rem; font-weight: 700; color: #fff; background: var(--navy); pointer-events: none;
}
.cur-badge.usd { background: #1a7a3f; } .cur-badge.eur { background: #0b3a82; } .cur-badge.usdt { background: #1b9a76; }
.cur-badge.cny { background: #c0392b; } .cur-badge.try { background: #b3322e; } .cur-badge.rub { background: #3a58a8; }
.cur-badge.ves { background: var(--gold); color: #3b2a00; font-size: .68rem; }

/* Botón de intercambio, a caballo entre los dos paneles */
.swap-wrap { position: relative; z-index: 2; height: 8px; display: flex; align-items: center; justify-content: center; }
.swap {
  flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; padding: 0;
  background: var(--surface); color: var(--accent); border: 1px solid var(--line); box-shadow: 0 0 0 4px var(--surface);
  transition: transform .3s ease, background .15s;
}
.swap:hover { background: var(--surface-2); }
.swap svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.swap.spun { transform: rotate(180deg); }

/* Tasa utilizada */
.rate-used {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px;
  margin: 14px 2px 0; font-size: .86rem; color: var(--muted); min-height: 1.4em;
}
.rate-used b { color: var(--ink); font-weight: 600; }
.rate-used .tag { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 1px 10px; font-size: .76rem; font-weight: 600; }

/* Montos rápidos */
.quick-wrap { margin-top: 14px; }
.mini-cap { display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.quick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.quick::-webkit-scrollbar { display: none; }
.quick button {
  flex: none; height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: .85rem;
}
.quick button:hover { border-color: var(--accent); }
.quick button[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }

/* Acciones */
.btn {
  border: 0; border-radius: 14px; padding: 11px 16px; font-weight: 700; font-size: .92rem; min-height: 44px;
  background: #fff; color: #0b2c63; display: inline-flex; align-items: center; gap: 8px;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.calc .btn { justify-content: center; min-height: 42px; padding: 0 12px; border-radius: 12px; font-weight: 600; font-size: .88rem; background: var(--navy); color: #fff; }
.calc .btn:hover { filter: brightness(1.12); }
.calc .btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.calc .btn.ghost:hover { background: var(--surface-2); filter: none; }
.calc .btn svg { width: 16px; height: 16px; }
.flash { min-height: 1.2em; margin-top: 6px; text-align: center; font-size: .84rem; color: var(--up); }

/* ── Lista de tasas ──────────────────────────────────── */
.rate-list { list-style: none; margin: 0; padding: 0; }
.rate-list li + li { border-top: 1px solid var(--line); }
.rate-row {
  width: 100%; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  text-align: left; background: transparent; border: 0; padding: 12px 8px; border-radius: 14px; position: relative;
}
.rate-row:hover { background: var(--surface-2); }
.rate-row[aria-pressed="true"] { background: var(--surface-2); box-shadow: inset 4px 0 0 var(--gold); }
.badge {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 1.15rem; color: #fff; background: var(--navy);
}
.badge.usd { background: #1a7a3f; }
.badge.eur { background: #0b3a82; }
.badge.usdt { background: #1b9a76; }
.badge.cny { background: #c0392b; }
.badge.try { background: #b3322e; }
.badge.rub { background: #3a58a8; }
.rate-name { font-weight: 700; display: block; }
.rate-src { font-size: .8rem; color: var(--muted); display: block; }
.rate-val { text-align: right; }
.rate-val b { display: block; font-size: 1.12rem; letter-spacing: -.01em; }
.rate-val .chip { margin-top: 2px; font-size: .74rem; padding: 2px 8px; }
.stale-dot { color: var(--down); font-weight: 700; font-size: .75rem; }

/* ── Gráfico ─────────────────────────────────────────── */
.seg { flex: none; display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { white-space: nowrap; border: 0; background: transparent; padding: 6px 12px; border-radius: 9px; font-weight: 700; font-size: .85rem; color: var(--muted); min-height: 34px; }
.seg button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.chart-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.chart-val { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.chart-sub { color: var(--muted); font-size: .85rem; }
.chart-box { position: relative; touch-action: pan-y; }
.chart-box svg { display: block; width: 100%; height: 170px; overflow: visible; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-area { fill: var(--accent); opacity: .12; }
.chart-dot {
  position: absolute; left: var(--x, 100%); top: var(--y, 50%); width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 50%; background: var(--gold); border: 3px solid var(--accent); pointer-events: none;
}
.chart-cursor { position: absolute; top: 0; bottom: 0; left: var(--x, 100%); width: 0; border-left: 1px dashed var(--muted); pointer-events: none; }
.chart-cursor[hidden] { display: none; }
.chart-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .78rem; margin-top: 4px; }
.chart-empty { padding: 34px 10px; text-align: center; color: var(--muted); font-size: .92rem; }

/* ── Brecha BCV vs USDT ──────────────────────────────── */
.gap-row { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: .9rem; margin: 8px 0; }
.bar { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; width: var(--w, 0%); border-radius: 999px; background: var(--accent); }
.bar i.mkt { background: #1b9a76; }
.gap-note { margin: 10px 0 0; font-size: .9rem; color: var(--muted); }
.gap-note b { color: var(--ink); }

/* ── Texto SEO y pie ─────────────────────────────────── */
.lede { margin: 18px 2px 0; color: var(--muted); font-size: .92rem; max-width: 70ch; }
.lede strong { color: var(--ink); }
.foot { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .84rem; display: grid; gap: 8px; }
.foot nav { display: flex; gap: 16px; flex-wrap: wrap; }
.foot a { color: var(--accent); font-weight: 600; text-decoration: none; }
.foot a:hover { text-decoration: underline; }
.foot p { margin: 0; max-width: 75ch; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Modo embed / WebView  (?embed=1 [&view=calc|rates]) ── */
html.embed body { background: transparent; }
html.embed .app { padding-top: 8px; padding-bottom: 8px; }
html.embed .top, html.embed .foot, html.embed .lede, html.embed #chart, html.embed #gap { display: none; }
html.embed.view-calc #rates { display: none; }
html.embed.view-rates #calc, html.embed.view-rates .band { display: none; }
html.embed .grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: none; }
html.embed #calc, html.embed #rates { grid-area: auto; }

@media (min-width: 880px) {
  .brand img { width: 44px; height: 44px; }
  .card { padding: 20px; }
  .calc { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ── Tasas históricas ───────────────────────────────── */
:root { --warn: #c2410c; }
:root[data-theme="dark"] { --warn: #ff9f43; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --warn: #ff9f43; } }

#chart-h { white-space: nowrap; }
.tools { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.tool-btn {
  width: 36px; height: 36px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--accent); display: grid; place-items: center; padding: 0;
}
.tool-btn:hover { background: var(--surface-2); }
.tool-btn[aria-expanded="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.tool-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.hist-panel { background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 0 0 14px; }
.hist-panel[hidden] { display: none; }
.hist-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.hist-value { font-size: clamp(1.35rem, 6vw, 1.6rem); font-weight: 600; letter-spacing: -.02em; line-height: 1.2; margin-top: 2px; white-space: nowrap; }
.hist-sub { font-size: .86rem; color: var(--muted); margin-top: 2px; }
.link-btn { background: none; border: 0; padding: 6px 2px; color: var(--accent); font-weight: 600; font-size: .86rem; white-space: nowrap; }
.link-btn:hover { text-decoration: underline; }

.hist-dates { max-height: 240px; overflow-y: auto; padding: 0 4px 0 0; }
.month + .month { margin-top: 12px; }
.month h3 { margin: 0 0 6px; font-size: .8rem; font-weight: 600; color: var(--muted); position: sticky; top: 0; background: var(--surface-2); padding: 2px 0; z-index: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.date-chip {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font-weight: 600; font-size: .84rem;
}
.date-chip:hover { border-color: var(--accent); }
.date-chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }

.chain {
  display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px 12px; align-items: start;
  margin-top: 12px; padding: 12px; border-radius: 14px; border: 1px dashed var(--line); background: var(--surface);
}
.chain-ico { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); color: var(--accent); }
.chain-ico svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chain-txt b { display: block; font-size: .9rem; margin-top: 6px; }
.chain-txt span { font-size: .8rem; color: var(--muted); }
.soon { display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .02em; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.hist-foot { display: flex; justify-content: flex-end; margin-top: 6px; }

/* Aviso en la franja superior cuando se usan tasas históricas */
.hist-flag {
  background: none; border: 0; padding: 0; color: var(--warn); font-weight: 600; font-size: .9rem; text-align: left;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
}
