@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --bg-primary: #f9fafb;
    --bg-secondary: #ffffff;
    --card-bg: rgba(255, 255, 255, 0.85);
    --border-color: rgba(0, 0, 0, 0.08);
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    
    /* Health Status Colors */
    --color-healthy: #10b981;      /* Emerald Green */
    --color-moderate: #eab308;     /* Amber Yellow */
    --color-high: #f97316;         /* Orange */
    --color-critical: #ef4444;     /* Red */
    
    --primary-gradient: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.06);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-primary);
    background-image: 
        radial-gradient(at 0% 0%, rgba(243, 146, 35, 0.04) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(227, 34, 41, 0.04) 0px, transparent 50%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Authentication Page Styles */
.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(245, 245, 245, 0.95) 100%), 
                url('/Ganovis.png') no-repeat center center;
    background-size: cover;
}

.auth-card {
    background: var(--bg-secondary);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--card-shadow);
    animation: fadeInUp 0.6s ease-out;
}

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

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.auth-logo span {
    background: linear-gradient(to right, #2563eb, #1e40af);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(243, 146, 35, 0.18);
}

.form-row-checkbox {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    font-size: 0.85rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox-label input {
    accent-color: #2563eb;
}

.auth-btn {
    width: 100%;
    background: var(--primary-gradient);
    border: none;
    border-radius: 10px;
    padding: 14px;
    color: #fff;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
}

.auth-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(243, 146, 35, 0.4);
}

.error-list {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 20px;
    list-style: none;
    color: var(--color-critical);
    font-size: 0.85rem;
}

/* Header Dashboard */
.app-header {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: 15px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
}

.app-logo span {
    color: #2563eb;
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 25px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition);
}

.nav-link:hover, .nav-link.active {
    color: var(--text-primary);
}

/* ------------------------------------------------------------------ */
/* App-bar user menu (top-right dropdown)                              */
/* ------------------------------------------------------------------ */
.user-menu {
    position: relative;
}

.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 5px 12px 5px 5px;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
}

.user-menu-trigger:hover {
    background: rgba(37, 99, 235, 0.06);
    border-color: rgba(37, 99, 235, 0.35);
}

.user-menu.open .user-menu-trigger {
    background: rgba(37, 99, 235, 0.08);
    border-color: rgba(37, 99, 235, 0.45);
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff;
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.user-avatar-lg {
    width: 44px;
    height: 44px;
    font-size: 1rem;
}

.user-menu-info {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    text-align: left;
}

.user-menu-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.user-menu-role {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.user-menu-chevron {
    color: var(--text-secondary);
    transition: transform 0.2s ease;
}

.user-menu.open .user-menu-chevron {
    transform: rotate(180deg);
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 265px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.14);
    padding: 8px;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}

.user-menu.open .user-menu-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-menu-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 10px 12px;
}

.user-menu-header-text {
    min-width: 0;
}

.user-menu-header .user-menu-name {
    font-size: 0.95rem;
}

.user-menu-email {
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 165px;
}

.user-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

.user-menu-dropdown form {
    margin: 0;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 9px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    text-align: left;
    transition: background 0.15s ease, color 0.15s ease;
}

.user-menu-item svg {
    color: var(--text-secondary);
    transition: color 0.15s ease;
}

.user-menu-item:hover {
    background: rgba(37, 99, 235, 0.08);
    color: #2563eb;
}

.user-menu-item:hover svg {
    color: #2563eb;
}

.user-menu-item-danger:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #ef4444;
}

.user-menu-item-danger:hover svg {
    color: #ef4444;
}

@media (max-width: 640px) {
    .app-header {
        padding: 15px 20px;
    }

    .user-menu-info {
        display: none;
    }

    .user-menu-dropdown {
        width: 240px;
    }
}

/* Dashboard Body Container */
.dashboard-container {
    max-width: 1400px;
    width: 100%;
    margin: 40px auto;
    padding: 0 20px;
    flex-grow: 1;
}

.section-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.section-desc {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 30px;
}

/* Dashboard Layout Grid */
/* Two-column layout: the upload form on the left, the "How It Works" help
   panel as a right sidebar. Spans the full container width and left-aligns
   with the page title and the history table below it (no more centered,
   indented card). */
.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 2.1fr) minmax(0, 1fr);
    gap: 30px;
    margin: 0 0 50px;
    align-items: stretch;
}

@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

.panel-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    padding: 30px;
    box-shadow: var(--card-shadow);
}

.panel-card-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Upload Fields */
.upload-method-selector {
    display: flex;
    gap: 20px;
    margin-bottom: 25px;
}

.radio-card {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: var(--transition);
}

.radio-card:hover {
    border-color: rgba(243, 146, 35, 0.5);
    background: rgba(243, 146, 35, 0.05);
}

.radio-card input[type="radio"] {
    accent-color: #2563eb;
}

.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.upload-zone-wrapper {
    display: flex;
    flex-direction: column;
}

.upload-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.drag-drop-zone {
    border: 2px dashed var(--border-color);
    background: rgba(0, 0, 0, 0.02);
    border-radius: 12px;
    padding: 30px 15px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 160px;
    position: relative;
}

.drag-drop-zone:hover {
    border-color: #2563eb;
    background: rgba(37, 99, 235, 0.05);
}

.drag-drop-zone svg {
    color: var(--text-secondary);
    transition: var(--transition);
}

.drag-drop-zone:hover svg {
    color: #2563eb;
    transform: translateY(-3px);
}

.drag-drop-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.drag-drop-filename {
    font-size: 0.85rem;
    font-weight: 600;
    color: #2563eb;
    word-break: break-all;
    display: none;
}

.drag-drop-zone input[type="file"] {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 3;
}

/* Filled state: image fills the whole drop zone, filename becomes a caption bar */
.drag-drop-zone.has-preview {
    padding: 0;
    min-height: 220px;
    overflow: hidden;
}

.drag-drop-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #111827;
    border-radius: 10px;
    margin: 0;
    border: 0;
    z-index: 1;
}

.drag-drop-zone.has-preview .drag-drop-filename {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    display: block;
    text-align: left;
    color: #fff;
    padding: 18px 12px 10px;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.82) 0%, rgba(0, 0, 0, 0.5) 65%, transparent 100%);
    border-radius: 0 0 10px 10px;
}

/* Brief highlight when a field is auto-filled from a parsed filename */
.form-input.autofilled {
    animation: autofillPulse 1.1s ease;
}

@keyframes autofillPulse {
    0% { border-color: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.35); }
    100% { border-color: var(--border-color); box-shadow: none; }
}

/* Multi-Sample Dynamic List */
.samples-container {
    max-height: 380px;
    overflow-y: auto;
    margin-bottom: 20px;
    padding-right: 5px;
}

.sample-row {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 15px;
    position: relative;
    animation: fadeIn 0.4s ease-out;
}

.sample-row-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.sample-row-title {
    font-size: 0.95rem;
    font-weight: 600;
}

.remove-sample-btn {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
}

.add-sample-btn {
    width: 100%;
    background: rgba(0, 0, 0, 0.03);
    border: 1px dashed var(--border-color);
    color: var(--text-primary);
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 25px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.add-sample-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    border-color: var(--text-secondary);
}

/* Action buttons */
.action-buttons {
    display: flex;
    gap: 15px;
}

.btn-primary {
    background: var(--primary-gradient);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 12px 25px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    flex: 2;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(243, 146, 35, 0.4);
}

.btn-secondary {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 25px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    flex: 1;
    text-align: center;
    text-decoration: none;
}

.btn-secondary:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* Info Panel / How It Works */
.info-alert-panel {
    background: rgba(59, 130, 246, 0.07);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 14px;
    padding: 20px;
}

.info-alert-title {
    color: #3b82f6;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-alert-list {
    list-style-type: none;
}

.info-alert-list li {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-left: 15px;
    position: relative;
}

.info-alert-list li::before {
    content: "•";
    color: #3b82f6;
    position: absolute;
    left: 0;
    font-weight: bold;
}

/* Running/Queued overlay */
.running-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.running-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.running-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: var(--card-shadow);
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(243, 146, 35, 0.1);
    border-top: 4px solid #2563eb;
    border-radius: 50%;
    margin: 0 auto 25px;
    animation: spin 1.2s linear infinite;
}

.running-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.running-msg {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 25px;
}

.progress-container {
    background: rgba(0, 0, 0, 0.05);
    height: 8px;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-bar {
    background: var(--primary-gradient);
    height: 100%;
    width: 5%;
    border-radius: 10px;
    transition: width 0.4s ease;
}

.progress-pct {
    font-size: 0.9rem;
    font-weight: 600;
    color: #2563eb;
}

/* History / Results Table */
.history-section {
    margin-top: 20px;
}

.history-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    padding: 30px;
    box-shadow: var(--card-shadow);
}

.history-table-wrapper {
    overflow-x: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.history-table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
}

.history-table td {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.95rem;
    vertical-align: middle;
}

.history-table tr:last-child td {
    border-bottom: none;
}

/* Bulk selection column */
.history-table th.select-cell,
.history-table td.select-cell {
    width: 44px;
    padding-right: 0;
    text-align: center;
}

.row-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    /* Red rather than the brand orange: ticking a row arms it for deletion,
       so the control matches the Delete Selected button it feeds. */
    accent-color: #ef4444;
    vertical-align: middle;
}

/* Highlight rows queued for deletion so the selection is unmistakable.
   Driven by a .row-selected class toggled in updateBulkSelection() rather than
   tr:has(.row-select:checked): the JS already runs on every selection change,
   and a plain class avoids depending on :has() support entirely. */
.history-table tr.row-selected {
    background: rgba(239, 68, 68, 0.08);
}

/* Bulk action bar — hidden until at least one row is selected */
.bulk-actions-bar {
    display: none;
    align-items: center;
    gap: 12px;
}

.bulk-actions-bar.active {
    display: flex;
}

.bulk-actions-count {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.bulk-clear-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: underline;
    padding: 4px;
}

.bulk-clear-btn:hover {
    color: var(--text-primary);
}

.bulk-delete-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: #ef4444;
    border: none;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.bulk-delete-btn:hover {
    background: #dc2626;
}

.history-table tr {
    transition: var(--transition);
}

.history-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.scan-meta-cell {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.scan-clone {
    font-weight: 600;
    /* Was #fff, left over from the old dark theme — invisible against the
       light table background. */
    color: var(--text-primary);
}

.scan-details {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.image-preview-cell {
    display: flex;
    gap: 8px;
}

.thumbnail {
    width: 50px;
    height: 50px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--border-color);
    cursor: zoom-in;
    transition: var(--transition);
}

.thumbnail:hover {
    transform: scale(1.1);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-pending {
    background: rgba(156, 163, 175, 0.15);
    color: #9ca3af;
    border: 1px solid rgba(156, 163, 175, 0.3);
}

.badge-processing {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.3);
    animation: pulse 1.5s infinite;
}

.badge-completed {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-failed {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
}

.status-healthy {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-healthy);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-moderate {
    background: rgba(234, 179, 8, 0.15);
    color: var(--color-moderate);
    border: 1px solid rgba(234, 179, 8, 0.3);
}

.status-high {
    background: rgba(249, 115, 22, 0.15);
    color: var(--color-high);
    border: 1px solid rgba(249, 115, 22, 0.3);
}

.status-critical {
    background: rgba(239, 68, 68, 0.15);
    color: var(--color-critical);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Actions Menu */
.actions-cell {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: var(--transition);
}

.btn-icon:hover {
    /* Was a white tint + #fff icon from the old dark theme, which made these
       icons vanish against the light table on hover. */
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

.btn-icon-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Results Viewer Modal */
.results-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    z-index: 500;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 30px;
    animation: fadeIn 0.4s ease;
}

.results-modal.active {
    display: flex;
}

.results-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    width: 100%;
    max-width: 1280px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
}

.results-header {
    padding: 25px 30px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 10;
}

.results-title {
    font-size: 1.4rem;
    font-weight: 700;
}

.close-modal-btn {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.close-modal-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    transform: rotate(90deg);
}

.results-body {
    padding: 30px;
}

/* Image grid side-by-side */
.results-image-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 40px;
}

@media (max-width: 768px) {
    .results-image-layout {
        grid-template-columns: 1fr;
    }
}

.image-panel {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
}

.image-panel-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.image-panel-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: normal;
}

.image-comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.image-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.image-box-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.result-image {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    object-fit: contain;
    aspect-ratio: 4/3;
    background: #f3f4f6;
}

/* Tube Analysis Stats Grid */
.tubes-analysis-section {
    margin-top: 30px;
}

.tubes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.tube-card {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 20px;
    transition: var(--transition);
}

.tube-card:hover {
    transform: translateY(-2px);
    border-color: rgba(0, 0, 0, 0.15);
}

.tube-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.tube-number {
    font-size: 1.1rem;
    font-weight: 700;
}

.tube-details-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.tube-details-row span:last-child {
    font-weight: 600;
    color: var(--text-primary);
}

.tube-severity-bar-wrapper {
    margin-top: 15px;
    background: rgba(255, 255, 255, 0.05);
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
}

.tube-severity-bar {
    height: 100%;
    border-radius: 3px;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

/* ==========================================================================
   Analytics & Results page
   ========================================================================== */

.analytics-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 18px 20px;
    margin: 22px 0;
}

.analytics-filter {
    display: flex;
    flex-direction: column;
    min-width: 190px;
}

.analytics-filter .form-label {
    margin-bottom: 6px;
}

.analytics-filter-actions {
    display: flex;
    gap: 10px;
    margin-left: auto;
}

/* Summary metric cards */
.analytics-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.analytics-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 18px 20px;
}

.analytics-card-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

.analytics-card-value {
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin-top: 6px;
}

.analytics-card-sub {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Chart panels */
.analytics-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 22px;
    margin-bottom: 24px;
}

.analytics-panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.analytics-panel-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.analytics-panel-sub {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin: 4px 0 0;
}

.analytics-chart-wrap {
    position: relative;
    width: 100%;
    min-height: 240px;
}

.analytics-grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 24px;
}

/* Explanatory note shown when a chart cannot be drawn from current data */
.analytics-note {
    background: rgba(37, 99, 235, 0.06);
    border: 1px solid rgba(37, 99, 235, 0.18);
    color: var(--text-secondary);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.83rem;
    line-height: 1.5;
    margin-bottom: 16px;
}

.analytics-note strong {
    color: var(--text-primary);
}

/* Demo-data indicator (mirrors the Tube Analysis Breakdown pill) */
.analytics-demo-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid #fde68a;
    background: #fffbeb;
    color: #b45309;
    border-radius: 999px;
    padding: 5px 14px;
    font-size: 0.75rem;
    font-weight: 700;
}

.analytics-demo-dot {
    height: 7px;
    width: 7px;
    border-radius: 50%;
    background: #f59e0b;
}

/* ==========================================================================
   Administration (RBAC) — user & model management
   ========================================================================== */

.user-menu-section-label {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    padding: 6px 12px 4px;
}

.flash-message {
    border-radius: 10px;
    padding: 13px 16px;
    margin: 18px 0 0;
    font-size: 0.9rem;
    border: 1px solid;
}

.flash-success {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: #047857;
}

.flash-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #b91c1c;
}

.admin-count-pill {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.admin-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 15px;
}

.admin-badge-admin {
    background: rgba(37, 99, 235, 0.12);
    color: #2563eb;
    font-weight: 700;
}

.admin-badge-user {
    background: rgba(107, 114, 128, 0.12);
    color: #4b5563;
    font-weight: 700;
}

.admin-you-tag {
    display: inline-block;
    margin-left: 6px;
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.admin-btn-sm {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.admin-btn-sm:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
}

.admin-btn-sm:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.admin-btn-danger {
    border-color: rgba(239, 68, 68, 0.35);
    color: #dc2626;
}

.admin-btn-danger:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #b91c1c;
}

.admin-inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}

/* ---- Model management ---- */
.model-warning {
    display: flex;
    gap: 12px;
    background: rgba(239, 68, 68, 0.06);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: var(--text-secondary);
    border-radius: 12px;
    padding: 15px 17px;
    margin: 20px 0;
    font-size: 0.86rem;
    line-height: 1.55;
}

.model-warning strong { color: var(--text-primary); }
.model-warning svg { color: #dc2626; }

.model-warning code,
.model-path code {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.85em;
}

.model-settings-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 22px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 18px;
    padding-left: 2px;
}

.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
    gap: 20px;
    margin-bottom: 22px;
}

.model-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 20px;
}

.model-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.model-card-title {
    font-size: 1rem;
    font-weight: 650;
    color: var(--text-primary);
    margin: 0 0 4px;
}

.model-card-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

.model-tag {
    display: inline-block;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    vertical-align: middle;
    margin-left: 6px;
}

.model-tag-required { background: rgba(37, 99, 235, 0.12); color: #2563eb; }
.model-tag-optional { background: rgba(107, 114, 128, 0.12); color: #4b5563; }

.model-status {
    flex-shrink: 0;
    border-radius: 999px;
    padding: 4px 11px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.model-status-ok { background: rgba(16, 185, 129, 0.12); color: #047857; }
.model-status-missing { background: rgba(239, 68, 68, 0.12); color: #b91c1c; }

.model-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
    margin: 0 0 12px;
}

.model-meta dt {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

.model-meta dd {
    margin: 2px 0 0;
    font-size: 0.86rem;
    color: var(--text-primary);
    font-weight: 600;
}

.model-path {
    font-family: ui-monospace, Menlo, monospace;
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    padding: 7px 9px;
    margin-bottom: 14px;
    overflow-wrap: anywhere;
}

.model-upload-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.model-upload-form .form-input {
    flex: 1;
    min-width: 170px;
    padding: 8px 10px;
    font-size: 0.82rem;
}
