/*
 * CollatCred — Calculator Styles
 * All styles scoped to dynamic_calculator.html.
 * Depends on: variables.css (loaded before this file)
 *
 * Mobile layout philosophy:
 *   - No arbitrary height caps. Layout naturally compresses by:
 *     tightening padding/gap, reducing font clamps, collapsing the
 *     two-column main grid to a single column with a more compact
 *     arrangement. The gauge row merges inline with the credit output
 *     on mobile to eliminate one full data-box height.
 *   - Tier selection: card grid hidden on mobile, compact <select>
 *     shown in its place. Same data source, same activation path.
 *   - Desktop is pixel-identical — all mobile rules are inside
 *     max-width: 599px media queries.
 */

/* ── Body (calculator iframe context) ───────────────── */

body {
    font-family: var(--font-sans, 'Inter', sans-serif);
    background-color: transparent;
    color: var(--color-text-primary, #f5f5f7);
    -webkit-font-smoothing: antialiased;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    box-sizing: border-box;
    width: 100%;
}

.mono { font-family: var(--font-mono, 'JetBrains Mono', monospace); }

/* ── Engine Card ─────────────────────────────────────── */

.engine-card {
    background: linear-gradient(180deg,
        rgba(15,17,21,0.7)  0%,
        rgba(5,7,10,0.85)  100%);
    backdrop-filter: blur(32px);
    -webkit-backdrop-filter: blur(32px);
    border: 1px solid rgba(255,255,255,0.06);
    border-top: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 20px 40px -10px rgba(0,0,0,0.5);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 1000px;
    padding: clamp(12px, 3.5vw, 24px) clamp(12px, 3.5vw, 32px);
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 2.5vw, 18px);
    box-sizing: border-box;
    min-width: 0;
}

@media (max-width: 480px) {
    .engine-card { border-radius: var(--radius-md); }
}

/* ── Engine Header ───────────────────────────────────── */

.engine-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    padding-bottom: clamp(12px, 2.5vw, 20px);
}

/* ── Engine Title ────────────────────────────────────── */

.engine-title {
    font-size: clamp(1.5rem, 6vw, 3rem);
    font-weight: 900;
    color: white;
    letter-spacing: -0.04em;
    line-height: 1.1;
}

/* ── Custom Coin Dropdown ────────────────────────────── */

/*
 * .coin-dropdown-root  — relative wrapper (holds trigger + floating panel)
 * .cd-trigger          — the always-visible selected-value button
 * .cd-panel            — the floating list, position:absolute, z-indexed
 * .cd-list             — scrollable inner container with capped height
 * .cd-group            — tier group wrapper
 * .cd-group-label      — dim uppercase label separating groups
 * .cd-option           — individual coin row
 */

.coin-dropdown-root {
    position: relative;
    width: 100%;
    user-select: none;
}

/* ── Trigger button ──────────────────────────────────── */

.cd-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(34,211,238,0.25);
    border-radius: var(--radius-md);
    color: var(--color-text-primary, #f5f5f7);
    font-family: var(--font-sans, 'Inter', sans-serif);
    cursor: pointer;
    min-height: 52px;
    box-sizing: border-box;
    transition:
        border-color 200ms ease,
        background   200ms ease,
        box-shadow   200ms ease;
    text-align: left;
}

.cd-trigger:hover {
    background: rgba(255,255,255,0.05);
    border-color: rgba(34,211,238,0.45);
}

.cd-trigger:focus-visible {
    outline: none;
    border-color: rgba(34,211,238,0.7);
    box-shadow: 0 0 0 3px rgba(34,211,238,0.12);
}

.cd-trigger[aria-expanded="true"] {
    border-color: rgba(34,211,238,0.6);
    background: rgba(34,211,238,0.04);
    box-shadow: 0 0 0 3px rgba(34,211,238,0.10);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.cd-trigger-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.cd-trigger-name {
    font-size: 0.875rem;
    font-weight: 700;
    color: #f5f5f7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.cd-trigger-meta {
    font-size: 0.6875rem;
    font-weight: 500;
    color: rgba(34,211,238,0.7);
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    letter-spacing: 0.02em;
}

.cd-trigger-chevron {
    color: rgba(34,211,238,0.6);
    flex-shrink: 0;
    transition: transform 200ms ease;
    display: flex;
    align-items: center;
}

.cd-trigger[aria-expanded="true"] .cd-trigger-chevron {
    transform: rotate(180deg);
}

/* ── Floating panel ──────────────────────────────────── */

.cd-panel {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 50;
    background: linear-gradient(180deg, #0e1115 0%, #080a0d 100%);
    border: 1px solid rgba(34,211,238,0.30);
    border-top: 1px solid rgba(34,211,238,0.12);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow:
        0 20px 40px -8px rgba(0,0,0,0.7),
        0 0 0 1px rgba(255,255,255,0.04) inset;
    overflow: hidden;

    /* Hidden state */
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
    transition:
        opacity   180ms ease,
        transform 180ms ease;
}

.cd-panel.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* ── Scrollable list ─────────────────────────────────── */

.cd-list {
    max-height: 380px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px 0;
}

/* Custom scrollbar — webkit */
.cd-list::-webkit-scrollbar { width: 4px; }
.cd-list::-webkit-scrollbar-track { background: transparent; }
.cd-list::-webkit-scrollbar-thumb {
    background: rgba(34,211,238,0.25);
    border-radius: 2px;
}
.cd-list::-webkit-scrollbar-thumb:hover {
    background: rgba(34,211,238,0.45);
}
/* Firefox */
.cd-list { scrollbar-width: thin; scrollbar-color: rgba(34,211,238,0.25) transparent; }

/* ── Group headers ───────────────────────────────────── */

.cd-group { padding-top: 4px; }
.cd-group + .cd-group {
    border-top: 1px solid rgba(255,255,255,0.05);
    margin-top: 4px;
    padding-top: 8px;
}

.cd-group-label {
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.25);
    padding: 2px 16px 6px;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
}

/* ── Option rows ─────────────────────────────────────── */

.cd-option {
    display: grid;
    grid-template-columns: 52px 1fr auto 20px;
    align-items: center;
    gap: 0 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 140ms ease;
    outline: none;
    min-width: 0;
}

.cd-option:hover,
.cd-option:focus {
    background: rgba(255,255,255,0.05);
}

.cd-option.selected {
    background: rgba(34,211,238,0.07);
}

.cd-option-code {
    font-size: 0.8125rem;
    font-weight: 800;
    color: #ffffff;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.cd-option-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: rgba(255,255,255,0.65);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.cd-option-meta {
    font-size: 0.6875rem;
    font-weight: 600;
    color: rgba(34,211,238,0.55);
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.cd-option-check {
    color: rgba(34,211,238,0.9);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 150ms ease, transform 150ms ease;
    flex-shrink: 0;
}

.cd-option.selected .cd-option-check {
    opacity: 1;
    transform: scale(1);
}

/* ── Mobile sizing (max-width: 599px) ────────────────── */

@media (max-width: 599px) {
    .cd-list {
        max-height: 260px;
    }

    .cd-option {
        grid-template-columns: 44px 1fr auto 18px;
        gap: 0 8px;
        padding: 10px 14px;
    }

    .cd-option-code  { font-size: 0.75rem; }
    .cd-option-name  { font-size: 0.75rem; }
    .cd-option-meta  { font-size: 0.625rem; }
    .cd-trigger-name { font-size: 0.8125rem; }
}

/* ── Collateral Input ────────────────────────────────── */

.input-ghost {
    background: transparent;
    border: none;
    outline: none;
    color: white;
    font-weight: 800;
    width: 100%;
    min-width: 0;
    text-shadow: 0 0 15px rgba(255,255,255,0.1);
}

.collateral-input-row {
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
}

.collateral-input-row .rupee-prefix {
    font-size: clamp(1.5rem, 6vw, 2.25rem);
    font-family: var(--font-sans);
    font-weight: 700;
    color: var(--color-text-muted);
    margin-right: 6px;
    flex-shrink: 0;
}

.collateral-input-size {
    font-size: clamp(1.75rem, 8vw, 3rem);
    font-family: var(--font-sans);
}

/* ── Range Slider ────────────────────────────────────── */

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.1);
    outline: none;
    touch-action: pan-y;
    margin-top: 10px;
    box-sizing: border-box;
    max-width: 100%;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--color-brand);
    cursor: pointer;
    margin-top: -8px;
    box-shadow: 0 0 10px var(--color-brand-glow);
    border: 2px solid #000;
    transition: transform var(--dur-fast) ease;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type=range]::-webkit-slider-thumb:active {
    transform: scale(1.1);
    box-shadow:
        0 0 0 6px var(--color-brand-dim),
        0 0 10px var(--color-brand-glow);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
}

/* ── Data Boxes ──────────────────────────────────────── */

.data-box {
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: var(--radius-md);
    padding: clamp(14px, 3vw, 20px) clamp(14px, 3vw, 24px);
    box-sizing: border-box;
    min-width: 0;
}

.data-box.highlight {
    border-color: rgba(34,211,238,0.14);
    background: radial-gradient(120% 120% at 0% 0%,
        rgba(34,211,238,0.07) 0%,
        rgba(0,0,0,0.3)       100%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}

@media (max-width: 480px) {
    .data-box { border-radius: var(--radius-sm); }
}

/* ── Credit Output ───────────────────────────────────── */

.credit-output {
    font-size: clamp(1.8rem, 9vw, 3.5rem);
    font-weight: 900;
    color: white;
    letter-spacing: -0.04em;
    margin-bottom: 0.5rem;
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.1;
}

/* ── Gauge ───────────────────────────────────────────── */

.gauge-svg {
    width: 90px;
    height: 50px;
    overflow: visible;
    flex-shrink: 0;
}

.gauge-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}

.gauge-right {
    text-align: right;
    min-width: 0;
    flex-shrink: 1;
}

@media (max-width: 480px) {
    .gauge-row { flex-wrap: wrap; }
}

/* ── Stats Grid ──────────────────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.05);
    background: rgba(255,255,255,0.05);
}

.stats-cell {
    background: var(--color-surface-2, #0b0d10);
    padding: 12px;
    min-width: 0;
}

.stats-cell + .stats-cell {
    border-left: 1px solid rgba(255,255,255,0.05);
}

.stats-val {
    font-size: clamp(0.75rem, 2.8vw, 1.15rem);
    font-weight: 700;
    font-family: var(--font-mono);
    word-break: break-word;
    overflow-wrap: break-word;
}

.stats-label {
    font-size: clamp(10px, 2vw, 11px);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── CTA Button ──────────────────────────────────────── */

.btn-gradient {
    background: linear-gradient(90deg, var(--color-brand) 0%, var(--color-blue) 100%);
    color: #000;
    font-weight: 700;
    transition:
        transform   var(--dur-base) var(--ease-spring),
        box-shadow  var(--dur-base) ease;
    box-shadow: 0 6px 15px -3px var(--color-brand-glow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    text-align: center;
    border-radius: var(--radius-md);
    padding: 14px 24px;
    font-size: 0.875rem;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.btn-gradient:hover {
    transform: translateY(var(--lift-sm));
    box-shadow: 0 10px 20px -3px var(--color-brand-glow);
}

.btn-gradient:active {
    transform: translateY(1px);
    box-shadow: 0 4px 8px -2px var(--color-brand-glow-sm);
}

/* ════════════════════════════════════════════════════════
   MOBILE LAYOUT REDESIGN  (max-width: 599px)
   ════════════════════════════════════════════════════════
 *
 * Goal: the full calculator fits in one mobile screen without
 * artificial height caps. Every reduction is earned by:
 *   1. Tighter gaps and padding on the engine-card
 *   2. Compressed engine-header (smaller title clamp)
 *   3. Smaller collateral input text (tighter clamp ceiling)
 *   4. Gauge merged into the credit output box (no separate box)
 *   5. Tighter stats-cell padding
 *   6. Tighter CTA padding
 *
 * Desktop/tablet (≥ 600px) is completely unaffected.
 */

@media (max-width: 599px) {

    /* Card: tighter gap and padding */
    .engine-card {
        gap: 10px;
        padding: 14px 14px;
    }

    /* Header: less breathing room below the fold */
    .engine-header {
        gap: 4px;
        padding-bottom: 10px;
    }

    /* Title: cap at 1.75rem on mobile — still large, not oversized */
    .engine-title {
        font-size: clamp(1.25rem, 6vw, 1.75rem);
    }

    /* Collateral input: tighter number size */
    .collateral-input-size {
        font-size: clamp(1.5rem, 7.5vw, 2.25rem);
    }

    .collateral-input-row .rupee-prefix {
        font-size: clamp(1.25rem, 5.5vw, 1.75rem);
    }

    /* Data boxes: tighter padding */
    .data-box {
        padding: 12px 14px;
    }

    /* Credit output: tighter clamp so it doesn't dominate */
    .credit-output {
        font-size: clamp(1.6rem, 8vw, 2.5rem);
        margin-bottom: 0.3rem;
    }

    /* Gauge row: compact horizontal layout preserved, no wrap needed */
    .gauge-row {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .gauge-svg {
        width: 72px;
        height: 40px;
    }

    /* Stats cells: tighter padding */
    .stats-cell {
        padding: 9px 10px;
    }

    /* CTA: tighter vertical padding, smaller font, ensure it fits */
    .btn-gradient {
        padding: 12px 16px;
        font-size: 0.8125rem;
        gap: 8px;
        max-width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }

    /* ── Fix 1: text clipping in highlight box ── */
    /*
     * The parent has overflow:hidden (via Tailwind class) which clips
     * the absolute "0% Tax" badge on very narrow screens.
     * Override: let the box grow to reveal content, reposition the
     * badge so it never overlaps the LTV label text.
     */
    .data-box.highlight {
        overflow: visible;
    }

    .data-box.highlight .absolute {
        /* Reflow badge from absolute to inline so it never clips text */
        position: static;
        display: inline-flex;
        align-self: flex-start;
        margin-bottom: 6px;
    }

    /* LTV label: allow wrapping so long strings don't truncate */
    #ltv-label {
        white-space: normal;
        word-break: break-word;
        overflow-wrap: break-word;
        padding-right: 0;
    }

}
