/* ===========================================
   DFU Analysis — Premium Dark Theme CSS
   =========================================== */

/* ---- Reset & Base ---- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --bg-primary: #080a0f;
    --bg-secondary: #0d1117;
    --bg-card: #111827;
    --bg-card-hover: #151d2e;
    --bg-input: #0c1018;
    --bg-header: rgba(8, 10, 15, 0.85);

    --border: #1e293b;
    --border-hover: #334155;
    --border-focus: #6366f1;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-accent: #a5b4fc;

    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.25);

    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --info: #3b82f6;
    --info-bg: rgba(59, 130, 246, 0.12);

    /* Sizes */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Transitions */
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    /* Fonts */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* ---- Header ---- */
header {
    background: var(--bg-header);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 0 24px;
}

.header-content {
    max-width: 1800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-md);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #f1f5f9, #a5b4fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
    background: var(--bg-card);
    border: 1px solid var(--border);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 2s infinite;
}

.status-badge.online .status-dot {
    background: var(--success);
}

.status-badge.offline .status-dot {
    background: var(--danger);
    animation: none;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* ---- Pipeline Banner ---- */
.pipeline-banner {
    max-width: 1800px;
    margin: 16px auto 0;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.pipeline-step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: var(--transition);
}

.pipeline-step:hover {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

.step-num {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

.step-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.step-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.pipeline-arrow {
    font-size: 1.5rem;
    color: var(--accent);
    font-weight: 300;
}

/* ---- Main Layout ---- */
main {
    flex: 1;
    padding: 16px 24px 24px;
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
}

.main-grid {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 20px;
    margin-top: 16px;
}

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: var(--transition);
}

.card:hover {
    border-color: var(--border-hover);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
}

.btn-icon:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

/* ---- Source Tabs ---- */
.source-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--transition);
    position: relative;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
    color: var(--accent);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: var(--accent);
    border-radius: 2px 2px 0 0;
}

/* ---- Drop Zone ---- */
.source-panel {
    padding: 16px;
}

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.drop-zone p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 500;
}

.drop-zone span {
    color: var(--text-muted);
    font-size: 0.76rem;
}

/* ---- Preview ---- */
.preview-container {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    margin-top: 12px;
}

.preview-container img {
    width: 100%;
    height: auto;
    display: block;
    max-height: 260px;
    object-fit: contain;
    background: #000;
}

.btn-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.85);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    backdrop-filter: blur(8px);
}

.btn-remove:hover {
    background: var(--danger);
    transform: scale(1.1);
}

/* ---- Camera ---- */
.camera-controls {
    margin-bottom: 12px;
}

.camera-controls label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.camera-controls select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.82rem;
}

.camera-viewport {
    width: 100%;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
    position: relative;
    border: 1px solid var(--border);
    margin-bottom: 12px;
    /* Let the video dictate height instead of forcing aspect-ratio */
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.camera-viewport video {
    width: 100%;
    height: auto;
    max-height: 70vh;
    object-fit: contain;
    /* Show full frame, no cropping */
    display: block;
}

.camera-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.camera-actions .btn {
    flex: 1;
    min-width: 90px;
    font-size: 0.72rem;
    padding: 8px 10px;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-card);
    color: var(--text-primary);
    white-space: nowrap;
}

.btn:hover:not(:disabled) {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--text-accent);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.5);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.btn-danger:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.2);
}

.btn-predict {
    width: 100%;
    padding: 14px 20px;
    font-size: 0.95rem;
    font-weight: 700;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: 1px solid rgba(139, 92, 246, 0.4);
    color: white;
    border-radius: var(--radius-lg);
    margin-top: 12px;
    letter-spacing: 0.01em;
    position: relative;
    overflow: hidden;
}

.btn-predict::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.6s ease;
}

.btn-predict:hover:not(:disabled)::before {
    left: 100%;
}

.btn-predict:hover:not(:disabled) {
    box-shadow: 0 4px 30px rgba(99, 102, 241, 0.35);
    transform: translateY(-1px);
}

.btn-predict:active:not(:disabled) {
    transform: translateY(0);
}

/* ---- Configuration ---- */
.config-body {
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.82rem;
    transition: var(--transition);
}

.form-group select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.range-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.range-group input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.range-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg-card);
    box-shadow: 0 0 8px var(--accent-glow);
}

.range-val {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent);
    min-width: 36px;
    text-align: center;
}

.form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ---- Checkbox ---- */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--border);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    background: var(--bg-input);
    flex-shrink: 0;
}

.checkbox-label input:checked+.checkmark {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox-label input:checked+.checkmark::after {
    content: '✓';
    color: white;
    font-size: 11px;
    font-weight: 700;
}

/* ---- Log ---- */
.log-card {
    margin-top: 12px;
}

.log-area {
    padding: 12px 16px;
    max-height: 240px;
    overflow-y: auto;
    font-size: 0.76rem;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    line-height: 1.7;
}

.log-entry {
    margin-bottom: 4px;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.log-info {
    color: var(--text-muted);
}

.log-success {
    color: var(--success);
}

.log-error {
    color: var(--danger);
}

.log-warn {
    color: var(--warning);
}

/* ---- Results Area ---- */
.results-area {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.results-card {
    min-height: 140px;
}

.placeholder-text {
    padding: 40px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.placeholder-text p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---- Classification Result ---- */
.clf-content {
    padding: 0;
}

.clf-content img {
    width: 100%;
    height: auto;
    display: block;
}

.result-badge {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.result-badge.ulcer {
    background: var(--danger-bg);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.result-badge.healthy {
    background: var(--success-bg);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

/* ---- Segmentation Results ---- */
.seg-content {
    padding: 0;
}

.seg-images {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 16px;
}

.seg-img-wrapper {
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
    background: #000;
    transition: var(--transition);
}

.seg-img-wrapper:hover {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
    transform: scale(1.01);
}

.seg-img-wrapper h3 {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 8px 12px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.seg-img-wrapper img {
    width: 100%;
    height: auto;
    display: block;
    min-height: 180px;
    object-fit: contain;
}

.seg-stats {
    display: flex;
    gap: 8px;
}

.stat-pill {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 500;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--text-accent);
}

/* ---- Download Buttons ---- */
.download-btns {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.download-btns .btn {
    flex: 1;
}

/* ---- Loading Overlay ---- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(8, 10, 15, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    text-align: center;
}

.spinner-ring {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    margin: 0 4px;
    animation: spin 1s ease-in-out infinite;
}

.spinner-ring:nth-child(2) {
    width: 36px;
    height: 36px;
    animation-delay: 0.15s;
    border-top-color: #8b5cf6;
}

.spinner-ring:nth-child(3) {
    width: 24px;
    height: 24px;
    animation-delay: 0.3s;
    border-top-color: #a78bfa;
}

.loading-spinner p {
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---- Footer ---- */
footer {
    padding: 16px 24px;
    text-align: center;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

footer p {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ---- Utility ---- */
.hidden {
    display: none !important;
}

/* ---- Responsive ---- */
@media (max-width: 1200px) {
    .main-grid {
        grid-template-columns: 320px 1fr;
    }

    .seg-images {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 900px) {
    .main-grid {
        grid-template-columns: 1fr;
    }

    .pipeline-banner {
        flex-direction: column;
        gap: 10px;
    }

    .pipeline-arrow {
        transform: rotate(90deg);
        font-size: 1rem;
    }

    .seg-images {
        grid-template-columns: 1fr;
    }

    .header-content {
        height: auto;
        padding: 12px 0;
        flex-wrap: wrap;
        gap: 8px;
    }

    .download-btns {
        flex-direction: column;
    }
}

@media (max-width: 600px) {
    main {
        padding: 10px 12px 16px;
    }

    .card-header {
        padding: 10px 14px;
    }

    .seg-stats {
        flex-wrap: wrap;
    }
}

/* ---- Animations ---- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    animation: fadeIn 0.4s ease-out;
}

.results-card {
    animation: fadeIn 0.5s ease-out;
}