:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #ec4899;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius: 16px;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--background);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Ensures app-container is centered */
}

/* Navbar */
.navbar {
    background: var(--surface);
    padding: 1rem 2rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: center;
    text-align: center;
    width: 100%;
    /* Full width navbar inside container or outside? */
}

/* Note: Navbar is inside app-container in HTML, so it takes container width.
   If we want navbar to span full screen width, it should be outside app-container.
   But based on current HTML, it's inside. We'll leave it but ensure it centers.
*/

.logo-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Main Layout */
.app-container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    /* Backup centering */
    flex: 1;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.02);
    /* Subtle shadow better distincts structure */
    background: #fff;
    /* Optional: distinct background for container if desired, else transparent */
    background: transparent;
}

.main-content {
    flex: 1;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Centers content vertically if height allows */
}

/* Allow panels to take full width up to a max */
.input-panel,
.result-panel {
    width: 100%;
    max-width: 800px;
    /* Centered max width */
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tabs */
.tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    background: #f1f5f9;
    padding: 0.25rem;
    border-radius: 12px;
}

.tab-btn {
    flex: 1;
    padding: 0.75rem;
    border: none;
    background: transparent;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.tab-btn.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 1rem;
    text-align: center;
    transition: all 0.3s;
    background: #f8fafc;
}

.upload-area:hover {
    border-color: var(--primary);
    background: #eef2ff;
}

.upload-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

/* Camera: square viewfinder, the same shape the model analyzes */
.camera-container {
    position: relative;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    aspect-ratio: 1;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Inset 6.25% = the 224/256 center crop the model uses */
.camera-guide {
    position: absolute;
    inset: 6.25%;
    border: 2px dashed rgba(255, 255, 255, 0.85);
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.guide-hint {
    position: absolute;
    top: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.55);
    color: white;
    font-size: 0.8rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    white-space: nowrap;
}

.camera-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    justify-items: center;
    max-width: 480px;
    margin: 1rem auto 0;
}

.btn-capture {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--primary);
    border: 5px solid #e0e7ff;
    color: white;
    font-size: 1.6rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.btn-capture:active {
    transform: scale(0.9);
}

.btn-round {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: #f1f5f9;
    color: var(--text-main);
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-round.active {
    background: #fef3c7;
    color: #b45309;
}

.invisible {
    visibility: hidden;
}

.camera-tips {
    list-style: none;
    max-width: 480px;
    margin: 1rem auto 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: grid;
    gap: 0.35rem;
}

.camera-tips i {
    width: 1.25rem;
    color: var(--primary);
    text-align: center;
}

/* Phones: use the full width of the screen */
@media (max-width: 600px) {
    .main-content {
        padding: 1rem 0.75rem;
    }

    .input-panel,
    .result-panel {
        padding: 1rem;
    }

    .tabs {
        margin-bottom: 1rem;
    }
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 1rem;
    transition: background 0.3s;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

/* Result Panel */
.result-panel {
    /* Uses inherited panel styles but we ensure relative positioning for loader */
    position: relative;
    min-height: 400px;
}

.hidden {
    display: none !important;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--primary);
    border-bottom-color: transparent;
    border-radius: 50%;
    animation: rotation 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.prediction-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.confidence-badge {
    background: #e0e7ff;
    color: var(--primary-dark);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
}

.disease-title {
    font-size: 1.5rem;
    color: var(--text-main);
    margin-bottom: 1.5rem;
    line-height: 1.4;
    word-wrap: break-word;
    /* Ensure long words break */
    min-height: 60px;
    /* Prevent layout jump */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.visuals-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 600px) {
    .visuals-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.visual-card {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.visual-card img {
    width: 100%;
    display: block;
    aspect-ratio: 1;
    object-fit: cover;
}

.badge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.gradient {
    background: linear-gradient(45deg, var(--primary), var(--secondary));
}

/* Top-3 probabilities */
.top-predictions {
    margin-bottom: 1.5rem;
}

.top-predictions h3,
.disease-info h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-main);
}

.top-row {
    display: grid;
    grid-template-columns: minmax(110px, 160px) 1fr 3.5rem;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.top-row .top-label {
    color: var(--text-muted);
}

.top-row.first .top-label {
    color: var(--text-main);
    font-weight: 600;
}

.top-bar {
    height: 10px;
    background: #f1f5f9;
    border-radius: 5px;
    overflow: hidden;
}

.top-bar-fill {
    height: 100%;
    background: #cbd5e1;
    border-radius: 5px;
    transition: width 0.6s ease-out;
}

.top-row.first .top-bar-fill {
    background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.top-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* Disease information card */
.disease-info {
    margin-top: 1.5rem;
    padding: 1.25rem 1.5rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
    line-height: 1.5;
}

.disease-info h3 i {
    color: var(--primary);
    margin-right: 0.25rem;
}

.disease-info h4 {
    font-size: 0.9rem;
    margin: 1rem 0 0.4rem;
}

.disease-info ul {
    padding-left: 1.25rem;
}

.disease-info li {
    margin-bottom: 0.2rem;
}

.contagious {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
}

.contagious i {
    margin-top: 0.2rem;
}

.contagious strong {
    display: block;
}

.contagious.si {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.contagious.no {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.contagious.depende {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

.info-note {
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Rejection (blurry / not valid / low confidence) */
.rejection-card {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 12px;
    padding: 2rem 1.5rem;
    text-align: center;
    color: #9a3412;
}

.rejection-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: #ea580c;
}

.rejection-card h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.rejection-card p {
    line-height: 1.5;
    color: #7c2d12;
}

.btn-reset {
    width: 100%;
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f1f5f9;
    border: none;
    border-radius: 8px;
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background 0.3s;
}

.btn-reset:hover {
    background: #e2e8f0;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 2rem;
    margin-top: auto;
    /* Pushes to bottom */
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    width: 100%;
}

.app-footer p {
    margin: 0.25rem 0;
}

.copyright {
    font-weight: 600;
    color: var(--primary-dark);
}

/* Disclaimer Banner */
.disclaimer-banner {
    background-color: #fff3cd;
    color: #856404;
    border-bottom: 1px solid #ffeeba;
    padding: 0.75rem 1rem;
    width: 100%;
    font-size: 0.9rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

.disclaimer-banner p {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.disclaimer-banner i {
    font-size: 1rem;
}