/* =========================================================================
   Global mobile responsiveness overrides.
   Targeted, defensive rules — does NOT touch Laravel Breeze / Tailwind
   primitives (button, input padding, .container, .card from frameworks).
   Only the project's own custom classes are overridden.
   ========================================================================= */

/* Safety net: prevent horizontal page scroll */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

img {
    max-width: 100%;
    height: auto;
}

/* Videos / canvas / svg get max-width but NOT height:auto — that would override
   explicit heights like height:100vh on background videos. */
canvas,
svg {
    max-width: 100%;
}

video {
    max-width: 100%;
}

/* Allow .video-background elements to fill the viewport — just override any
   constraint coming from the global image/video max-width rule above. */
.video-background {
    max-width: none !important;
}

/* Keep progress / scale bars inside their parent on every screen size */
#progress-container,
#progress-bar,
.progress-container,
.progress-bar,
.progress,
.bmi-scale,
.bmi-indicator,
.probability-meter,
.probability-fill,
.ecg-visual {
    max-width: 100%;
    box-sizing: border-box;
}

/* Welcome page navbar had width: calc(100% - 65px) leaving a strip uncovered.
   Force full width and keep right-alignment of items. */
nav.navbar {
    width: 100% !important;
    left: 0 !important;
    right: 0 !important;
    justify-content: flex-end !important;
}

/* Step5 forgot to style .btn-prev — match the gray gradient used on other steps. */
.btn-prev {
    background: linear-gradient(to right, #64748b, #94a3b8) !important;
    color: white !important;
    box-shadow: 0 4px 6px -1px rgba(100, 116, 139, 0.3), 0 2px 4px -1px rgba(100, 116, 139, 0.1) !important;
}

.btn-prev:hover {
    background: linear-gradient(to right, #475569, #64748b) !important;
}

/* ===== Tablet and below ===== */
@media (max-width: 992px) {

    /* Custom dashboards used inside the predict form collapse to one column */
    .vitals-dashboard,
    .clinical-console {
        grid-template-columns: 1fr !important;
    }

    .bmi-widget {
        grid-column: span 1 !important;
    }
}

/* ===== Phone breakpoint ===== */
@media (max-width: 640px) {

    /* Body padding only on the OLD predict-form (which used <body style="padding:20px"> via CSS) */
    body {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* Generic headings */
    h1 {
        font-size: 1.4rem !important;
        line-height: 1.3;
    }

    h2 {
        font-size: 1.2rem !important;
    }

    /* === Project-specific custom containers (NOT Tailwind .container) === */
    .form-container,
    .clinical-console {
        max-width: 100% !important;
        padding: 16px !important;
        margin: 8px auto !important;
        border-radius: 12px !important;
    }

    /* Force flex/grid rows to stack on phones — only project's custom rows */
    .form-row,
    .toggle-group,
    .lipid-panel,
    .advanced-blood-panel,
    .bp-widgets,
    .section-row,
    .section-row.reverse {
        flex-direction: column !important;
        flex-wrap: wrap !important;
        gap: 14px !important;
    }

    /* Cards inside those rows take the full width */
    .form-group,
    .age-card,
    .gender-card,
    .lipid-card,
    .advanced-lab-card,
    .toggle-card,
    .vital-widget,
    .bmi-widget,
    .clinical-panel,
    .card-text,
    .card-style {
        flex: 1 1 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        padding: 14px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        border-radius: 12px !important;
        box-sizing: border-box;
    }

    /* Inputs inside the project's custom cards (NOT global input rule) */
    .form-group input[type="text"],
    .form-group input[type="email"],
    .form-group input[type="password"],
    .form-group input[type="number"],
    .form-group input[type="tel"],
    .form-group input[type="date"],
    .form-group select,
    .form-group textarea,
    .age-card input,
    .gender-card select,
    .lipid-input,
    .lab-input,
    .vital-input,
    .ecg-input {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 16px !important;
        box-sizing: border-box;
    }

    /* Override the huge inline width="770px" on step1 age input */
    .form-group input[style*="770px"] {
        width: 100% !important;
    }

    /* The "age" big number input in predict-form */
    .age-card input[type="number"] {
        width: 100% !important;
        font-size: 1.6rem !important;
    }

    .age-unit {
        position: static !important;
        display: block;
        margin-top: 6px;
        text-align: center;
    }

    /* Unit suffixes inside inputs — move below to avoid overlap on narrow screens */
    .lipid-unit,
    .input-unit,
    .vital-unit,
    .ecg-unit {
        position: static !important;
        display: inline-block;
        transform: none !important;
        margin-top: 6px;
        margin-left: 4px;
        font-size: 0.85rem;
        color: #64748b;
    }

    .vital-input-group,
    .bp-input-container {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .vital-unit {
        margin-left: 0 !important;
        margin-top: 4px;
    }

    /* Toggle / radio cards */
    .toggle-options {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .toggle-option {
        flex: 1 1 45% !important;
        font-size: 0.95rem !important;
    }

    /* === Predict-form navigation buttons (the .buttons row only) === */
    .buttons {
        flex-direction: column !important;
        gap: 14px !important;
    }

    .buttons button {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    /* Predict-form-stepN footer: Prev + Next stack vertically with breathing room */
    .form-footer {
        flex-direction: column !important;
        gap: 14px !important;
        margin-top: 1.5rem !important;
    }

    .form-footer .btn {
        width: 100% !important;
        margin: 0 !important;
        justify-content: center !important;
    }

    /* The next button had margin-left:auto pushing it to the right on desktop */
    .form-footer .btn-next {
        margin-left: 0 !important;
    }

    /* Bubble navigation: allow horizontal scroll instead of overflowing the page */
    .bubble-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        max-width: 100% !important;
    }

    .progress-line {
        max-width: 100% !important;
    }

    /* Welcome page: model-performance card was overflowing because padding + content > viewport */
    .model-performance,
    section.how-it-works .card,
    .card-text {
        max-width: 100% !important;
        width: 100% !important;
    }

    .stat-item {
        min-width: 0 !important;
        flex: 1 1 45% !important;
    }

    /* Progress / step indicators */
    .step-label {
        font-size: 1.05rem !important;
        padding-left: 10px !important;
        margin-bottom: 16px !important;
    }

    /* BMI scale labels — keep readable, allow wrap */
    .bmi-labels {
        flex-wrap: wrap !important;
        gap: 4px;
        font-size: 0.7rem !important;
    }

    .bmi-labels span {
        flex: 1 1 45%;
    }

    /* Range-visual labels (step 3): keep each label under its tick.
       For well-spaced bars (≥17% intervals) a small font keeps them on one row.
       For tight bars (10–12.5% intervals) some labels are zig-zagged to a 2nd row. */
    .range-visual {
        margin-bottom: 1.75rem !important;
    }

    .range-label {
        font-size: 0.55rem !important;
        letter-spacing: -0.02em;
        white-space: nowrap;
        line-height: 1;
        top: 10px !important;
    }

    /* Drop alternate labels of the crowded bars to a 2nd line.
       Selected by their inline `left:` percentage so we only touch the tight ones. */
    .range-label[style*="left: 27.5%"],
    .range-label[style*="left: 55%"],
    .range-label[style*="left: 43.3%"],
    .range-label[style*="left: 31.25%"] {
        top: 22px !important;
    }

    /* Tables — horizontal scroll */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* === Login / Register pages (auth/) === */
    .login-wrapper {
        height: auto !important;
        min-height: 100vh;
        padding: 16px 12px !important;
    }

    .login-box {
        width: 100% !important;
        max-width: 100% !important;
        padding: 1.25rem !important;
    }

    /* The "Back to Home" button had an inline padding-right:260px that broke mobile */
    .home-button {
        padding-right: 0 !important;
        width: 100%;
        text-align: left;
        margin-bottom: 1rem !important;
    }

    /* Welcome page video background — keep a sensible scale on phones */
    .video-background {
        transform: translate(-50%, -50%) scale(1.1) !important;
    }

    .content {
        padding: 1rem !important;
    }
}

/* ===== Very small phones ===== */
@media (max-width: 380px) {
    h1 {
        font-size: 1.2rem !important;
    }

    .toggle-option {
        flex: 1 1 100% !important;
    }
}
