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

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #334155;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    padding-top: max(20px, env(safe-area-inset-top, 20px)); /* iOS safe area support */
    color: var(--text-primary);
    overflow-x: hidden; /* Prevent horizontal scroll on body */
    width: 100%;
    max-width: 100vw;
    position: relative;
    overflow-y: auto; /* Allow body to scroll, but formSection won't scroll internally */
}

/* iOS Safari status bar area */
@supports (padding: max(0px)) {
    body {
        padding-top: max(20px, env(safe-area-inset-top));
    }
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow);
    animation: fadeIn 0.5s ease-in;
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Form Section - no scrolling, resize to fit content */
#formSection {
    overflow: visible !important;
    overflow-y: visible !important;
    height: auto !important;
    max-height: none !important;
    min-height: auto !important;
    position: relative;
    z-index: 10;
}

/* Results Section - no vertical scrolling, resize to fit content */
#resultsSection {
    overflow: visible !important;
    overflow-y: visible !important;
    height: auto !important;
    max-height: none !important;
    min-height: auto !important;
}

/* Ensure form elements are clickable */
#formSection input,
#formSection select,
#formSection button,
#formSection label,
#formSection .file-upload-label {
    position: relative;
    z-index: 11;
    pointer-events: auto;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.header {
    text-align: center;
    margin-bottom: 40px;
}

.header h1 {
    font-size: 3rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
}

.logo-image {
    max-width: 300px;
    height: auto;
    margin-bottom: 10px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.form-container {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.form-group input,
.form-group select {
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.file-upload-wrapper {
    position: relative;
}

.file-upload-wrapper input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    background: var(--bg-color);
    cursor: pointer;
    transition: all 0.3s ease;
}

.file-upload-label:hover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
}

.file-upload-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.file-upload-text {
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.file-name {
    color: var(--primary-color);
    font-weight: 600;
    margin-top: 5px;
}

/* reCAPTCHA styling */
.g-recaptcha {
    margin: 15px 0;
    display: flex;
    justify-content: center;
}

.g-recaptcha > div {
    margin: 0 auto;
}

.submit-btn {
    padding: 16px 32px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 10px;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3);
}

.submit-btn:active {
    transform: translateY(0);
}

.submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Analyzing Animation */
.analyzing-container {
    text-align: center;
    padding: 60px 20px;
}

.spinner {
    width: 80px;
    height: 80px;
    border: 5px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 30px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.progress-dots {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 30px;
}

.progress-dots span {
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

.progress-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.progress-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* Results Section */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.results-header h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.new-analysis-btn {
    padding: 12px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.new-analysis-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.results-card {
    background: var(--bg-color);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 25px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.results-card h2 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.summary-content {
    color: var(--text-secondary);
    line-height: 1.8;
    font-size: 1.05rem;
}

.concerns-card {
    border-left: 4px solid var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
}

.concerns-card ul {
    list-style: none;
    padding: 0;
}

.concerns-card li {
    padding: 12px;
    margin-bottom: 10px;
    background: rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    border-left: 3px solid var(--danger-color);
}

.recommendations-card {
    border-left: 4px solid var(--success-color);
}

.recommendations-card ul {
    list-style: none;
    padding: 0;
}

.recommendations-card li {
    padding: 12px;
    margin-bottom: 10px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 8px;
    border-left: 3px solid var(--success-color);
}

.dashboard-card {
    overflow-x: visible; /* Don't scroll the card itself */
    overflow-y: visible;
}

.dashboard-card > * {
    overflow-x: visible; /* Don't scroll child elements */
}

.dashboard-card .chart-wrapper {
    overflow-x: auto; /* Only chart-wrapper scrolls horizontally */
    overflow-y: visible;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on mobile */
    touch-action: pan-x; /* Allow horizontal panning on mobile */
}

.dashboard-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 16px;
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.filter-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.filter-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 30px;
    margin-top: 20px;
    width: 100%;
    overflow-x: visible;
    overflow-y: visible;
    box-sizing: border-box;
    position: relative;
}

.chart-wrapper {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    min-height: 300px;
    height: auto;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}


/* Status chart card - completely separate from dashboard-card */
.status-chart-card {
    margin-top: 0;
    margin-bottom: 25px;
}

/* Status chart wrapper - completely separate from charts-container */
.status-chart-wrapper {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 100%;
    height: 300px;
    box-sizing: border-box;
    overflow: hidden;
}

.status-chart-wrapper canvas {
    margin: 0 auto;
    display: block;
}

.table-container {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on mobile */
    touch-action: pan-x; /* Allow horizontal panning on mobile */
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

thead {
    background: var(--card-bg);
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

tbody tr:hover {
    background: rgba(99, 102, 241, 0.05);
}

.status-badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-normal {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success-color);
}

.status-high {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger-color);
}

.status-low {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

.status-borderline {
    background: rgba(249, 115, 22, 0.2);
    color: #f97316;
}

.comparison-content {
    color: var(--text-secondary);
    line-height: 1.8;
    font-size: 1.05rem;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-in;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 20px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 30px 30px 20px;
    border-bottom: 2px solid var(--border-color);
}

.modal-header h2 {
    color: var(--warning-color);
    font-size: 1.8rem;
    margin: 0;
}

.modal-body {
    padding: 30px;
    color: var(--text-secondary);
    line-height: 1.8;
}

.modal-body p {
    margin-bottom: 15px;
}

.modal-body p strong {
    color: var(--text-primary);
    font-size: 1.1rem;
}

.modal-body ul {
    margin: 15px 0;
    padding-left: 25px;
}

.modal-body li {
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.modal-footer {
    padding: 20px 30px 30px;
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    border-top: 2px solid var(--border-color);
}

.modal-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.cancel-btn {
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

.cancel-btn:hover {
    background: var(--bg-color);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.agree-btn {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
}

.agree-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3);
}

.agree-btn:active {
    transform: translateY(0);
}

/* Ad Container Styles */
.ad-container {
    margin: 20px 0;
    padding: 15px;
    background: var(--bg-color);
    border-radius: 10px;
    text-align: center;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Sidebar Ad Styles (Desktop Only) */
.ad-sidebar {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 160px;
    z-index: 100;
    display: none; /* Hidden by default, shown on desktop */
    padding: 10px;
    background: var(--bg-color);
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.ad-sidebar-left {
    left: 20px;
}

.ad-sidebar-right {
    right: 20px;
}

.ad-sidebar .adsbygoogle {
    display: block;
    width: 100%;
    min-height: 600px;
}

.ad-banner-top {
    margin-top: 0;
    margin-bottom: 30px;
    min-height: 90px;
}

.ad-in-content {
    margin: 25px 0;
    min-height: 250px;
}

.ad-footer {
    margin-top: 30px;
    margin-bottom: 0;
    min-height: 100px;
}

.ad-disclaimer {
    font-size: 1rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 12px;
    opacity: 0.8;
    font-weight: 500;
    width: 100%;
}

/* AdSense responsive styling */
.adsbygoogle {
    display: block;
    width: 100%;
    max-width: 100%;
}

/* reCAPTCHA badge - ensure it's above all content */
.grecaptcha-badge {
    z-index: 99999 !important;
    position: fixed !important;
}

/* Hide reCAPTCHA badge on results page */
body.results-visible .grecaptcha-badge {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Mobile Ad Above Form - Hidden on desktop */
.ad-mobile-top {
    display: none;
    position: relative;
    z-index: 1;
    pointer-events: none;
}

.ad-mobile-top .adsbygoogle {
    pointer-events: auto; /* Allow clicks on the ad itself */
}

/* Show sidebar ads on desktop */
@media (min-width: 1024px) {
    .ad-sidebar {
        display: block;
    }
    
    .ad-mobile-top {
        display: none !important;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 20px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* Form Section on mobile - no scrolling */
    #formSection {
        overflow: visible !important;
        overflow-y: visible !important;
        height: auto !important;
        max-height: none !important;
    }

    /* Results Section on mobile - no vertical scrolling */
    #resultsSection {
        overflow: visible !important;
        overflow-y: visible !important;
        height: auto !important;
        max-height: none !important;
    }

    .header h1 {
        font-size: 2rem;
    }
    
    .logo-image {
        max-width: 250px;
    }
    
    .analyzing-container {
        text-align: center;
        padding: 20px;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    .results-container {
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .charts-container {
        grid-template-columns: 1fr;
        width: 100%;
        max-width: 100%;
        overflow-x: visible; /* Don't constrain - let wrapper scroll */
        overflow-y: visible;
        box-sizing: border-box;
        margin-left: 0;
        margin-right: 0;
        position: relative;
    }

    .chart-wrapper {
        min-height: 250px;
        /* Width will be set by JavaScript on mobile */
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x !important;
        position: relative;
        z-index: 2;
        box-sizing: border-box;
        width: 100%;
        max-width: 100%;
    }
    
    /* Values chart wrapper - allow horizontal scroll */
    .chart-wrapper:first-of-type {
        /* Width will be set by JavaScript to calculated width */
        overflow-x: auto !important; /* Force horizontal scroll */
        overflow-y: visible !important; /* Allow vertical overflow for labels */
        min-height: 350px; /* Minimum height for chart including labels */
        height: auto; /* Allow height to accommodate labels */
        display: block !important; /* Ensure proper block layout */
        position: relative !important; /* For proper positioning */
        z-index: 2 !important;
        touch-action: pan-x !important;
    }
    
    /* Ensure bar chart canvas can be wider than wrapper */
    .chart-wrapper:first-of-type canvas {
        height: 350px !important; /* Fixed height to prevent skewing, with room for labels */
        width: auto !important; /* Width will be set by JavaScript */
        max-width: none !important; /* Remove any max-width constraints */
        min-width: 600px !important; /* Minimum width to ensure spacing */
        display: block !important; /* Block display for proper sizing */
    }
    
    /* Status chart wrapper on mobile */
    .status-chart-wrapper {
        height: 250px;
        padding: 15px;
        margin-top: 15px;
    }
    
    
    .dashboard-card {
        overflow-x: visible; /* Don't scroll the card itself */
        overflow-y: visible;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .dashboard-card > *:not(.chart-wrapper) {
        overflow-x: hidden;
        width: 100%;
    }
    
    .dashboard-card .chart-wrapper {
        overflow-x: auto !important; /* Force horizontal scroll on mobile */
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x !important; /* Allow horizontal panning */
        width: 100% !important;
        max-width: 100% !important;
        position: relative !important;
        z-index: 2 !important;
        display: block !important;
    }
    
    .dashboard-card .chart-wrapper canvas {
        position: relative;
        z-index: 1;
    }

    .results-header {
        flex-direction: column;
        gap: 20px;
        align-items: flex-start;
        width: 100%;
        box-sizing: border-box;
    }
    
    .results-card {
        width: 100%;
        box-sizing: border-box;
        overflow-x: visible; /* Don't scroll the card itself */
        overflow-y: visible;
    }
    
    .results-card > *:not(.chart-wrapper):not(.table-container) {
        overflow-x: hidden;
    }
    
    .results-card .table-container {
        overflow-x: auto !important; /* Allow table to scroll horizontally */
        touch-action: pan-x !important; /* Allow horizontal panning */
    }

    table {
        font-size: 0.9rem;
        width: 100%;
        table-layout: auto;
    }

    th, td {
        padding: 10px;
        white-space: nowrap; /* Prevent text wrapping in table cells */
    }
    
    .table-container {
        overflow-x: auto !important; /* Force horizontal scroll on mobile */
        overflow-y: visible;
        width: 100%;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on mobile */
        display: block;
    }
    
    .table-container table {
        min-width: 600px; /* Ensure table is wide enough to trigger horizontal scroll */
        width: auto; /* Let table be its natural width */
    }

    .modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 20px;
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-btn {
        width: 100%;
    }

    /* Mobile ad adjustments */
    .ad-container {
        margin: 15px 0;
        padding: 10px;
        min-height: 50px;
    }

    .ad-banner-top {
        margin-bottom: 20px;
        min-height: 50px;
    }

    .ad-in-content {
        min-height: 200px;
    }

    .ad-footer {
        min-height: 50px;
    }

    /* Ensure sidebars are hidden on mobile */
    .ad-sidebar {
        display: none !important;
    }

    /* Show mobile ad above form */
    .ad-mobile-top {
        display: block;
        margin: 0 auto 0;
        max-width: 100%;
        padding: 15px 10px;
        min-height: 0 !important;
        max-height: 200px !important;
        position: relative;
        z-index: 1;
        pointer-events: none;
    }
    
    .ad-mobile-top .adsbygoogle {
        pointer-events: auto; /* Allow clicks on the ad itself */
    }
    
    /* Ensure form elements are clickable on mobile */
    #formSection {
        position: relative;
        z-index: 10;
    }
    
    #formSection input,
    #formSection select,
    #formSection button,
    #formSection label,
    #formSection .file-upload-label {
        position: relative;
        z-index: 11;
        pointer-events: auto !important;
    }

    .ad-mobile-top .adsbygoogle {
        min-height: 0 !important;
        max-height: 200px !important;
    }

    .ad-mobile-disclaimer {
        display: block;
        text-align: center;
        margin: 12px auto 20px;
    }
}

