:root {
    --bg-page: radial-gradient(circle at top, #0f172a, #070a12);
    --bg-container: rgba(15, 23, 42, 0.75);
    --bg-card: rgba(30, 41, 59, 0.3);
    --border-color: rgba(56, 189, 248, 0.12);
    --border-color-hover: rgba(56, 189, 248, 0.45);
    --accent-neon-cyan: #00f2fe;
    --accent-neon-blue: #38bdf8;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --glass-bg: rgba(15, 23, 42, 0.65);
    --glass-blur: 16px;
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    padding: 20px;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Custom scrollbars for premium feel */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: #070a12;
}
::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.25);
    border-radius: 4px;
    border: 2px solid #070a12;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-neon-cyan);
    box-shadow: 0 0 8px var(--accent-neon-cyan);
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: var(--bg-container);
    border-radius: 20px;
    padding: 25px;
    border: 1px solid var(--border-color);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.05);
    backdrop-filter: blur(20px);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 18px 24px;
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    flex-wrap: wrap;
    gap: 15px;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.05);
}

h1 {
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 50%, var(--accent-neon-cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.btn-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    background: rgba(30, 41, 59, 0.45);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition-smooth);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

button:hover:not(:disabled) {
    background: rgba(56, 189, 248, 0.12);
    color: white;
    border-color: var(--accent-neon-cyan);
    transform: translateY(-1px);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.35);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
    padding: 12px 18px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border-radius: 14px;
    border: 1px solid var(--border-color);
    box-shadow: var(--glass-shadow);
}

.tool-btn {
    background: rgba(30, 41, 59, 0.35);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition-smooth);
}

.tool-btn:hover:not(.active):not(:disabled) {
    background: rgba(56, 189, 248, 0.1);
    color: var(--text-primary);
    border-color: var(--accent-neon-cyan);
    transform: translateY(-1px);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.25);
}

.tool-btn.active, button.active {
    background: linear-gradient(135deg, rgba(0, 114, 255, 0.45) 0%, rgba(0, 242, 254, 0.45) 100%) !important;
    color: white !important;
    border-color: var(--accent-neon-cyan) !important;
    box-shadow: 0 0 15px rgba(0, 242, 254, 0.4) !important;
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.5);
}

.tool-btn.active:hover, button.active:hover {
    background: linear-gradient(135deg, rgba(0, 114, 255, 0.6) 0%, rgba(0, 242, 254, 0.6) 100%) !important;
    border-color: var(--accent-neon-cyan) !important;
}

.tool-btn.recording, button.recording {
    background: rgba(239, 68, 68, 0.25) !important;
    color: white !important;
    border-color: #ef4444 !important;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.45) !important;
    animation: pulse 1.5s infinite;
}

.tool-btn.recording:hover, button.recording:hover {
    background: rgba(239, 68, 68, 0.4) !important;
    border-color: #ef4444 !important;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.preset-menu {
    background: #0f172a;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    outline: none;
    transition: var(--transition-smooth);
}

.preset-menu:hover {
    border-color: var(--accent-neon-cyan);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.25);
}

.preset-menu option {
    background: #0f172a;
    color: var(--text-primary);
}

.roi-stats {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 14px 18px;
    margin-top: 10px;
    font-size: 13.5px;
    display: inline-block;
    min-width: 300px;
    box-shadow: var(--glass-shadow);
    color: var(--text-secondary);
}

.roi-stats h4 {
    color: var(--accent-neon-cyan);
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    text-shadow: 0 0 8px rgba(0, 242, 254, 0.35);
}

.roi-stats div {
    margin-bottom: 6px;
}

.roi-stats span {
    font-weight: bold;
    color: white;
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.25);
}

.frame-control {
    display: none;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    padding: 12px 24px;
    border-radius: 14px;
    margin-bottom: 24px;
    align-items: center;
    gap: 20px;
    border: 1px solid var(--border-color);
    flex-wrap: wrap;
    box-shadow: var(--glass-shadow);
}

.frame-control label {
    font-weight: bold;
    color: var(--accent-neon-cyan);
    font-size: 13px;
    white-space: nowrap;
    text-shadow: 0 0 8px rgba(0, 242, 254, 0.35);
}

.frame-slider {
    flex: 1;
    height: 6px;
    cursor: pointer;
    min-width: 200px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    -webkit-appearance: none;
}

.frame-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-neon-cyan);
    cursor: pointer;
    box-shadow: 0 0 8px var(--accent-neon-cyan);
    transition: var(--transition-smooth);
}

.frame-slider::-webkit-slider-thumb:hover {
    transform: scale(1.25);
    box-shadow: 0 0 14px var(--accent-neon-cyan);
}

.frame-label {
    font-weight: bold;
    color: var(--text-primary);
    min-width: 140px;
    text-align: right;
    font-size: 13.5px;
}

.canvas-container {
    background: #04060b;
    border-radius: 16px;
    padding: 12px;
    min-height: 650px;
    display: grid;
    gap: 12px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.8), 0 0 0 1px rgba(255, 255, 255, 0.05);
    width: 100%;
}

.viewport-box {
    position: relative;
    border: 2px solid rgba(255, 255, 255, 0.07);
    border-radius: 12px;
    background: #000000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    height: 100%;
    width: 100%;
}

.viewport-box.active {
    border-color: var(--accent-neon-cyan);
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.35);
}

.viewport-box canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: crosshair;
    background: #000000;
    border-radius: 8px;
}

.viewport-label {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(8px);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 11.5px;
    font-weight: 700;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.info {
    margin-top: 20px;
    padding: 14px 20px;
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    font-size: 13px;
    text-align: center;
    color: var(--text-secondary);
}

.status {
    color: var(--accent-neon-cyan);
    font-weight: bold;
    text-shadow: 0 0 8px rgba(0, 242, 254, 0.25);
}

.shortcuts-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 8px;
    opacity: 0.8;
}

@media (max-width: 768px) {
    body { padding: 10px; }
    .toolbar { justify-content: center; }
    button { padding: 8px 14px; font-size: 12px; }
    .header { flex-direction: column; align-items: stretch; }
    .btn-group { flex-direction: column; }
    .frame-control { flex-direction: column; align-items: stretch; }
    .frame-label { text-align: center; }
}

.header-image-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 24px;
    width: 100%;
}

.header-image {
    max-width: 35%;
    height: auto;
    border-radius: 12px;
    opacity: 0.9;
    filter: drop-shadow(0 0 15px rgba(56, 189, 248, 0.15));
}

/* Modal Emergente para el Informe Completo */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(5, 8, 17, 0.8);
    backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #0f172a;
    width: 90%;
    max-width: 700px;
    border-radius: 16px;
    border: 1px solid rgba(56, 189, 248, 0.2);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6), 0 0 25px rgba(56, 189, 248, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.9) 0%, rgba(30, 41, 59, 0.9) 100%);
    border-bottom: 1px solid rgba(56, 189, 248, 0.15);
    color: white;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(to right, var(--accent-neon-cyan), #ffffff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.6rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition-smooth);
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.modal-body {
    padding: 20px;
    background: #070b13;
    flex: 1;
}

.modal-body label {
    font-weight: 700;
    color: var(--accent-neon-cyan);
    font-size: 13px;
    text-shadow: 0 0 6px rgba(0, 242, 254, 0.2);
}

.modal-body textarea {
    width: 100%;
    height: 380px;
    padding: 14px;
    border: 1px solid rgba(56, 189, 248, 0.15);
    border-radius: 10px;
    background-color: #03050a;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13.5px;
    line-height: 1.5;
    resize: none;
    outline: none;
    color: #e2e8f0;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
    transition: var(--transition-smooth);
}

.modal-body textarea:focus {
    border-color: var(--accent-neon-cyan);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5), 0 0 15px rgba(0, 242, 254, 0.25);
}

.modal-body select, .modal-body input[type="text"], .modal-body input[type="password"] {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(56, 189, 248, 0.15);
    background: #03050a;
    color: var(--text-primary);
    outline: none;
    font-size: 14px;
    transition: var(--transition-smooth);
}

.modal-body select:focus, .modal-body input[type="text"]:focus, .modal-body input[type="password"]:focus {
    border-color: var(--accent-neon-cyan);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.25);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    background: #0f172a;
    border-top: 1px solid rgba(56, 189, 248, 0.15);
}

.modal-footer button {
    padding: 9px 16px;
    font-size: 13px;
}

.btn-secondary {
    background: #334155;
    border-color: rgba(255, 255, 255, 0.05);
}

.btn-secondary:hover {
    background: #475569;
}

/* --- AI Assistant UI --- */
.ai-settings-modal {
    max-width: 480px !important;
}

.ai-comparison-modal-content {
    max-width: 980px !important;
}

.ai-flex-container {
    display: flex;
    gap: 20px;
    margin-top: 10px;
}

.ai-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-column label {
    font-weight: 700;
    color: var(--accent-neon-cyan);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-column textarea {
    height: 320px !important;
    width: 100%;
    padding: 12px;
    border: 1px solid rgba(56, 189, 248, 0.15);
    border-radius: 10px;
    background-color: #03050a;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    line-height: 1.5;
    resize: none;
    outline: none;
    color: #e2e8f0;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.api-key-input-container {
    position: relative;
    width: 100%;
}

.api-key-input {
    width: 100%;
    padding: 10px 40px 10px 12px !important;
}

.toggle-pwd-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-secondary);
    box-shadow: none !important;
    transition: var(--transition-smooth);
}

.toggle-pwd-btn:hover {
    color: white;
    background: transparent !important;
    transform: translateY(-50%) scale(1.1) !important;
}

/* Overlay de carga de IA */
.ai-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 8, 17, 0.85);
    backdrop-filter: blur(12px);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 15px;
    color: white;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ai-loading-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.ai-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.05);
    border-top-color: var(--accent-neon-cyan);
    border-radius: 50%;
    animation: ai-spin 1s linear infinite;
    box-shadow: 0 0 15px rgba(0, 242, 254, 0.2);
}

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

.ai-loading-text {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
    animation: ai-pulse 1.5s ease-in-out infinite alternate;
    color: var(--accent-neon-cyan);
    text-shadow: 0 0 8px rgba(0, 242, 254, 0.35);
}

@keyframes ai-pulse {
    from {
        opacity: 0.6;
    }
    to {
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .ai-flex-container {
        flex-direction: column;
    }
    .ai-column textarea {
        height: 220px !important;
    }
}

/* Barra de progreso de carga de volumen DICOM (Web Workers) */
.progress-bar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 8, 17, 0.82);
    backdrop-filter: blur(12px);
    z-index: 1999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.35s ease;
}

.progress-bar-glass {
    width: 480px;
    padding: 32px 36px;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(0, 242, 254, 0.3);
    border-radius: 24px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7), 0 0 30px rgba(0, 242, 254, 0.12);
    display: flex;
    flex-direction: column;
    gap: 18px;
    text-align: center;
}

.progress-bar-icon {
    font-size: 36px;
    animation: progress-bounce 1.2s ease-in-out infinite;
}

@keyframes progress-bounce {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-6px); }
}

.progress-bar-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #ffffff, var(--accent-neon-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.progress-bar-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: -10px;
    opacity: 0.75;
}

.progress-bar-track {
    width: 100%;
    height: 14px;
    background: rgba(30, 41, 59, 0.7);
    border-radius: 7px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6);
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #0072ff 0%, #00c9ff 50%, #00f2fe 100%);
    border-radius: 7px;
    box-shadow: 0 0 14px rgba(0, 242, 254, 0.7);
    transition: width 0.2s ease-out;
    position: relative;
    overflow: hidden;
}

/* Shimmer effect en la barra */
.progress-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: -60%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
    animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
    0%   { left: -60%; }
    100% { left: 120%; }
}

.progress-bar-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-neon-cyan);
    text-shadow: 0 0 8px rgba(0, 242, 254, 0.3);
    letter-spacing: 0.3px;
}

.progress-bar-workers {
    font-size: 11px;
    color: rgba(148, 163, 184, 0.6);
    margin-top: -6px;
}

/* --- Histograma de Densidad Interactivo --- */
.histogram-container {
    display: inline-flex;
    flex-direction: column;
    background: rgba(30, 41, 59, 0.35);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 6px 12px;
    gap: 4px;
    align-items: center;
    position: relative;
    user-select: none;
    transition: var(--transition-smooth);
    min-width: 280px;
    align-self: center;
}

.histogram-container:hover {
    border-color: rgba(56, 189, 248, 0.35);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.15);
}

.histogram-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    pointer-events: none;
}

#histogramCanvas {
    background: #04060c;
    border: 1px solid rgba(56, 189, 248, 0.1);
    border-radius: 8px;
    cursor: ew-resize;
    display: block;
}

.histogram-values {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 10.5px;
    color: var(--text-secondary);
    font-family: monospace;
    pointer-events: none;
}

.histogram-values span {
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.1);
}

