/* =============================================
   Monitor Bs. — v3
   Tokens: tema (dark/light) × acento (yellow/green)
   ============================================= */

:root,
[data-theme="dark"] {
    --bg: #0a0b0d;
    --bg-glass: rgba(10, 11, 13, 0.82);
    --surface: #111317;
    --surface-2: #16191e;
    --surface-3: #1d2127;
    --sheet-bg: #121418;
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #eceef1;
    --text-2: #9aa1ab;
    --text-3: #626a75;
    --overlay: rgba(0, 0, 0, 0.62);
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);

    --green: #4ade80;
    --green-rgb: 74, 222, 128;
    --blue: #60a5fa;
    --blue-rgb: 96, 165, 250;
    --yellow: #facc15;
    --yellow-rgb: 250, 204, 21;
    --red: #f87171;
    --red-rgb: 248, 113, 113;
    --purple: #a78bfa;
    --purple-rgb: 167, 139, 250;
}

[data-theme="light"] {
    --bg: #f2f3f5;
    --bg-glass: rgba(242, 243, 245, 0.85);
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --surface-3: #eceef1;
    --sheet-bg: #ffffff;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.16);
    --text: #15171a;
    --text-2: #5b626c;
    --text-3: #959ca6;
    --overlay: rgba(15, 18, 22, 0.45);
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.16);

    --green: #16a34a;
    --green-rgb: 22, 163, 74;
    --blue: #2563eb;
    --blue-rgb: 37, 99, 235;
    --yellow: #b7860b;
    --yellow-rgb: 183, 134, 11;
    --red: #dc2626;
    --red-rgb: 220, 38, 38;
    --purple: #7c3aed;
    --purple-rgb: 124, 58, 237;
}

/* Acento amarillo (Binance) */
:root,
[data-accent="yellow"] {
    --accent: #f0b90b;
    --accent-rgb: 240, 185, 11;
    --accent-ink: #f0b90b;
    --accent-contrast: #111316;
}

[data-theme="light"][data-accent="yellow"] {
    --accent-ink: #a37800;
}

/* Acento verde (estilo Arco) */
[data-accent="green"] {
    --accent: #5f8f3e;
    --accent-rgb: 95, 143, 62;
    --accent-ink: #86c25a;
    --accent-contrast: #ffffff;
}

[data-theme="light"][data-accent="green"] {
    --accent-ink: #4b7a2c;
}

/* =============================================
   BASE
   ============================================= */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    /* Evita el zoom por doble toque en iOS sin bloquear el zoom con dos dedos */
    touch-action: manipulation;
}

/* iOS hace zoom al enfocar campos con letra menor a 16px */
input,
select,
textarea {
    font-size: 16px;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s ease;
}

body.no-scroll {
    overflow: hidden;
}

button,
input {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

h1,
h2,
h3,
p {
    margin: 0;
}

.hidden {
    display: none !important;
}

/* Tamaños de íconos (lucide copia la clase al <svg>) */
.ic-xs { width: 12px; height: 12px; }
.ic-sm { width: 14px; height: 14px; }
.ic    { width: 17px; height: 17px; }
.ic-md { width: 20px; height: 20px; }

svg.lucide {
    flex-shrink: 0;
}

.animate-spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =============================================
   LAYOUT
   ============================================= */
.app {
    max-width: 460px;
    margin: 0 auto;
    /* espacio para la barra fija inferior */
    padding: 0 16px calc(96px + env(safe-area-inset-bottom));
}

/* ── Botones flotantes (abajo a la derecha) ── */
.bottom-dock {
    position: fixed;
    /* alineados con el borde derecho del contenido en pantallas anchas */
    right: max(16px, calc((100vw - 460px) / 2 + 16px));
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    transition: transform 0.12s, opacity 0.15s;
}

.fab:active {
    transform: scale(0.92);
}

.fab-main {
    width: 58px;
    height: 58px;
    background: var(--accent);
    color: var(--accent-contrast);
    box-shadow: 0 6px 18px rgba(var(--accent-rgb), 0.35);
    animation: fab-pulse 2.6s ease-in-out infinite;
}

.fab-main.is-active {
    animation: none;
}

.fab-sm {
    width: 44px;
    height: 44px;
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
}

/* Pulso suave: un halo del color de acento que crece y se desvanece */
@keyframes fab-pulse {
    0% { box-shadow: 0 6px 18px rgba(var(--accent-rgb), 0.35), 0 0 0 0 rgba(var(--accent-rgb), 0.32); }
    70% { box-shadow: 0 6px 18px rgba(var(--accent-rgb), 0.35), 0 0 0 14px rgba(var(--accent-rgb), 0); }
    100% { box-shadow: 0 6px 18px rgba(var(--accent-rgb), 0.35), 0 0 0 0 rgba(var(--accent-rgb), 0); }
}

@media (prefers-reduced-motion: reduce) {
    .fab-main {
        animation: none;
    }
}

.app-main {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ── Cabecera ── */
.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: calc(12px + env(safe-area-inset-top)) 0 12px;
    margin-bottom: 4px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: block;
    flex-shrink: 0;
}

.brand-text h1 {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
    white-space: nowrap;
}

.brand-text h1 span {
    color: var(--accent-ink);
}

.brand-text p {
    font-size: 11px;
    color: var(--text-3);
    margin-top: 1px;
    white-space: nowrap;
}

.hdr-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.offline-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: rgba(var(--red-rgb), 0.12);
    color: var(--red);
    margin-right: 2px;
}

/* ── Botón ícono genérico ── */
.icon-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}

.icon-btn:hover {
    background: var(--surface-3);
    color: var(--text);
}

.icon-btn:active {
    transform: scale(0.92);
}

.icon-btn.is-active {
    color: var(--accent-ink);
    background: rgba(var(--accent-rgb), 0.12);
}

.icon-btn.copied {
    color: var(--green);
    background: rgba(var(--green-rgb), 0.14);
}

.icon-btn-accent {
    color: var(--accent-ink);
    background: rgba(var(--accent-rgb), 0.12);
}

.icon-btn-accent:hover {
    color: var(--accent-ink);
    background: rgba(var(--accent-rgb), 0.2);
}

/* =============================================
   CONVERSOR
   ============================================= */
.converter {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px 16px 10px;
}

.conv-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.currency-wrap {
    position: relative;
    flex-shrink: 0;
}

.currency-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    border: none;
    background: transparent;
    padding: 4px 4px 4px 0;
    font-size: 30px;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.currency-btn svg {
    color: var(--text-3);
}

.currency-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: -6px;
    z-index: 30;
    min-width: 170px;
    padding: 6px;
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.currency-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    border: none;
    background: transparent;
    border-radius: 10px;
    padding: 9px 10px;
    text-align: left;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.currency-menu button:hover {
    background: var(--surface-2);
}

.currency-menu button.is-selected {
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent-ink);
}

.cm-sym {
    width: 26px;
    text-align: center;
    font-weight: 800;
    color: var(--accent-ink);
}

.amount-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font-size: 34px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
    padding: 0;
    caret-color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.amount-input::placeholder {
    color: var(--text-3);
}

.direction-pill {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    font-size: 14px;
    font-weight: 800;
    color: var(--text-2);
    transition: background 0.15s, transform 0.1s;
}

.direction-pill:hover {
    background: var(--surface-3);
}

.direction-pill:active {
    transform: scale(0.95);
}

.direction-pill svg {
    color: var(--text-3);
}

.dir-from {
    color: var(--accent-ink);
}

.quick-row {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    overflow-x: auto;
    scrollbar-width: none;
}

.quick-row::-webkit-scrollbar {
    display: none;
}

.quick-btn {
    flex-shrink: 0;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    border-radius: 9px;
    padding: 5px 12px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.quick-btn:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.quick-btn.active {
    background: rgba(var(--accent-rgb), 0.14);
    border-color: rgba(var(--accent-rgb), 0.4);
    color: var(--accent-ink);
}

.conv-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.conv-hint {
    font-size: 12px;
    color: var(--text-3);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-hint strong {
    color: var(--text-2);
    font-weight: 600;
}

.conv-icons {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

/* =============================================
   EQUIVALENTE EN USDT
   ============================================= */
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.7); }
}

.usdt-card {
    border-radius: 20px;
    padding: 14px 16px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
}

.usdt-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.usdt-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
}

.usdt-value-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 8px 0 4px;
}

.usdt-value {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}

.usdt-sub {
    font-size: 12px;
    color: var(--text-3);
}

.usdt-sub strong {
    color: var(--text-2);
    font-weight: 600;
}

.usdt-price {
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-3);
}

.usdt-price:empty {
    display: none;
}

.binance-btn {
    width: 100%;
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 11px;
    border-radius: 13px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.binance-btn svg {
    color: var(--accent-ink);
}

.binance-btn:hover {
    background: var(--surface-3);
    border-color: rgba(var(--accent-rgb), 0.45);
}

.binance-btn:active {
    transform: scale(0.98);
}

/* =============================================
   TASAS
   ============================================= */
.rates-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 2px 10px;
}

.section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-3);
}

.rate-date-badge {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px 8px;
}

.rate-date-badge:empty {
    display: none;
}

.rate-date-badge.is-historical {
    color: var(--accent-ink);
    border-color: rgba(var(--accent-rgb), 0.35);
}

.view-toggle {
    margin-left: auto;
    display: flex;
    padding: 3px;
    gap: 2px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.view-toggle button {
    width: 30px;
    height: 26px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.view-toggle button.is-selected {
    background: var(--surface-3);
    color: var(--text);
}

.rates-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* ── Tarjeta ── */
.rate-card {
    --cc: var(--green);
    --cc-rgb: var(--green-rgb);
    display: flex;
    flex-direction: column;
    text-align: left;
    width: 100%;
    min-width: 0;
    padding: 14px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s, background 0.2s, transform 0.12s, border-radius 0.25s;
}

.rate-card[data-color="blue"] { --cc: var(--blue); --cc-rgb: var(--blue-rgb); }
.rate-card[data-color="yellow"] { --cc: var(--yellow); --cc-rgb: var(--yellow-rgb); }
.rate-card[data-color="red"] { --cc: var(--red); --cc-rgb: var(--red-rgb); }
.rate-card[data-color="purple"] { --cc: var(--purple); --cc-rgb: var(--purple-rgb); }

.rate-card:hover {
    border-color: var(--border-strong);
    background: var(--surface-2);
}

.rate-card:active {
    transform: scale(0.98);
}

.rate-card.copied {
    border-color: rgba(var(--green-rgb), 0.6);
}

.rate-card.is-alert {
    border-color: rgba(var(--red-rgb), 0.55);
    animation: alert-pulse 1.6s ease-in-out infinite;
}

@keyframes alert-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(var(--red-rgb), 0); }
    50% { box-shadow: 0 0 0 4px rgba(var(--red-rgb), 0.15); }
}

.rc-head {
    grid-area: head;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.rc-icon {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--cc-rgb), 0.13);
    color: var(--cc);
}

.rc-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rc-value {
    grid-area: value;
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-top: 10px;
    min-width: 0;
}

.rc-num {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rc-suffix {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-ink);
}

.rc-meta {
    grid-area: meta;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 10px;
    padding-top: 9px;
    border-top: 1px solid var(--border);
    min-width: 0;
}

.rc-line {
    font-size: 11px;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rc-line:empty {
    display: none;
}

.rc-change {
    grid-area: change;
    margin-top: 3px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    white-space: nowrap;
}

.rc-change:empty {
    display: none;
}

.rc-change.up { color: var(--green); }
.rc-change.down { color: var(--red); }
.rc-change.alert { color: var(--red); }

/* ── Vista lista ── */
.rates-grid.is-list {
    grid-template-columns: 1fr;
    gap: 8px;
}

.rates-grid.is-list .rate-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "head value"
        "meta change";
    column-gap: 12px;
    align-items: center;
    padding: 12px 14px;
}

.rates-grid.is-list .rc-value {
    margin-top: 0;
    justify-self: end;
}

.rates-grid.is-list .rc-num {
    font-size: 19px;
}

.rates-grid.is-list .rc-meta {
    margin-top: 4px;
    padding-top: 0;
    border-top: none;
    padding-left: 34px;
}

.rates-grid.is-list .rc-change {
    justify-self: end;
    align-self: start;
    margin-top: 4px;
}

.rates-hint {
    text-align: center;
    font-size: 11px;
    font-style: italic;
    color: var(--text-3);
    margin-top: 12px;
}

.error-box {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 12px;
    color: var(--yellow);
    background: rgba(var(--yellow-rgb), 0.08);
    border: 1px solid rgba(var(--yellow-rgb), 0.25);
}

.error-box svg {
    margin-top: 1px;
}

/* Animación al cambiar valores */
.value-updated {
    animation: valuePop 0.3s ease-out;
}

@keyframes valuePop {
    0% { transform: scale(1); }
    45% { transform: scale(1.04); }
    100% { transform: scale(1); }
}

/* =============================================
   HOJAS (bottom sheets) y MODAL
   ============================================= */
.sheet-overlay,
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--overlay);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: flex;
    justify-content: center;
    animation: fadeIn 0.18s ease;
}

.sheet-overlay {
    align-items: flex-end;
}

.modal-overlay {
    align-items: center;
    padding: 16px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.sheet {
    width: 100%;
    max-width: 460px;
    max-height: 92vh;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    background: var(--sheet-bg);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 24px 24px 0 0;
    box-shadow: var(--shadow);
    animation: slideUp 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

@media (min-width: 640px) {
    .sheet {
        margin-bottom: 16px;
        border-bottom: 1px solid var(--border);
        border-radius: 24px;
    }
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Zona para arrastrar hacia abajo y cerrar (barrita + cabecera) */
.sheet-handle {
    height: 22px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    touch-action: none;
}

.sheet-handle::before {
    content: '';
    width: 42px;
    height: 5px;
    border-radius: 5px;
    background: var(--border-strong);
}

.sheet-header {
    touch-action: none;
}

.sheet {
    transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

.sheet.is-dragging {
    transition: none;
}

.sheet.is-dragging .sheet-handle {
    cursor: grabbing;
}

/* Barra de scroll discreta */
.sheet-body,
.modal-body,
.calc-history-list {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.sheet-body::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.calc-history-list::-webkit-scrollbar {
    width: 4px;
}

.sheet-body::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track,
.calc-history-list::-webkit-scrollbar-track {
    background: transparent;
}

.sheet-body::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.calc-history-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

.sheet-header,
.modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 16px 12px 18px;
    flex-shrink: 0;
}

.sheet-header h3,
.modal-header h3 {
    flex: 1;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.sheet-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent-ink);
}

.sheet-header-actions {
    display: flex;
    gap: 4px;
}

.sheet-close {
    background: var(--surface-3);
    border-radius: 50%;
}

.sheet-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 18px 18px;
}

.sheet-footer {
    flex-shrink: 0;
    padding: 12px 18px calc(16px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
}

.modal {
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    max-height: 90dvh;
    display: flex;
    flex-direction: column;
    background: var(--sheet-bg);
    border: 1px solid var(--border);
    border-radius: 26px;
    box-shadow: var(--shadow);
    animation: modalIn 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--border);
}

.modal-kicker {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-ink);
    margin-top: 2px;
}

.modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    padding: 14px 18px 18px;
    border-top: 1px solid var(--border);
}

.modal-footer .btn-primary {
    flex: 1;
}

.news-item {
    display: flex;
    gap: 12px;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.news-item .rc-icon {
    --cc: var(--accent-ink);
    --cc-rgb: var(--accent-rgb);
    width: 32px;
    height: 32px;
    border-radius: 10px;
}

.news-title {
    font-size: 14px;
    font-weight: 700;
}

.news-desc {
    font-size: 12px;
    color: var(--text-2);
    margin-top: 3px;
    line-height: 1.5;
}

/* ── Botones ── */
.btn-primary,
.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 14px;
    padding: 13px 16px;
    font-size: 14px;
    font-weight: 700;
    transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

.btn-primary {
    width: 100%;
    border: none;
    background: var(--accent);
    color: var(--accent-contrast);
}

.btn-primary:hover {
    opacity: 0.92;
}

.btn-primary:active,
.btn-ghost:active {
    transform: scale(0.98);
}

.btn-ghost {
    border: 1px solid var(--border-strong);
    background: transparent;
    color: var(--text);
}

.btn-ghost:hover {
    background: var(--surface-3);
}

.btn-sm {
    width: auto;
    padding: 7px 14px;
    font-size: 12px;
    border-radius: 10px;
}

.link-btn {
    border: none;
    background: none;
    padding: 0;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.link-btn:hover {
    color: var(--accent-ink);
}

.chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 11px;
    font-weight: 700;
    border-radius: 20px;
    padding: 5px 11px;
}

.chip-btn:hover {
    color: var(--accent-ink);
    border-color: rgba(var(--accent-rgb), 0.5);
}

.chip-btn-green:hover {
    color: var(--green);
    border-color: rgba(var(--green-rgb), 0.5);
}

.mini-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-2);
    font-size: 11px;
    font-weight: 600;
    border-radius: 9px;
    padding: 5px 9px;
}

.mini-btn:hover {
    color: var(--text);
}

/* ── Campos ── */
.field-input {
    width: 100%;
    min-width: 0;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 13px;
    padding: 12px 14px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.15s;
}

.field-input::placeholder {
    color: var(--text-3);
}

.field-input:focus {
    border-color: rgba(var(--accent-rgb), 0.6);
}

.field-icon-wrap {
    position: relative;
}

.field-icon-wrap svg {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
    pointer-events: none;
}

.field-icon-wrap .field-input {
    padding-left: 36px;
}

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

input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

[data-theme="dark"] input[type=date]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.6;
}

/* ── Control segmentado ── */
.seg {
    display: flex;
    gap: 6px;
}

.seg button {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text-2);
    font-weight: 600;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.seg button.is-selected {
    border-color: rgba(var(--accent-rgb), 0.55);
    background: rgba(var(--accent-rgb), 0.12);
    color: var(--accent-ink);
}

.seg-lg button {
    padding: 13px 10px;
    border-radius: 14px;
    font-size: 14px;
}

.seg-sm {
    flex-shrink: 0;
    gap: 4px;
}

.seg-sm button {
    padding: 6px 9px;
    border-radius: 9px;
    font-size: 11px;
}

.seg-xs {
    flex-shrink: 0;
    gap: 3px;
}

.seg-xs button {
    flex: none;
    padding: 4px 9px;
    border-radius: 8px;
    font-size: 11px;
}

.swatch {
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

.swatch-yellow { background: #f0b90b; }
.swatch-green { background: #5f8f3e; }

/* ── Interruptor ── */
.switch {
    position: relative;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
    border: none;
    border-radius: 20px;
    background: var(--border-strong);
    transition: background 0.15s;
}

.switch.active {
    background: var(--accent);
}

.switch-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s;
}

.switch.active .switch-knob {
    transform: translateX(18px);
}

/* =============================================
   CALCULADORA
   ============================================= */
.calc-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.calc-display {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 18px;
    padding: 10px 12px 10px;
}

.calc-display-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.calc-items {
    display: flex;
    flex-wrap: nowrap;
    gap: 5px;
    margin-top: 8px;
    height: 26px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

.calc-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    border-radius: 20px;
    padding: 3px 5px 3px 10px;
}

.calc-item-remove {
    width: 17px;
    height: 17px;
    border: none;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--text-3);
    font-size: 12px;
    line-height: 1;
    padding: 0;
}

.calc-item-remove:hover {
    background: rgba(var(--red-rgb), 0.15);
    color: var(--red);
}

.calc-expression {
    text-align: right;
    height: 18px;
    line-height: 18px;
    margin-top: 6px;
    font-size: 13px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-main {
    text-align: right;
    height: 48px;
    line-height: 48px;
    font-size: 38px;
    font-weight: 800;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    font-variant-numeric: tabular-nums;
    transition: font-size 0.18s ease;
}

.calc-expression::-webkit-scrollbar,
.calc-main::-webkit-scrollbar {
    display: none;
}

.chips-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
}

.calc-chips-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chips-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 1px 24px 1px 1px;
    margin-right: -18px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
}

.chips-row:empty::after {
    content: 'Sin datos todavía';
    font-size: 11px;
    color: var(--text-3);
}

.rate-chip {
    --cc: var(--green);
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 20px;
    padding: 6px 11px;
    font-size: 12px;
    white-space: nowrap;
}

.rate-chip[data-color="blue"] { --cc: var(--blue); }
.rate-chip[data-color="yellow"] { --cc: var(--yellow); }
.rate-chip[data-color="purple"] { --cc: var(--purple); }

.rate-chip:hover {
    border-color: var(--cc);
}

.rate-chip .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cc);
}

.rate-chip .lbl {
    color: var(--text-2);
}

.rate-chip .val {
    color: var(--cc);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.rate-chip.is-prev {
    opacity: 0.75;
}

.rate-chip.is-selected {
    opacity: 1;
    border-color: var(--cc);
    background: color-mix(in srgb, var(--cc) 14%, var(--surface));
}

.calc-history-panel {
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 10px 12px;
    background: var(--surface);
}

.calc-history-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.calc-history-list {
    display: flex;
    flex-direction: column;
    max-height: 170px;
    overflow-y: auto;
}

.calc-history-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    padding: 8px 2px;
    text-align: left;
    font-size: 13px;
}

.calc-history-row:last-child {
    border-bottom: none;
}

.calc-history-row .expr {
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calc-history-row .res {
    font-weight: 700;
    flex-shrink: 0;
}

.calc-history-empty {
    font-size: 12px;
    color: var(--text-3);
    padding: 6px 0;
}

.calc-keypad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.key {
    height: clamp(44px, 6.4vh, 52px);
    border: none;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text);
    font-size: 21px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, transform 0.08s;
    touch-action: manipulation;
}

.key:hover {
    filter: brightness(1.12);
}

.key:active {
    transform: scale(0.94);
}

.key-fn {
    color: var(--text-2);
    font-size: 18px;
}

.key-op {
    color: var(--accent-ink);
    background: rgba(var(--accent-rgb), 0.12);
    font-size: 22px;
}

.key-eq {
    background: var(--accent);
    color: var(--accent-contrast);
    font-size: 24px;
}

.key-del {
    color: var(--red);
    background: rgba(var(--red-rgb), 0.12);
    font-size: 19px;
    font-weight: 700;
}

/* =============================================
   HISTORIAL
   ============================================= */
.history-filters {
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-filters .field-input {
    padding: 10px 10px;
    font-size: 16px;
}

.history-sep {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-3);
}

.history-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 12px 0;
    min-height: 26px;
}

.history-export {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 14px;
    padding: 9px 10px;
}

.history-cell {
    display: flex;
    flex-direction: column;
    border: none;
    background: none;
    border-radius: 8px;
    padding: 3px 6px;
    text-align: left;
    transition: background 0.15s;
}

.history-cell:hover {
    background: var(--surface-3);
}

.history-cell.is-value {
    align-items: flex-end;
    text-align: right;
}

.history-cell-label {
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-3);
}

.history-cell-value {
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.history-values {
    display: flex;
    gap: 2px;
}

.history-empty {
    text-align: center;
    padding: 28px 8px;
    font-size: 12px;
    color: var(--text-3);
}

/* =============================================
   COMPARTIR
   ============================================= */
.share-fields {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 14px;
}

.share-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    margin: 18px 0 9px;
}

.select-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.select-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 16px;
    padding: 12px 14px;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
}

.select-row.is-selected {
    border-color: rgba(var(--accent-rgb), 0.55);
    background: rgba(var(--accent-rgb), 0.07);
}

.select-row-title {
    font-size: 14px;
    font-weight: 700;
}

.select-row-sub {
    display: block;
    font-size: 12px;
    color: var(--text-3);
    margin-top: 1px;
    font-variant-numeric: tabular-nums;
}

.select-check {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 2px solid var(--border-strong);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    transition: background 0.15s, border-color 0.15s;
}

.select-row.is-selected .select-check {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.share-label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.share-label-row .share-label {
    margin-top: 6px;
}

.select-row-main {
    min-width: 0;
}

.select-row-sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
    padding: 20px 16px;
    border: 1px dashed var(--border-strong);
    border-radius: 16px;
    color: var(--text-3);
    font-size: 12px;
}

.empty-card svg {
    width: 26px;
    height: 26px;
}

/* =============================================
   PERFILES DE PAGO
   ============================================= */
.sheet-intro {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-3);
    margin-bottom: 14px;
}

.profiles-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.profile-row {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 16px;
    padding: 6px 6px 6px 4px;
}

.profile-main {
    flex: 1;
    min-width: 0;
    border: none;
    background: none;
    text-align: left;
    padding: 6px 4px;
}

.profile-star.is-default {
    color: var(--yellow);
}

.profile-star.is-default svg {
    fill: currentColor;
}

.icon-btn-solid {
    background: var(--accent);
    color: var(--accent-contrast);
}

.icon-btn-solid:hover {
    background: var(--accent);
    color: var(--accent-contrast);
    opacity: 0.9;
}

.form-card {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 18px;
    overflow: hidden;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 54px;
    padding: 10px 16px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    text-align: left;
}

.form-card > :last-child,
.form-card > .form-row:last-of-type {
    border-bottom: none;
}

.form-row-col {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.form-row-btn:hover {
    background: var(--surface-2);
}

.form-label {
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.form-value {
    flex: 1;
    min-width: 0;
    text-align: right;
    font-size: 13px;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.form-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 16px;
    text-align: right;
    padding: 4px 0;
}

.form-input::placeholder {
    color: var(--text-3);
}

.form-input-left {
    text-align: left;
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
}

.form-select {
    flex-shrink: 0;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 9px;
    padding: 5px 6px;
    font-size: 16px;
    font-weight: 600;
}

.form-hint {
    font-size: 11px;
    color: var(--text-3);
}

.form-hint.is-ok {
    color: var(--green);
}

.bank-list {
    display: flex;
    flex-direction: column;
    max-height: 260px;
    overflow-y: auto;
    border-top: 1px solid var(--border);
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.bank-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    padding: 10px 16px;
    text-align: left;
    font-size: 13px;
}

.bank-item:last-child {
    border-bottom: none;
}

.bank-item .bank-code {
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
    width: 38px;
    flex-shrink: 0;
}

.bank-item .bank-name {
    flex: 1;
}

.bank-item .select-check {
    width: 20px;
    height: 20px;
}

.bank-item.is-selected .select-check {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.btn-danger {
    width: 100%;
    margin-top: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid rgba(var(--red-rgb), 0.35);
    background: rgba(var(--red-rgb), 0.08);
    color: var(--red);
    font-size: 14px;
    font-weight: 700;
}

#profile-editor .seg-lg {
    margin-bottom: 4px;
}

/* =============================================
   CONFIGURACIÓN
   ============================================= */
.settings-body {
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
}

.settings-group-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-3);
    margin: 14px 4px 8px;
}

.settings-group-label:first-child {
    margin-top: 2px;
}

.settings-card {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 18px;
    overflow: hidden;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 12px 14px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    text-align: left;
}

.settings-card > .settings-row:last-child {
    border-bottom: none;
}

.settings-row-btn:hover {
    background: var(--surface-2);
}

a.settings-row-btn {
    color: inherit;
    text-decoration: none;
}

.settings-row-icon {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-3);
    color: var(--text-2);
}

.settings-row-text {
    flex: 1;
    min-width: 0;
}

.settings-row-title {
    font-size: 14px;
    font-weight: 600;
}

.settings-row-sub {
    font-size: 11px;
    color: var(--text-3);
    margin-top: 1px;
}

.row-chevron {
    color: var(--text-3);
}

.settings-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px 14px;
    border-bottom: 1px solid var(--border);
}

.settings-card > .settings-fields:last-child {
    border-bottom: none;
}

.settings-version {
    text-align: center;
    font-size: 11px;
    color: var(--text-3);
    margin-top: 18px;
}

/* =============================================
   TOAST
   ============================================= */
.toast {
    position: fixed;
    left: 50%;
    /* arriba, bajo la cabecera, para no tapar los botones flotantes */
    top: calc(68px + env(safe-area-inset-top));
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    align-items: center;
    gap: 9px;
    max-width: calc(100vw - 32px);
    padding: 10px 18px;
    border-radius: 30px;
    background: rgba(22, 163, 74, 0.95);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    animation: toastIn 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

.toast.error {
    background: rgba(220, 38, 38, 0.95);
}

.toast-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.85);
    animation: pulse-dot 1.4s ease-in-out infinite;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* =============================================
   CÓMO INSTALAR
   ============================================= */
.install-steps {
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: step;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.install-steps li {
    counter-increment: step;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
}

.install-steps li::before {
    content: counter(step);
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--accent-rgb), 0.15);
    color: var(--accent-ink);
    font-size: 12px;
    font-weight: 800;
}

.install-steps strong {
    font-weight: 700;
}

.install-note {
    font-size: 12px;
    color: var(--text-3);
    line-height: 1.5;
}

.install-note:empty {
    display: none;
}

/* =============================================
   GUÍA (driver.js) con los colores de la app
   ============================================= */
.driver-popover.mbs-tour {
    background: var(--sheet-bg);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow);
    max-width: 290px;
}

.driver-popover.mbs-tour * {
    font-family: 'Inter', -apple-system, sans-serif;
}

.driver-popover.mbs-tour .driver-popover-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.driver-popover.mbs-tour .driver-popover-description {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-2);
}

.driver-popover.mbs-tour .driver-popover-progress-text {
    font-size: 11px;
    color: var(--text-3);
}

.driver-popover.mbs-tour .driver-popover-close-btn {
    color: var(--text-3);
}

.driver-popover.mbs-tour .driver-popover-footer button {
    text-shadow: none;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 9px;
    padding: 6px 11px;
    font-size: 12px;
    font-weight: 600;
}

.driver-popover.mbs-tour .driver-popover-footer button.driver-popover-next-btn {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.driver-popover.mbs-tour .driver-popover-arrow-side-left { border-left-color: var(--sheet-bg); }
.driver-popover.mbs-tour .driver-popover-arrow-side-right { border-right-color: var(--sheet-bg); }
.driver-popover.mbs-tour .driver-popover-arrow-side-top { border-top-color: var(--sheet-bg); }
.driver-popover.mbs-tour .driver-popover-arrow-side-bottom { border-bottom-color: var(--sheet-bg); }

/* =============================================
   PANTALLAS ESTRECHAS
   ============================================= */
@media (max-width: 400px) {
    .hdr-actions .icon-btn {
        width: 32px;
    }

    .hdr-actions {
        gap: 0;
    }
}

@media (max-width: 370px) {
    .app {
        padding-left: 12px;
        padding-right: 12px;
    }

    .brand-text p {
        display: none;
    }

    .currency-btn {
        font-size: 26px;
    }

    .amount-input {
        font-size: 28px;
    }

    .direction-pill {
        padding: 8px 9px;
        font-size: 13px;
    }

    .rc-num {
        font-size: 19px;
    }

    .key {
        height: 50px;
    }
}

/* =============================================
   TRANSICIONES (todo entra y sale suave)
   ============================================= */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: none; }
}

@keyframes fadeSlideOut {
    from { opacity: 1; transform: none; }
    to { opacity: 0; transform: translateY(-6px); }
}

.anim-in {
    animation: fadeSlideIn 0.24s cubic-bezier(0.32, 0.72, 0, 1) both;
}

.anim-out {
    animation: fadeSlideOut 0.18s ease both;
    pointer-events: none;
}

/* Menú de moneda: crece desde el botón */
.currency-menu {
    transform-origin: top left;
}

.currency-menu.anim-in {
    animation: menuIn 0.18s cubic-bezier(0.32, 0.72, 0, 1) both;
}

.currency-menu.anim-out {
    animation: menuOut 0.14s ease both;
}

@keyframes menuIn {
    from { opacity: 0; transform: scale(0.94) translateY(-4px); }
    to { opacity: 1; transform: none; }
}

@keyframes menuOut {
    to { opacity: 0; transform: scale(0.96) translateY(-4px); }
}

/* Entrada de tarjetas */
.rate-card.card-in {
    animation: cardIn 0.42s cubic-bezier(0.32, 0.72, 0, 1) both;
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to { opacity: 1; transform: none; }
}

/* Cierre de hojas y ventanas */
.sheet-overlay.is-closing,
.modal-overlay.is-closing {
    animation: overlayOut 0.24s ease both;
    pointer-events: none;
}

.sheet-overlay.is-closing .sheet {
    animation: sheetOut 0.24s cubic-bezier(0.32, 0.72, 0, 1) both;
}

.modal-overlay.is-closing .modal {
    animation: modalOut 0.2s ease both;
}

@keyframes overlayOut {
    to { opacity: 0; }
}

/* sin "from": parte de donde esté la hoja (también si se soltó al arrastrarla) */
@keyframes sheetOut {
    to { transform: translateY(100%); }
}

@keyframes modalOut {
    to { opacity: 0; transform: scale(0.95); }
}

/* Aviso que se va */
.toast.is-hiding {
    animation: toastOut 0.22s ease both;
}

@keyframes toastOut {
    to { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* Marcas de selección que "aparecen" */
.select-check svg {
    transform: scale(0.4);
    opacity: 0;
    transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.15s;
}

.is-selected .select-check svg {
    transform: scale(1);
    opacity: 1;
}

.select-row,
.bank-item,
.rate-chip,
.view-toggle button,
.seg button,
.quick-btn {
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.12s ease;
}

.select-row:active,
.rate-chip:active,
.seg button:active,
.view-toggle button:active,
.quick-btn:active {
    transform: scale(0.97);
}

/* Flecha del desplegable de bancos */
#pf-banks-chevron {
    transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

#pf-banks-chevron.is-open {
    transform: rotate(90deg);
}

/* Cambio de icono del botón de copiar */
.icon-btn svg {
    transition: transform 0.15s ease;
}

.icon-btn.copied svg {
    transform: scale(1.12);
}

@media (prefers-reduced-motion: reduce) {
    .anim-in,
    .anim-out,
    .rate-card.card-in,
    .sheet-overlay,
    .modal-overlay,
    .sheet,
    .modal,
    .toast {
        animation: none !important;
    }
}


/* ── Calculadora: detalles de la pantalla ── */
.calc-items::-webkit-scrollbar,
.chips-row::-webkit-scrollbar {
    display: none;
}

.calc-items.is-empty {
    visibility: hidden;
}

.calc-item {
    flex-shrink: 0;
}

.calc-main.fs-xl { font-size: 38px; }
.calc-main.fs-lg { font-size: 30px; }
.calc-main.fs-md { font-size: 24px; }
.calc-main.fs-sm { font-size: 20px; }

/* Al pulsar "=": el resultado sube y la operación aparece arriba */
.calc-main.calc-swap {
    animation: calcResultIn 0.34s cubic-bezier(0.32, 0.72, 0, 1) both;
}

.calc-expression.calc-swap {
    animation: calcEchoIn 0.34s cubic-bezier(0.32, 0.72, 0, 1) both;
}

@keyframes calcResultIn {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: none; }
}

@keyframes calcEchoIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .calc-main { transition: none; }
    .calc-main.calc-swap,
    .calc-expression.calc-swap { animation: none; }
}

/* ── Calculadora: cursor para corregir en medio de la operación ── */
.calc-main {
    cursor: text;
}

/* Ancho neto cero (margen negativo) para que el texto no se mueva al aparecer */
.calc-caret {
    display: inline-block;
    width: 2px;
    height: 0.95em;
    margin: 0 -1px;
    vertical-align: -0.12em;
    border-radius: 1px;
    background: var(--accent);
    animation: calcCaretBlink 1.05s step-end infinite;
}

@keyframes calcCaretBlink {
    50% { opacity: 0; }
}

.calc-item,
.calc-expression.is-editable {
    cursor: pointer;
}

.calc-expression.is-editable {
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
    .calc-caret { animation: none; }
}

/* =============================================
   ESCRITORIO: vista bento (≥ 900px)
   La calculadora y el historial pasan de hojas a mosaicos fijos (ver app.js)
   ============================================= */
.dock-tile,
.desk-side,
.desktop-only {
    display: none;
}

/* En Configuración (teléfono) el bloque va entre otros grupos: conserva su margen */
.settings-quick > .settings-group-label:first-child {
    margin-top: 14px;
}

@media (min-width: 900px) {
    body.is-desktop .app {
        max-width: 1240px;
        padding: 0 28px 32px;
    }

    body.is-desktop .bottom-dock,
    body.is-desktop #hdr-calc,
    body.is-desktop #hdr-history {
        display: none;
    }

    body.is-desktop .desktop-only {
        display: inline-flex;
    }

    /* Dos columnas: contenido + calculadora */
    body.is-desktop .app-main {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 360px;
        grid-template-areas:
            "conv  calc"
            "rates calc"
            "usdt  calc"
            "hist  calc";
        /* la última fila absorbe la altura sobrante de la calculadora */
        grid-template-rows: auto auto auto 1fr;
        gap: 16px;
        align-items: start;
    }

    body.is-desktop #converter { grid-area: conv; }
    body.is-desktop .rates-section { grid-area: rates; }
    body.is-desktop #hero { grid-area: usdt; }
    body.is-desktop #history-tile { grid-area: hist; }
    body.is-desktop #desk-side { grid-area: calc; }

    /* 2 × 2 junto a la calculadora; en pantallas grandes, todas en una fila */
    body.is-desktop .rates-grid:not(.is-list) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* ── Mosaicos con la calculadora y el historial ── */
    body.is-desktop .dock-tile {
        display: block;
        position: relative;
        min-width: 0;
    }

    /* Columna derecha: calculadora y, debajo, los ajustes rápidos */
    body.is-desktop .desk-side {
        display: flex;
        flex-direction: column;
        gap: 16px;
        min-width: 0;
    }

    body.is-desktop #prefs-tile .settings-group-label:first-child {
        margin-top: 2px;
    }

    /* El historial ocupa el alto de su fila sin estirarla con su lista */
    body.is-desktop #history-tile {
        align-self: stretch;
        min-height: 340px;
    }

    body.is-desktop #history-tile .sheet {
        position: absolute;
        inset: 0;
    }

    body.is-desktop .dock-tile .sheet {
        max-width: none;
        max-height: none;
        margin: 0;
        border: 1px solid var(--border);
        border-radius: 20px;
        background: var(--surface);
        box-shadow: none;
        animation: none;
        transform: none;
    }

    body.is-desktop .dock-tile .sheet-handle,
    body.is-desktop .dock-tile .sheet-close {
        display: none;
    }

    body.is-desktop .dock-tile .sheet-header {
        padding-top: 14px;
        touch-action: auto;
    }

    body.is-desktop .dock-tile .sheet-footer {
        padding-bottom: 16px;
    }

    body.is-desktop .dock-tile.is-flash .sheet {
        animation: tileFlash 0.7s ease;
    }

    @keyframes tileFlash {
        0% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0); }
        30% { box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.35); }
        100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0); }
    }

    /* Las demás hojas (compartir, configuración...) se abren como diálogo centrado */
    body.is-desktop .sheet-overlay {
        align-items: center;
    }

    body.is-desktop .sheet-overlay .sheet {
        margin-bottom: 0;
        max-width: 480px;
        max-height: 86vh;
    }

    body.is-desktop .sheet-overlay .sheet-handle {
        display: none;
    }

    body.is-desktop .sheet-overlay .sheet-header {
        padding-top: 16px;
    }
}

/* La columna derecha (calculadora + ajustes, ~890px) acompaña al bajar solo si cabe
   entera en la pantalla; si no, quedaría fuera de alcance lo de abajo */
@media (min-width: 900px) and (min-height: 1000px) {
    body.is-desktop .desk-side {
        position: sticky;
        top: 68px; /* igual a su posición natural bajo la cabecera */
    }
}

/* Tres columnas: convertidor y tasas a lo ancho, USDT e historial lado a lado */
@media (min-width: 1200px) {
    body.is-desktop .app-main {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 380px;
        grid-template-areas:
            "conv  conv  calc"
            "rates rates calc"
            "usdt  hist  calc";
        grid-template-rows: auto auto 1fr;
    }

    body.is-desktop .rates-grid:not(.is-list) {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    body.is-desktop #hero {
        align-self: stretch;
        display: flex;
        flex-direction: column;
    }

    body.is-desktop #hero .binance-btn {
        margin-top: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.is-desktop .dock-tile.is-flash .sheet { animation: none; }
}
