/* ---------- RoadCash · estilos ----------
   Estética: dashboard de salpicadero. Tema oscuro
   anti-reflejo, números tipo odómetro, ámbar de
   señal de carretera, botones enormes.
------------------------------------------- */

:root {
    --bg:         #0a0a0c;
    --surface:    #15151a;
    --surface-2:  #1c1c23;
    --surface-3:  #262631;
    --line:       rgba(255,255,255,0.07);
    --line-2:     rgba(255,255,255,0.12);
    --text:       #f4f4f6;
    --text-dim:   #b6b6c0;
    --muted:      #7a7a85;

    --accent:     #f59e0b;   /* ámbar señal */
    --accent-hi:  #fbbf24;
    --accent-lo:  #b45309;
    --danger:     #ef4444;
    --ok:         #22c55e;

    --font-display: 'Archivo Black', 'Archivo', system-ui, sans-serif;
    --font-ui:      'Archivo', system-ui, -apple-system, sans-serif;
    --font-mono:    'JetBrains Mono', ui-monospace, 'Cascadia Mono', Menlo, monospace;

    --radius:    14px;
    --radius-lg: 22px;

    --pad: env(safe-area-inset-bottom, 0px);
}

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

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

body {
    min-height: 100svh;
    /* Textura sutil tipo asfalto */
    background-image:
        radial-gradient(1200px 600px at 50% -200px, rgba(245,158,11,0.10), transparent 60%),
        radial-gradient(800px 400px at 100% 100%, rgba(56,189,248,0.04), transparent 60%);
    background-attachment: fixed;
}

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

a { color: var(--accent); text-decoration: none; }

h1, h2, h3 { font-family: var(--font-display); letter-spacing: 0.02em; font-weight: 900; }
h2 { font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--text-dim); margin: 0; }

.muted { color: var(--muted); }

/* ============================================================
   INSTALADOR Y LOGIN
   ============================================================ */
body.install {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: clamp(16px, 4vw, 48px) 16px 80px;
}
.install-shell {
    width: 100%;
    max-width: 720px;
}
.install-shell.narrow { max-width: 440px; }

.install-head {
    margin-bottom: 28px;
}
.logo-block {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}
.logo-mark {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    background: var(--accent);
    color: #1a1208;
    border-radius: 12px;
    font-size: 28px;
    font-weight: 900;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 8px 24px rgba(245,158,11,0.25);
}
.install-head h1 {
    margin: 0;
    font-size: 2rem;
    letter-spacing: 0.04em;
}
.tagline {
    margin: 0;
    color: var(--text-dim);
    font-size: 1rem;
}

.steps {
    list-style: none;
    padding: 0; margin: 18px 0 0;
    display: flex; gap: 8px;
    border-top: 1px solid var(--line);
    padding-top: 16px;
}
.steps li {
    flex: 1;
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
}
.steps li span {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    margin-bottom: 4px;
    color: var(--muted);
}
.steps li.on {
    border-color: var(--accent);
    color: var(--text);
    background: linear-gradient(180deg, rgba(245,158,11,0.10), transparent);
}
.steps li.on span { color: var(--accent); }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: clamp(20px, 4vw, 32px);
    margin-bottom: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.35);
}
.card h2 { margin-bottom: 8px; }
.card .muted { margin: 4px 0 16px; }
.card.success {
    border-color: var(--ok);
    background: linear-gradient(180deg, rgba(34,197,94,0.10), transparent), var(--surface);
}

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin: 16px 0 20px;
}
.grid .span-2 { grid-column: 1 / -1; }

.card label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--text-dim);
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.card input {
    background: var(--surface-2);
    border: 1px solid var(--line-2);
    border-radius: 10px;
    color: var(--text);
    padding: 14px 14px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: var(--font-mono);
}
.card input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(245,158,11,0.15);
}

.btn-primary {
    display: inline-block;
    width: 100%;
    background: var(--accent);
    color: #1a1208;
    border: none;
    border-radius: 12px;
    padding: 18px 22px;
    font-family: var(--font-display);
    font-size: 1rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.08s, background 0.15s;
    box-shadow: 0 8px 24px rgba(245,158,11,0.25);
}
.btn-primary:hover { background: var(--accent-hi); }
.btn-primary:active { transform: translateY(1px); }

.alert {
    background: rgba(239,68,68,0.10);
    border: 1px solid rgba(239,68,68,0.4);
    color: #fecaca;
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 14px;
}
.alert ul { margin: 6px 0 0; padding-left: 20px; }

.install-foot {
    display: flex; justify-content: space-between;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 12px 4px;
}

/* ============================================================
   APP PRINCIPAL
   ============================================================ */
body.app {
    padding-bottom: calc(20px + var(--pad));
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    background: rgba(10,10,12,0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}
.trip-pill {
    justify-self: start;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 14px;
    cursor: pointer;
    max-width: 50vw;
}
.trip-label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--muted);
    letter-spacing: 0.2em;
}
.trip-name {
    font-weight: 800;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40vw;
}
.brand {
    display: flex; align-items: center; gap: 8px;
    justify-self: center;
}
.brand .logo-mark {
    width: 28px; height: 28px;
    font-size: 18px;
    border-radius: 8px;
}
.brand-name {
    font-family: var(--font-display);
    letter-spacing: 0.12em;
    font-size: 0.85rem;
    color: var(--text-dim);
}
.icon-btn {
    justify-self: end;
    width: 44px; height: 44px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    font-size: 22px;
    cursor: pointer;
}

main#mainView {
    padding: 16px;
    max-width: 560px;
    margin: 0 auto;
}

/* Pestañas */
.tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 4px;
    margin-bottom: 22px;
}
.tab {
    background: transparent;
    border: none;
    border-radius: 10px;
    padding: 14px 8px;
    font-family: var(--font-display);
    letter-spacing: 0.1em;
    font-size: 0.78rem;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-transform: uppercase;
}
.tab.on {
    background: var(--surface-3);
    color: var(--text);
}

.panel { display: none; }
.panel.on { display: block; }

/* ---------- Display de cantidad (odómetro) ---------- */
.amount-display {
    text-align: center;
    padding: 28px 16px 18px;
    background:
        radial-gradient(120% 80% at 50% 0%, rgba(245,158,11,0.18), transparent 60%),
        var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    margin-bottom: 18px;
    position: relative;
    overflow: hidden;
}
.amount-display::after {
    content: '';
    position: absolute;
    inset: auto 0 0 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.5;
}
.amount-display .cur {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    color: var(--text-dim);
    margin-right: 6px;
    vertical-align: 6px;
}
.amount-display .amt {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: clamp(3rem, 12vw, 4.6rem);
    color: var(--accent-hi);
    letter-spacing: -0.02em;
    text-shadow: 0 0 24px rgba(245,158,11,0.35);
}

/* ---------- Teclado numérico ---------- */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 26px;
}
.key {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 22px 8px;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.7rem;
    color: var(--text);
    cursor: pointer;
    transition: transform 0.06s, background 0.12s, border-color 0.12s;
    -webkit-tap-highlight-color: transparent;
}
.key:active {
    transform: scale(0.97);
    background: var(--surface-2);
    border-color: var(--accent);
}
.key-soft {
    color: var(--muted);
    background: var(--surface-2);
}

/* ---------- Categorías ---------- */
.section-title {
    margin: 10px 4px 12px;
    font-size: 0.78rem;
    color: var(--muted);
}
.cats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 24px;
}
@media (min-width: 480px) {
    .cats { grid-template-columns: repeat(4, 1fr); }
}
.cat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 18px 6px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    cursor: pointer;
    text-align: center;
    transition: transform 0.06s, border-color 0.15s, background 0.15s;
    min-height: 96px;
    -webkit-tap-highlight-color: transparent;
}
.cat:active { transform: scale(0.97); }
.cat-icon {
    font-size: 1.8rem;
    line-height: 1;
}
.cat-name {
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
}
.cat.pressed {
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--cat) 35%, transparent), transparent 70%),
        var(--surface);
    border-color: var(--cat);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--cat) 30%, transparent);
}

/* ---------- Estado / sync ---------- */
.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    font-size: 0.8rem;
}
.sync {
    font-family: var(--font-mono);
    color: var(--muted);
}
.sync.sync-ok { color: var(--ok); }
.sync.sync-pending { color: var(--accent); }
.sync.sync-error { color: var(--danger); }
.ghost-btn {
    background: transparent;
    border: 1px solid var(--line-2);
    color: var(--text-dim);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.8rem;
    cursor: pointer;
}
.ghost-btn[aria-pressed="true"] {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(245,158,11,0.08);
}

/* ---------- Historial ---------- */
.history-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px;
}
.hist {
    list-style: none;
    padding: 0; margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.hist-empty {
    text-align: center;
    color: var(--muted);
    padding: 24px;
    background: var(--surface);
    border: 1px dashed var(--line-2);
    border-radius: 14px;
}
.hist-row {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
}
.hist-icon {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    border-radius: 12px;
    background: var(--surface-2);
    font-size: 1.2rem;
}
.hist-meta { display: flex; flex-direction: column; min-width: 0; }
.hist-cat {
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hist-sub {
    font-size: 0.75rem;
    color: var(--muted);
    font-family: var(--font-mono);
}
.hist-amount {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.1rem;
}
.hist-row.pending { border-style: dashed; opacity: 0.85; }
.hist-row.pending .hist-amount::after {
    content: '⟳';
    color: var(--accent);
    margin-left: 6px;
    font-size: 0.85rem;
}

/* ---------- Resumen ---------- */
.big-num {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 2.6rem;
    color: var(--accent-hi);
    margin: 6px 0 24px;
    letter-spacing: -0.02em;
}
.bars {
    list-style: none;
    padding: 0; margin: 0;
    display: flex; flex-direction: column; gap: 10px;
}
.bar-row {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    gap: 10px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 14px;
    position: relative;
    overflow: hidden;
}
.bar-fill {
    position: absolute;
    inset: 0 auto 0 0;
    background: linear-gradient(90deg, color-mix(in srgb, var(--cat) 25%, transparent), transparent);
    z-index: 0;
}
.bar-row > * { position: relative; z-index: 1; }
.bar-icon { font-size: 1.1rem; }
.bar-name { font-weight: 700; font-size: 0.95rem; }
.bar-total { font-family: var(--font-mono); font-weight: 700; }

/* ---------- Hojas modales ---------- */
.sheet {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
    display: flex; align-items: flex-end; justify-content: center;
    z-index: 50;
    animation: fadeIn 0.18s ease-out;
}
.sheet[hidden] { display: none; }
.sheet-inner {
    width: 100%;
    max-width: 560px;
    background: var(--surface);
    border-top-left-radius: 28px;
    border-top-right-radius: 28px;
    padding: 16px 20px calc(28px + var(--pad));
    border-top: 1px solid var(--line-2);
    animation: slideUp 0.22s ease-out;
    max-height: 80svh;
    overflow-y: auto;
}
.sheet-handle {
    width: 42px; height: 4px;
    background: var(--line-2);
    border-radius: 99px;
    margin: 4px auto 14px;
}
.sheet h2 { margin-bottom: 14px; font-size: 1.1rem; }
.trip-list { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; }
.trip-row {
    width: 100%;
    text-align: left;
    padding: 16px 14px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
}
.trip-row.on { border-color: var(--accent); background: rgba(245,158,11,0.08); }
.new-trip { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.new-trip input {
    background: var(--surface-2);
    border: 1px solid var(--line-2);
    border-radius: 12px;
    color: var(--text);
    padding: 14px;
    font-size: 1rem;
    outline: none;
}
.new-trip input:focus { border-color: var(--accent); }

.big-link {
    display: block;
    text-align: center;
    padding: 16px;
    background: var(--surface-2);
    border-radius: 12px;
    margin: 8px 0 12px;
    color: var(--text);
    font-weight: 700;
}
.close-sheet { width: 100%; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%; bottom: calc(24px + var(--pad));
    transform: translate(-50%, 20px);
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: 999px;
    padding: 12px 22px;
    font-weight: 700;
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s, transform 0.22s;
    z-index: 100;
}
.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}
.toast.ok { border-color: var(--ok); color: #bbf7d0; }
.toast.err { border-color: var(--danger); color: #fecaca; }

@keyframes fadeIn  { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } }

/* Modo reducido de movimiento */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
