/* Frande One · Calculadora de costo de WhatsApp
   Solo el componente de la calculadora; el resto de la página usa el sistema de la landing (tokens --fo-*). */

.calc {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    gap: var(--fo-space-6);
    align-items: start;
}

/* ---------- Formulario ---------- */
.calc-form {
    display: grid;
    gap: var(--fo-space-5);
    margin: 0;
    padding: var(--fo-space-5);
    background: var(--fo-surface);
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-lg);
    box-shadow: var(--fo-shadow-sm);
}

.calc-group {
    border: 0;
    margin: 0;
    padding: 0;
    display: grid;
    gap: var(--fo-space-4);
    min-width: 0;
}

.calc-group > legend {
    padding: 0;
    margin-bottom: var(--fo-space-2);
    font-family: var(--fo-font-display);
    font-size: var(--fo-text-xl);
    font-weight: 700;
    color: var(--fo-foreground);
}

.calc-field {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 8.5rem;
    gap: var(--fo-space-2) var(--fo-space-4);
    align-items: center;
}

.calc-field label {
    font-weight: 600;
    color: var(--fo-foreground);
    line-height: 1.35;
}

.calc-field .calc-hint {
    grid-column: 1 / -1;
    margin: 0;
    font-size: var(--fo-text-sm);
    line-height: 1.5;
    color: var(--fo-muted);
}

.calc-field input[type="number"] {
    width: 100%;
    min-height: 2.75rem;
    padding: 0 var(--fo-space-3);
    font: 600 var(--fo-text-lg) / 1 var(--fo-font-mono);
    text-align: right;
    color: var(--fo-foreground);
    background: var(--fo-background);
    border: 1px solid var(--fo-border-strong);
    border-radius: var(--fo-radius-md);
    -moz-appearance: textfield;
    appearance: textfield;
}

.calc-field input[type="number"]::-webkit-outer-spin-button,
.calc-field input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.calc-field input[type="range"] {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 1.75rem;
    accent-color: var(--fo-primary);
}

.calc-field input:focus-visible,
.calc-more > summary:focus-visible {
    outline: 3px solid var(--fo-focus);
    outline-offset: 2px;
}

.calc-sum {
    margin: 0;
    padding: var(--fo-space-3) var(--fo-space-4);
    background: var(--fo-primary-soft);
    border-radius: var(--fo-radius-md);
    color: var(--fo-foreground);
    line-height: 1.5;
}

.calc-sum b {
    font-family: var(--fo-font-mono);
}

.calc-more {
    border-top: 1px dashed var(--fo-border-strong);
    padding-top: var(--fo-space-4);
}

.calc-more > summary {
    cursor: pointer;
    min-height: 2.75rem;
    display: flex;
    align-items: center;
    font-weight: 600;
    color: var(--fo-link);
    border-radius: var(--fo-radius-sm);
}

.calc-more[open] > summary {
    margin-bottom: var(--fo-space-4);
}

/* ---------- Recibo ---------- */
.calc-receipt {
    position: sticky;
    top: calc(var(--fo-header-h) + var(--fo-space-4));
    padding: var(--fo-space-6) var(--fo-space-5) var(--fo-space-5);
    background: var(--fo-surface);
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-lg);
    box-shadow: var(--fo-shadow-lg);
    /* borde superior dentado, como un recibo recién cortado */
    -webkit-mask: radial-gradient(0.55rem at 0.9rem 0, transparent 97%, #000) -0.9rem 0 / 1.8rem 100%;
    mask: radial-gradient(0.55rem at 0.9rem 0, transparent 97%, #000) -0.9rem 0 / 1.8rem 100%;
}

.calc-receipt-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--fo-space-2);
    padding-bottom: var(--fo-space-4);
    border-bottom: 1px dashed var(--fo-border-strong);
    font: 600 var(--fo-text-xs) / 1.4 var(--fo-font-mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--fo-muted);
}

.calc-lines {
    list-style: none;
    margin: 0;
    padding: var(--fo-space-4) 0;
    display: grid;
    gap: var(--fo-space-4);
    border-bottom: 1px dashed var(--fo-border-strong);
}

.calc-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--fo-space-1) var(--fo-space-4);
    align-items: baseline;
}

.calc-line-name {
    font-weight: 600;
    color: var(--fo-foreground);
}

.calc-line-cost {
    font: 600 var(--fo-text-lg) / 1.2 var(--fo-font-mono);
    color: var(--fo-foreground);
    white-space: nowrap;
}

.calc-line-detail {
    grid-column: 1 / -1;
    font: 500 var(--fo-text-sm) / 1.5 var(--fo-font-mono);
    color: var(--fo-muted);
}

.calc-line-free {
    color: var(--fo-success);
    font-weight: 600;
}

.calc-line.is-zero .calc-line-name,
.calc-line.is-zero .calc-line-cost {
    color: var(--fo-muted);
    font-weight: 500;
}

.calc-meter {
    grid-column: 1 / -1;
    display: flex;
    height: 0.5rem;
    border-radius: var(--fo-radius-pill);
    overflow: hidden;
    background: var(--fo-surface-sunken);
}

.calc-meter i {
    display: block;
    height: 100%;
    transition: width var(--fo-duration) var(--fo-ease);
}

.calc-meter i:first-child {
    background: var(--fo-success);
}

.calc-meter i:last-child {
    background: var(--fo-primary);
}

.calc-total {
    display: grid;
    gap: var(--fo-space-1);
    padding-top: var(--fo-space-4);
}

.calc-total-label {
    font: 600 var(--fo-text-xs) / 1.4 var(--fo-font-mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--fo-muted);
}

.calc-total-usd {
    font-family: var(--fo-font-display);
    font-size: clamp(2.4rem, 6vw, 3.4rem);
    font-weight: 800;
    line-height: 1;
    color: var(--fo-foreground);
}

.calc-total-usd small {
    font: 600 var(--fo-text-md) / 1 var(--fo-font-body);
    color: var(--fo-muted);
}

.calc-total-dop {
    font: 600 var(--fo-text-lg) / 1.4 var(--fo-font-mono);
    color: var(--fo-foreground-secondary);
}

.calc-note {
    margin: var(--fo-space-4) 0 0;
    font-size: var(--fo-text-sm);
    line-height: 1.55;
    color: var(--fo-muted);
}

.calc-receipt[aria-busy="true"] .calc-lines,
.calc-receipt[aria-busy="true"] .calc-total {
    opacity: 0.55;
}

.calc-error {
    margin: var(--fo-space-4) 0 0;
    padding: var(--fo-space-4);
    background: var(--fo-warning-soft);
    color: var(--fo-warning);
    border-radius: var(--fo-radius-md);
    line-height: 1.5;
}

.calc-error a {
    color: inherit;
    font-weight: 600;
}

/* ---------- Tabla de tarifas ---------- */
.calc-rates {
    width: 100%;
    border-collapse: collapse;
    background: var(--fo-surface);
    border: 1px solid var(--fo-border);
    border-radius: var(--fo-radius-md);
    overflow: hidden;
}

.calc-rates caption {
    caption-side: bottom;
    padding-top: var(--fo-space-3);
    text-align: left;
    font-size: var(--fo-text-sm);
    line-height: 1.5;
    color: var(--fo-muted);
}

.calc-rates th,
.calc-rates td {
    padding: var(--fo-space-3) var(--fo-space-4);
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--fo-border);
    line-height: 1.5;
}

.calc-rates thead th {
    font-size: var(--fo-text-sm);
    color: var(--fo-muted);
    background: var(--fo-surface-sunken);
}

.calc-rates tbody tr:last-child th,
.calc-rates tbody tr:last-child td {
    border-bottom: 0;
}

.calc-rates td.calc-rate {
    font: 600 var(--fo-text-md) / 1.5 var(--fo-font-mono);
    white-space: nowrap;
}

.calc-rates-wrap {
    overflow-x: auto;
}

@media (max-width: 900px) {
    .calc {
        grid-template-columns: minmax(0, 1fr);
    }

    .calc-receipt {
        position: static;
    }
}

@media (max-width: 600px) {
    /* La tabla de tarifas se lee como fichas: una por tipo de mensaje */
    .calc-rates thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    .calc-rates tr,
    .calc-rates th,
    .calc-rates td {
        display: block;
    }

    .calc-rates tbody th {
        padding-bottom: 0;
        border-bottom: 0;
    }

    .calc-rates td.calc-rate {
        padding-top: var(--fo-space-1);
        padding-bottom: 0;
        border-bottom: 0;
        font-size: var(--fo-text-lg);
    }

    .calc-rates tbody td:last-child {
        padding-top: var(--fo-space-1);
        color: var(--fo-foreground-secondary);
    }

    .calc-rates tbody tr:last-child td:last-child {
        border-bottom: 0;
    }
}

@media (max-width: 480px) {
    .calc-field {
        grid-template-columns: minmax(0, 1fr);
    }

    .calc-field input[type="number"] {
        text-align: left;
    }
}

@media (prefers-reduced-motion: reduce) {
    .calc-meter i {
        transition: none;
    }
}
