/* ==========================================
   BananaLeafDetect - Modern Premium Styling
   ========================================== */

/* Import Fonts */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

:root {
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Plus Jakarta Sans', sans-serif;

    /* Theme Colors - Light Mode Defaults (Overrides in .dark-theme) */
    --bg-base: #f4f7f5;
    --bg-surface: rgba(255, 255, 255, 0.85);
    --bg-card: #ffffff;
    --border-color: rgba(15, 81, 50, 0.12);
    --text-primary: #152c1e;
    --text-secondary: #4a6052;
    --text-muted: #829a8a;
    
    /* Brand Accent Colors */
    --primary: #198754;
    --primary-light: #d1e7dd;
    --primary-hover: #146c43;
    --accent: #ffc107;
    --accent-light: #fff3cd;
    
    /* Functional Colors */
    --success: #198754;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #0dcaf0;
    
    /* Styling variables */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --shadow-sm: 0 2px 8px rgba(15, 81, 50, 0.04);
    --shadow-md: 0 8px 30px rgba(15, 81, 50, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 81, 50, 0.12);
    --glass-blur: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme Variables */
.dark-theme {
    --bg-base: #0a0e0b;
    --bg-surface: rgba(16, 26, 20, 0.75);
    --bg-card: #121a15;
    --border-color: rgba(25, 135, 84, 0.2);
    --text-primary: #f0f7f3;
    --text-secondary: #a3b8ab;
    --text-muted: #6b8474;
    
    --primary: #20c997;
    --primary-light: rgba(32, 201, 151, 0.15);
    --primary-hover: #1ba87e;
    --accent: #ffca2c;
    --accent-light: rgba(255, 202, 44, 0.15);
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
}

/* General Resets & Layout */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    transition: var(--transition);
    background-image: 
        radial-gradient(at 0% 0%, var(--primary-light) 0px, transparent 50%),
        radial-gradient(at 100% 100%, var(--accent-light) 0px, transparent 50%);
    background-attachment: fixed;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}

/* Header / Navbar */
header {
    padding: 1.25rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 2rem;
    animation: sway 3s ease-in-out infinite alternate;
}

@keyframes sway {
    0% { transform: rotate(-5deg); }
    100% { transform: rotate(5deg); }
}

.logo-text h1 {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--text-primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.logo-text span {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--primary);
    display: block;
    margin-top: -3px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Status Pill */
.status-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-muted);
}

.status-indicator.loading {
    background-color: var(--warning);
    animation: pulse 1.5s infinite;
}

.status-indicator.ready {
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-indicator.error {
    background-color: var(--danger);
}

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

/* Theme Toggle Button */
.theme-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.theme-btn:hover {
    transform: rotate(45deg) scale(1.05);
    background: var(--primary-light);
}

/* Main Container Grid */
.container {
    max-width: 1300px;
    margin: 0 auto;
    padding: 0 1.5rem 3rem;
    flex-grow: 1;
    width: 100%;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 2rem;
    align-items: start;
}

/* Sidebar/Widget layout on smaller screens */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* Base Panel Styles */
.panel {
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    position: relative;
}

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

.panel-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.35rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Media Source Toggles (Camera vs Upload) */
.source-tabs {
    display: flex;
    background: var(--bg-base);
    padding: 0.25rem;
    border-radius: 50px;
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.source-tab {
    flex: 1;
    padding: 0.6rem 1.2rem;
    border: none;
    background: transparent;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-radius: 50px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.source-tab.active {
    background: var(--primary);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

/* Scan / Preview Area */
.scan-area {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
    aspect-ratio: 4/3;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.6);
}

.scan-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    gap: 1rem;
    color: #ffffff;
    z-index: 5;
    text-align: center;
    padding: 2rem;
    cursor: pointer;
}

.upload-icon {
    font-size: 3.5rem;
    color: var(--primary);
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

/* Live Video */
#webcam-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror camera */
}

/* Image preview element */
#image-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: none;
}

/* Output Bounding Box Canvas */
#canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 8;
    pointer-events: none; /* Allow click events to pass through to elements underneath */
}

/* Scanning Line Laser effect */
.scan-line {
    position: absolute;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(to bottom, rgba(32, 201, 151, 0), var(--primary), rgba(32, 201, 151, 0));
    box-shadow: 0 0 15px var(--primary);
    z-index: 10;
    top: 0;
    display: none;
    animation: scanAnimation 2.5s ease-in-out infinite;
}

@keyframes scanAnimation {
    0% { top: 0%; }
    50% { top: 100%; }
    100% { top: 0%; }
}

/* Action Controls Row */
.action-controls {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn {
    flex: 1;
    padding: 0.85rem 1.5rem;
    border-radius: 50px;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    box-shadow: var(--shadow-sm);
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(25, 135, 84, 0.3);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--primary-light);
    color: var(--primary-hover);
    transform: translateY(-2px);
}

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

/* Camera Switcher overlay button */
.camera-switch-btn {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    z-index: 12;
    transition: var(--transition);
}

.camera-switch-btn:hover {
    background: var(--primary);
    transform: scale(1.1);
}

/* Model parameters card */
.settings-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-top: 1.5rem;
    border: 1px solid var(--border-color);
}

.settings-card h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.slider-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.slider-group input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
}

/* Dynamic Fallback Alert */
.fallback-alert {
    background: var(--accent-light);
    color: #664d03;
    border: 1px solid #ffe69c;
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    line-height: 1.4;
    display: none;
    align-items: flex-start;
    gap: 0.75rem;
}

.dark-theme .fallback-alert {
    background: rgba(255, 202, 44, 0.1);
    color: #ffda6a;
    border: 1px solid rgba(255, 202, 44, 0.2);
}

/* Results Display Panel */
.results-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Health Score circular indicator or banner */
.health-score-container {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.health-score-radial {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.radial-svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.radial-bg {
    fill: none;
    stroke: var(--border-color);
    stroke-width: 8;
}

.radial-bar {
    fill: none;
    stroke: var(--primary);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 226.2; /* 2 * PI * r (36) */
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s ease-out;
}

.radial-text {
    position: absolute;
    font-family: var(--font-heading);
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-primary);
}

.health-summary-text h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.health-summary-text p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Diagnostic items list */
.diagnosis-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.diagnosis-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: var(--transition);
}

.diagnosis-card:hover {
    transform: translateX(4px);
    border-color: var(--primary);
}

.diagnosis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.disease-badge {
    padding: 0.4rem 0.8rem;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.disease-badge.danger {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
    border: 1px solid rgba(220, 53, 69, 0.2);
}

.disease-badge.warning {
    background: rgba(255, 193, 7, 0.1);
    color: #b58100;
    border: 1px solid rgba(255, 193, 7, 0.2);
}

.dark-theme .disease-badge.warning {
    color: #ffca2c;
}

.disease-badge.success {
    background: rgba(25, 135, 84, 0.1);
    color: #198754;
    border: 1px solid rgba(25, 135, 84, 0.2);
}

.confidence-score {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.disease-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.disease-actions {
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
}

.treatment-title {
    font-weight: 700;
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
    color: var(--text-primary);
}

.treatment-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.treatment-list li {
    font-size: 0.8rem;
    color: var(--text-secondary);
    position: relative;
    padding-left: 1.25rem;
}

.treatment-list li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--primary);
    font-weight: 700;
}

/* Empty scan state view */
.empty-results {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
}

.empty-results-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* Disease Library section */
.library-section {
    margin-top: 3rem;
}

.library-search-bar {
    margin-bottom: 1.5rem;
    display: flex;
    gap: 1rem;
}

.search-input-wrapper {
    flex: 1;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.8rem 1.2rem;
    border-radius: 50px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(25, 135, 84, 0.15);
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.library-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.library-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.library-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.library-card-icon {
    font-size: 1.75rem;
}

.library-card-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-primary);
}

.library-card-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
}

.library-card-body {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Footer styling */
footer {
    text-align: center;
    padding: 2rem;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* PDF Print styling override */
@media print {
    body {
        background: #ffffff !important;
        color: #000000 !important;
        background-image: none !important;
    }
    
    header, footer, .source-tabs, .action-controls, .settings-card, .library-section, .theme-btn, .camera-switch-btn {
        display: none !important;
    }
    
    .container {
        padding: 0 !important;
        max-width: 100% !important;
    }
    
    .dashboard-grid {
        display: block !important;
    }
    
    .panel {
        box-shadow: none !important;
        border: none !important;
        background: transparent !important;
        padding: 0 !important;
        margin-bottom: 2cm !important;
        page-break-inside: avoid;
    }
    
    .scan-area {
        border: 2px solid #ccc !important;
        box-shadow: none !important;
        background: white !important;
        aspect-ratio: auto !important;
        height: auto !important;
        page-break-inside: avoid;
    }
    
    #canvas-overlay {
        position: relative !important;
        width: 100% !important;
    }
    
    .diagnosis-card {
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        page-break-inside: avoid;
        margin-bottom: 1rem !important;
    }
    
    /* Printable Report Header */
    .print-header {
        display: block !important;
        border-bottom: 2px solid #000000;
        padding-bottom: 1rem;
        margin-bottom: 2rem;
    }
}

.print-header {
    display: none;
}

.print-header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.print-meta {
    text-align: right;
    font-size: 0.85rem;
    color: #555555;
}

/* Diagnostic Progress loader */
.model-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    padding: 2rem;
    text-align: center;
}

.loading-spinner {
    border: 4px solid rgba(255, 255, 255, 0.1);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border-left-color: var(--primary);
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-progress-bar {
    width: 200px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    margin-top: 1rem;
    overflow: hidden;
    position: relative;
}

.loading-progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
}

/* Custom Modal style for Fallback / Manual Guide */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalSlide 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.15rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-base);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}
