/* =========================================================
   EnvíaYa · Cotizador de envíos
   Mobile‑first. Bottom nav en móvil, se oculta en escritorio.
   ========================================================= */

:root {
    --primary: #0f8af6;
    --primary-dark: #0960ac;
    --accent: #ff8a00;
    --success: #19b36b;
    --danger: #e5484d;
    --bg: #eef3f9;
    --card: #ffffff;
    --text: #1d2939;
    --muted: #667085;
    --border: #dfe5ee;
    --radius: 16px;
    --shadow: 0 6px 20px rgba(16, 40, 80, .08);
    --nav-h: 68px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { line-height: 1.2; }
h2 { font-size: 1.25rem; display: flex; align-items: center; gap: .5rem; }
h2 > i { color: var(--primary); }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between;
    padding: .85rem 1.1rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.brand {
    display: flex; align-items: center; gap: .55rem;
    color: #fff; text-decoration: none; font-size: 1.3rem;
}
.brand i { font-size: 1.5rem; }
.topbar-tag { font-size: .85rem; opacity: .9; display: none; }

/* ---------- Layout ---------- */
.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

.view { display: none; }
.view.active { display: block; animation: aparecer .35s ease; }

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

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; }

/* ---------- Hero ---------- */
.hero {
    display: flex; flex-direction: column; gap: 1.25rem;
    background: linear-gradient(135deg, #0f8af6 0%, #4f46e5 100%);
    color: #fff;
    overflow: hidden;
}
.hero h1 { font-size: 1.6rem; margin-bottom: .5rem; }
.hero p { opacity: .92; margin-bottom: 1rem; }
.hero .btn-primary { background: #fff; color: var(--primary-dark); }

.hero-icons {
    position: relative;
    height: 150px;
    display: grid; place-items: center;
}
.hero-icons .fa-earth-americas { font-size: 7rem; opacity: .25; }
.hero-plane { position: absolute; top: 10px; right: 22%; font-size: 2.6rem; }
.hero-box   { position: absolute; bottom: 8px; left: 22%; font-size: 2.2rem; color: #ffd27a; }

/* ---------- Features ---------- */
.features {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
}
.feature { text-align: center; margin: 0; padding: 1rem .75rem; }
.feature i { font-size: 1.9rem; color: var(--primary); margin-bottom: .5rem; }
.feature h3 { font-size: 1rem; }
.feature p { font-size: .82rem; color: var(--muted); }
.feature:nth-child(2) i { color: var(--accent); }
.feature:nth-child(3) i { color: #4f46e5; }
.feature:nth-child(4) i { color: var(--danger); }

/* ---------- Formulario ---------- */
form h2 { margin-bottom: 1rem; }

fieldset { border: 0; margin-bottom: 1.1rem; }
legend {
    font-size: .8rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted); margin-bottom: .5rem;
}

.segmented {
    display: grid; grid-template-columns: 1fr 1fr; gap: .5rem;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
    display: flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .8rem .5rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: .2s;
    user-select: none;
}
.segmented span:hover { border-color: var(--primary); }
.segmented input:checked + span {
    border-color: var(--primary);
    background: rgba(15,138,246,.08);
    color: var(--primary-dark);
}
.segmented input:focus-visible + span { outline: 3px solid rgba(15,138,246,.35); }

/* Animaciones de Font Awesome aplicadas al seleccionar */
.segmented input[value="nacional"]:checked + span i      { animation: fa-bounce 1s 1; }
.segmented input[value="internacional"]:checked + span i { animation: fa-spin 2s linear infinite; }
.segmented input[value="standard"]:checked + span i      { animation: fa-shake 1s 1; }
.segmented input[value="express"]:checked + span i       { animation: fa-beat-fade 1s infinite; color: var(--accent); }

/* Stepper */
.stepper { display: flex; align-items: center; gap: .5rem; }
.step-btn {
    width: 46px; height: 46px; flex-shrink: 0;
    border: 0; border-radius: 12px;
    background: var(--primary); color: #fff; font-size: 1rem;
    cursor: pointer; transition: .2s;
}
.step-btn:hover { background: var(--primary-dark); }
.step-btn:active i { animation: fa-beat .4s 1; }
.step-value {
    flex: 1; display: flex; align-items: center; gap: .5rem;
    border: 2px solid var(--border); border-radius: 12px; padding: 0 .9rem;
}
.step-value i { color: var(--primary); }
.step-value input { border: 0; text-align: center; font-weight: 700; font-size: 1.1rem; }
.step-value input:focus { box-shadow: none; }

/* Campos */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .75rem; }
.field { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 600; }
.field span i { color: var(--primary); width: 1.1em; }
.field small { color: var(--muted); font-weight: 400; }

input[type="number"] {
    width: 100%;
    padding: .75rem .8rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    font: inherit; font-size: 1rem;
    color: var(--text);
    background: #fff;
    outline: none;
    transition: .2s;
    -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type="number"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,138,246,.15); }
input.invalid { border-color: var(--danger); animation: fa-shake .5s 1; }

.error {
    display: flex; align-items: center; gap: .5rem;
    color: var(--danger); background: #fdecec;
    padding: .65rem .8rem; border-radius: 10px; margin-bottom: 1rem; font-size: .9rem;
}
.error[hidden] { display: none; }

/* ---------- Botones ---------- */
.actions { display: grid; grid-template-columns: 1fr 2fr; gap: .5rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .85rem 1.2rem;
    border: 2px solid transparent; border-radius: 12px;
    font: inherit; font-weight: 700;
    cursor: pointer; transition: .2s;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary-dark); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--danger); border-color: var(--danger); }
.btn-sm { padding: .45rem .8rem; font-size: .85rem; }
.btn:disabled { opacity: .7; cursor: wait; }

/* Animaciones FA al pasar el mouse */
.btn-primary:hover i     { animation: fa-wag 1s infinite; }
.btn-ghost:hover .fa-rotate     { animation: fa-spin 1s linear infinite; }
.btn-ghost:hover .fa-trash-can  { animation: fa-shake 1s infinite; }

/* ---------- Resultado ---------- */
.result[hidden] { display: none; }
.result { border-top: 5px solid var(--success); animation: aparecer .4s ease; }
.result-head { display: flex; gap: .85rem; align-items: center; margin-bottom: 1rem; }
.result-head > i { font-size: 2.4rem; color: var(--success); }
.result-head p { color: var(--muted); font-size: .9rem; }

.breakdown { list-style: none; }
.breakdown li {
    display: flex; justify-content: space-between; gap: .5rem;
    padding: .55rem 0; border-bottom: 1px dashed var(--border); font-size: .92rem;
}
.breakdown li span { color: var(--muted); }
.breakdown li span i { width: 1.3em; color: var(--primary); }
.breakdown li.hl { background: rgba(15,138,246,.06); margin: 0 -.5rem; padding: .55rem .5rem; border-radius: 8px; }
.breakdown li.hl strong { color: var(--primary-dark); }
.breakdown li[hidden] { display: none; }

.total {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 1rem; padding: 1rem;
    background: linear-gradient(135deg, var(--success), #0f9b8e);
    color: #fff; border-radius: 12px;
}
.total strong { font-size: 1.6rem; }
.eta { margin-top: .8rem; color: var(--muted); font-size: .9rem; }
.eta i { color: var(--accent); }

/* ---------- Historial ---------- */
.history { list-style: none; }
.history li {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem; border-radius: 12px; background: var(--bg); margin-bottom: .5rem;
}
.history .h-icon {
    width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
    display: grid; place-items: center; background: var(--primary); color: #fff;
}
.history .h-icon.express { background: var(--accent); }
.history .h-info { flex: 1; font-size: .85rem; }
.history .h-info strong { display: block; font-size: .95rem; }
.history .h-info small { color: var(--muted); }
.history .h-price { font-weight: 700; color: var(--success); }
.history li:hover .h-icon i { animation: fa-bounce 1s 1; }

.empty { text-align: center; color: var(--muted); padding: 1.5rem 0; }
.empty i { display: block; font-size: 2.5rem; margin-bottom: .5rem; color: var(--border); }
.empty[hidden] { display: none; }

/* ---------- Tarifas ---------- */
.table-wrap { overflow-x: auto; margin: 1rem 0; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; min-width: 420px; }
th, td { padding: .65rem .5rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; }
td i { color: var(--primary); margin-right: .25rem; }
.note { display: flex; gap: .5rem; font-size: .85rem; color: var(--muted); }
.note i { color: #f5b301; margin-top: .2rem; }
.carriers { display: flex; justify-content: center; gap: 1.5rem; font-size: 2.6rem; color: var(--muted); margin-top: 1rem; }
.carriers i { transition: color .2s; }
.carriers i:hover { color: var(--primary); animation: fa-flip 1s 1; }

/* ---------- Footer ---------- */
.footer { text-align: center; padding: 1rem 1rem 1.5rem; color: var(--muted); font-size: .85rem; }
.footer a { color: var(--muted); font-size: 1.4rem; margin: 0 .5rem; transition: .2s; }
.footer a:hover { color: var(--primary); }
.footer a:hover i { animation: fa-bounce 1s infinite; }
.footer p { margin-top: .5rem; }

/* ---------- Bottom nav (estilo app móvil) ---------- */
.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    display: grid; grid-template-columns: repeat(4, 1fr);
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(16,40,80,.08);
}
.nav-item {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem;
    color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
    transition: color .2s;
}
.nav-item i { font-size: 1.3rem; }
.nav-item.active { color: var(--primary); }
.nav-item.active::before {
    content: ""; position: absolute; top: 0;
    width: 36px; height: 4px; border-radius: 0 0 4px 4px; background: var(--primary);
}

/* =========================================================
   Tablet
   ========================================================= */
@media (min-width: 600px) {
    .topbar-tag { display: block; }
    .features { grid-template-columns: repeat(4, 1fr); }
    .hero { flex-direction: row; align-items: center; }
    .hero-text { flex: 1.3; }
    .hero-icons { flex: 1; height: 200px; }
    .hero h1 { font-size: 2rem; }
}

/* =========================================================
   Escritorio: se oculta la bottom nav y todo se acomoda en grid
   ========================================================= */
@media (min-width: 992px) {
    body { padding-bottom: 0; }

    .bottom-nav { display: none; }

    .app {
        display: grid;
        grid-template-columns: 1.25fr 1fr;
        grid-template-areas:
            "inicio    inicio"
            "cotizar   historial"
            "cotizar   tarifas";
        grid-template-rows: auto auto 1fr;
        gap: 1.25rem;
        padding: 1.5rem;
    }

    /* Todas las vistas visibles en escritorio */
    .view, .view.active { display: block; animation: none; }

    #inicio    { grid-area: inicio; }
    #cotizar   { grid-area: cotizar; }
    #historial { grid-area: historial; }
    #tarifas   { grid-area: tarifas; align-self: start; }

    .hero { padding: 2rem 2.5rem; }
    .hero h1 { font-size: 2.4rem; }
    .hero-icons .fa-earth-americas { font-size: 9rem; }

    .history { max-height: 320px; overflow-y: auto; }

    .card { padding: 1.5rem; }
}
.btn[hidden] { display: none; }
