* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #f5f5f5;
}

/* ─── Navigation ─────────────────────────────────────────────── */
nav {
    background: #e74c3c;
    padding: 1rem 2rem;
    position: fixed;
    width: 100%;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Allow the mobile toggle to be positioned inside */
    position: relative;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    color: white;
    text-decoration: none;
    /* Prevent brand from shrinking on narrow screens */
    flex-shrink: 0;
}

.nav-logo {
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-logo img {
    width: 30px;
    height: 30px;
}

.nav-brand-text {
    font-size: 1.3rem;
    font-weight: 500;
    letter-spacing: 1px;
}

.nav-menu {
    list-style: none;
    display: flex;
    gap: 2rem;
    align-items: center;
}

.nav-menu li {
    position: relative;
}

.nav-menu a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.3s;
    /* Comfortable touch target */
    display: flex;
    align-items: center;
    min-height: 44px;
}

.nav-menu a:hover {
    opacity: 0.8;
}

/* ─── Dropdown ────────────────────────────────────────────────── */
.dropdown {
    position: relative;
}

.dropdown-toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem;
    user-select: none;
    color: white;
    min-height: 44px;
}

.dropdown-arrow {
    font-size: 0.7rem;
    transition: transform 0.3s;
}

.dropdown.active .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: white;
    min-width: 250px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
    margin-top: 0.5rem;
    padding: 0.5rem 0;
    max-height: 0;
    overflow: hidden;
}

.dropdown.active .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
    max-height: 500px;
}

.dropdown-menu li {
    list-style: none;
}

.dropdown-menu a {
    display: block;
    padding: 0.8rem 1.5rem;
    color: #666;
    text-decoration: none;
    transition: background 0.3s, color 0.3s;
    border-radius: 5px;
    margin: 0 0.5rem;
    min-height: 44px;
}

.dropdown-menu a:hover {
    background: #f8f8f8;
    color: #e74c3c;
}

/* ─── Mobile menu toggle ──────────────────────────────────────── */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: white;
    cursor: pointer;
    /* Comfortable touch target */
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* ─── Main layout ─────────────────────────────────────────────── */
.main-content {
    margin-top: 70px;
    padding: 3rem 1.5rem 4rem;
}

.page-wrapper {
    max-width: 860px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* ─── Page header ─────────────────────────────────────────────── */
.page-header {
    text-align: center;
    padding: 1rem 0 0.5rem;
}

.page-title {
    color: #e74c3c;
    /* Fluid type — scales from 1.5rem up to 2rem */
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.page-sub {
    color: #777;
    font-size: clamp(0.9rem, 2vw, 1rem);
    max-width: 520px;
    margin: 0 auto;
}

/* ─── Cards ───────────────────────────────────────────────────── */
.card {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ─── Upload zone ─────────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed #ddd;
    border-radius: 12px;
    min-height: 220px;
    position: relative;
    overflow: hidden;
    transition: border-color 0.3s, background 0.3s;
    cursor: pointer;
    margin-bottom: 1.2rem;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: #e74c3c;
    background: rgba(231, 76, 60, 0.03);
}

.upload-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 2rem;
    gap: 0.75rem;
    min-height: 220px;
    text-align: center;
}

.upload-icon-wrap {
    width: 60px;
    height: 60px;
    background: rgba(231, 76, 60, 0.08);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #e74c3c;
    margin-bottom: 0.3rem;
    flex-shrink: 0;
}

.upload-icon {
    width: 32px;
    height: 32px;
}

.upload-title {
    font-weight: 600;
    font-size: 1rem;
    color: #333;
}

.upload-hint {
    font-size: 0.82rem;
    color: #999;
}

.btn-browse {
    margin-top: 0.3rem;
    background: transparent;
    border: 1.5px solid #ddd;
    color: #555;
    padding: 0.5rem 1.3rem;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.25s, color 0.25s;
    /* Comfortable touch target */
    min-height: 44px;
}

.btn-browse:hover {
    border-color: #e74c3c;
    color: #e74c3c;
}

.upload-preview {
    width: 100%;
    height: 240px;
    position: relative;
}

.upload-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 10px;
}

.preview-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s;
    border-radius: 10px;
}

.upload-preview:hover .preview-overlay {
    opacity: 1;
}

.btn-change {
    background: rgba(255, 255, 255, 0.2);
    border: 1.5px solid rgba(255, 255, 255, 0.5);
    color: white;
    padding: 0.55rem 1.3rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    backdrop-filter: blur(4px);
    transition: background 0.2s;
    min-height: 44px;
}

.btn-change:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ─── File info ───────────────────────────────────────────────── */
.file-info {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    background: #f8f8f8;
    border-radius: 8px;
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    margin-bottom: 1.2rem;
    /* Prevent overflow on narrow screens */
    min-width: 0;
}

.file-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.file-name {
    flex: 1;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.88rem;
    min-width: 0;
}

.file-size {
    color: #999;
    white-space: nowrap;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.btn-clear {
    background: none;
    border: none;
    color: #bbb;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    transition: color 0.2s;
    line-height: 1;
    flex-shrink: 0;
    /* Comfortable touch target */
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-clear:hover {
    color: #e74c3c;
}

/* ─── Analyse button ──────────────────────────────────────────── */
.btn-analyse {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 0.95rem;
    border-radius: 10px;
    font-size: 1.05rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    transition: background 0.3s, transform 0.2s;
    width: 100%;
    /* Comfortable touch target */
    min-height: 48px;
}

.btn-analyse:hover:not(:disabled) {
    background: #c0392b;
    transform: translateY(-2px);
}

.btn-analyse:active:not(:disabled) {
    transform: translateY(0);
}

.btn-analyse:disabled {
    background: #ccc;
    color: #fff;
    cursor: not-allowed;
    transform: none;
}

.btn-arrow {
    width: 20px;
    height: 20px;
}

.soil-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2.5px solid rgba(255, 255, 255, .35);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .75s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
    flex-shrink: 0;
}

.soil-loading-text {
    transition: opacity .3s;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* ─── Results panel ───────────────────────────────────────────── */
.results-panel {
    animation: fadeUp 0.4s ease-out;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-card {
    max-width: 800px;
    margin: 0 auto;
}

/* Results header */
.results-header {
    text-align: center;
    margin-bottom: 32px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.status-badge {
    display: inline-block;
    background: #d4edda;
    color: #155724;
    padding: 5px 15px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 10px;
}

.results-title {
    color: #e74c3c;
    /* Fluid: 22px → 28px */
    font-size: clamp(1.375rem, 4vw, 1.75rem);
    margin-bottom: 5px;
}

.results-date {
    color: #999;
    font-size: 14px;
}

/* Metrics */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.metric-box {
    text-align: center;
    padding: 20px;
    background: #fafafa;
    border-radius: 8px;
}

.metric-label {
    font-size: 11px;
    color: #999;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 15px;
    text-transform: uppercase;
}

.metric-value {
    font-size: clamp(2rem, 6vw, 2.5rem);
    font-weight: 700;
    color: #27ae60;
    margin-bottom: 5px;
    display: flex;
    align-items: baseline;
    justify-content: center;
}

.metric-value.confidence {
    font-size: clamp(2.2rem, 7vw, 3rem);
    color: #e74c3c;
}

.metric-unit {
    font-size: clamp(1rem, 3vw, 1.5rem);
    color: #999;
}

.metric-status {
    color: #27ae60;
    font-weight: 600;
    font-size: 14px;
}

/* Divider */
.divider {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 30px 0;
}

/* Section */
.section {
    margin-bottom: 30px;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    color: #333;
    margin-bottom: 15px;
}

.section-title span {
    margin-right: 5px;
}

.explanation-box {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    color: #555;
    line-height: 1.6;
    border-left: 3px solid #e74c3c;
}

/* Recommendations */
.recommendations {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.reco-item {
    padding: 15px 20px;
    background: #f9f9f9;
    border-radius: 8px;
    color: #555;
    font-size: 14px;
    line-height: 1.6;
    border-left: 3px solid #e74c3c;
}

/* Action buttons */
.action-buttons {
    display: flex;
    gap: 15px;
    margin-top: 30px;
}

.btn-primary,
.btn-secondary {
    flex: 1;
    padding: 15px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    /* Comfortable touch target */
    min-height: 48px;
}

.btn-secondary {
    background: #ecf0f1;
    color: #555;
}

.btn-secondary:hover {
    background: #d5d8dc;
}

.btn-primary {
    background: #e74c3c;
    color: white;
}

.btn-primary:hover {
    background: #c0392b;
}

/* ─── Modal ───────────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    /* Allow scrolling if modal is taller than viewport */
    overflow-y: auto;
    padding: 1rem;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 2.5rem 2rem;
    max-width: 380px;
    width: 100%;
    text-align: center;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease-out;
    /* Prevent shrinking below padding on very small screens */
    margin: auto;
}

@keyframes slideIn {
    from {
        transform: translateY(-28px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-icon {
    font-size: 2.4rem;
    margin-bottom: 0.8rem;
}

.modal-content h3 {
    font-size: 1.3rem;
    color: #222;
    margin-bottom: 0.5rem;
}

.modal-content p {
    color: #666;
    font-size: 0.95rem;
    margin-bottom: 1.8rem;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-modal {
    padding: 0.75rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.25s;
    min-width: 100px;
    min-height: 44px;
}

.btn-yes {
    background: #e74c3c;
    color: white;
}

.btn-yes:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

.btn-no {
    background: #ecf0f1;
    color: #555;
}

.btn-no:hover {
    background: #d5dbdb;
    transform: translateY(-2px);
}

/* ─── Toast ───────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #27ae60;
    color: white;
    padding: 0.75rem 2rem;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.92rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 3000;
    /* Allow text to wrap on narrow screens instead of overflowing */
    white-space: normal;
    text-align: center;
    max-width: calc(100vw - 2rem);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════════════════
   TABLET  ≤ 768px
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Nav — slide-down mobile menu */
    .menu-toggle {
        display: flex;
    }

    .nav-menu {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #e74c3c;
        padding: 1rem;
        gap: 0.5rem;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        /* Slide animation */
        animation: slideDown 0.2s ease-out;
    }

    @keyframes slideDown {
        from { opacity: 0; transform: translateY(-8px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    .nav-menu.active {
        display: flex;
    }

    /* Dropdown — static inside the mobile menu */
    .dropdown {
        width: 100%;
    }

    .dropdown-toggle {
        width: 100%;
        justify-content: center;
        gap: 0.5rem;
    }

    .dropdown-menu {
        position: static;
        transform: none !important;
        box-shadow: none;
        background: rgba(255, 255, 255, 0.12);
        border-radius: 8px;
        margin: 0.3rem 0 0;
        /* Reset desktop opacity/visibility toggling; use display instead */
        opacity: 1;
        visibility: visible;
        max-height: none;
        overflow: visible;
        padding: 0.25rem 0;
        display: none;
    }

    .dropdown.active .dropdown-menu {
        display: block;
        transform: none !important;
    }

    .dropdown-menu a {
        color: white;
        margin: 0;
        border-radius: 6px;
    }

    .dropdown-menu a:hover {
        background: rgba(255, 255, 255, 0.15);
        color: white;
    }

    /* Layout */
    .main-content {
        padding: 2rem 1rem 3rem;
    }

    .card {
        padding: 1.6rem 1.3rem;
    }

    /* Results */
    .results-header {
        margin-bottom: 24px;
    }

    .metrics-grid {
        gap: 16px;
    }

    /* Action buttons — side by side still OK at 768 */
    .action-buttons {
        gap: 10px;
    }

    /* Modal buttons — still side by side at tablet */
    .modal-buttons {
        gap: 0.75rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE  ≤ 480px
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    /* Nav brand — hide text label on very small phones */
    .nav-brand-text {
        display: none;
    }

    /* Layout */
    .main-content {
        padding: 1.5rem 0.75rem 3rem;
    }

    .card {
        padding: 1.2rem 1rem;
    }

    /* Upload */
    .upload-empty {
        padding: 1.8rem 1rem;
    }

    .upload-preview {
        height: 180px;
    }

    /* Metrics — single column on small phones */
    .metrics-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .metric-box {
        padding: 16px;
    }

    /* Action buttons — stack vertically */
    .action-buttons {
        flex-direction: column;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
    }

    /* Modal */
    .modal-content {
        padding: 1.8rem 1.2rem;
    }

    .modal-buttons {
        flex-direction: column;
    }

    .btn-modal {
        width: 100%;
    }

    /* Toast — expand to fill screen width with margin */
    .toast {
        bottom: 1rem;
        left: 0.75rem;
        right: 0.75rem;
        max-width: none;
        /* Override the translateX centering — use fixed edges instead */
        transform: translateY(20px);
    }

    .toast.show {
        transform: translateY(0);
    }
}