/* Design Token Variables */
:root {
    --bg-primary: #080c14;
    --bg-secondary: #0d1527;
    --card-bg: rgba(17, 28, 52, 0.45);
    --border-color: rgba(255, 255, 255, 0.07);
    --accent-cyan: #00f0ff;
    --accent-blue: #3b82f6;
    
    /* Risk Levels Palette */
    --color-normal: #10b981;
    --color-normal-glow: rgba(16, 185, 129, 0.2);
    --color-mild: #f59e0b;
    --color-mild-glow: rgba(245, 158, 11, 0.2);
    --color-moderate: #f97316;
    --color-moderate-glow: rgba(249, 115, 22, 0.2);
    --color-severe: #ef4444;
    --color-severe-glow: rgba(239, 68, 68, 0.2);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Reset & Body */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Plus Jakarta Sans', 'Sarabun', 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    position: relative;
}

/* Dynamic Glow Background */
.glow-bg {
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.08) 0%, rgba(8, 12, 20, 0) 70%);
    top: 10%;
    left: 20%;
    z-index: 0;
    pointer-events: none;
    filter: blur(40px);
}

/* Main Container Layout */
.app-container {
    width: 100%;
    max-width: 1440px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    position: relative;
    z-index: 1;
}

/* Header Design */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo-icon {
    font-size: 2.5rem;
    color: var(--accent-cyan);
    filter: drop-shadow(0 0 10px rgba(0, 240, 255, 0.4));
}

.brand-text h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #ffffff 0%, var(--accent-cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-text p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.system-status {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 240, 255, 0.05);
    border: 1px solid rgba(0, 240, 255, 0.2);
    padding: 8px 16px;
    border-radius: 30px;
    font-size: 0.75rem;
    letter-spacing: 1px;
}

.status-pulse {
    width: 8px;
    height: 8px;
    background-color: var(--accent-cyan);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent-cyan);
    animation: pulse 1.5s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(0.9); opacity: 0.6; }
    100% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 12px var(--accent-cyan); }
}

/* Glassmorphism Panel Setup */
.app-content {
    display: grid;
    grid-template-columns: 320px 1fr 380px;
    gap: 24px;
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 24px;
    min-height: 520px;
}

.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.25);
    transition: var(--transition-smooth);
}

.glass-card:hover {
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.35);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 14px;
}

.panel-header i {
    font-size: 1.25rem;
    color: var(--accent-blue);
}

.panel-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Patient Form Inputs */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.input-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper i {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.input-wrapper input, .input-wrapper select {
    width: 100%;
    padding: 12px 14px 12px 40px;
    background: rgba(8, 12, 20, 0.5);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 10px;
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition-smooth);
}

.input-wrapper input:focus, .input-wrapper select:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.15);
}

.input-wrapper button {
    position: absolute;
    right: 8px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: var(--accent-blue);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
}

.input-wrapper button:hover {
    background: var(--accent-blue);
    color: white;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Preset Buttons Grid */
.presets-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.section-title h3 {
    font-size: 0.85rem;
    font-weight: 600;
}

.presets-section .description {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.presets-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preset-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition-smooth);
    text-align: left;
}

.preset-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.preset-btn.active {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--accent-blue);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.15);
}

.preset-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.preset-indicator.normal { background: var(--color-normal); box-shadow: 0 0 8px var(--color-normal); }
.preset-indicator.mild { background: var(--color-mild); box-shadow: 0 0 8px var(--color-mild); }
.preset-indicator.moderate { background: var(--color-moderate); box-shadow: 0 0 8px var(--color-moderate); }
.preset-indicator.severe { background: var(--color-severe); box-shadow: 0 0 8px var(--color-severe); }

.preset-label {
    flex-grow: 1;
    margin-left: 12px;
    font-weight: 500;
}

.preset-value {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Center Panel: Scanner Viewport */
.scanner-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
}

.viewport-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    max-width: 600px;
    background: #040810;
    border: 2px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
}

#webcam, #overlay-canvas {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 14px;
}

#overlay-canvas {
    z-index: 10;
    pointer-events: none;
}

/* Image Placeholder & Preset Views */
#image-placeholder {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    background: radial-gradient(circle, rgba(13, 21, 39, 0.9) 0%, rgba(4, 8, 16, 0.98) 100%);
    z-index: 5;
    transition: var(--transition-smooth);
}

#image-placeholder.hidden {
    opacity: 0;
    pointer-events: none;
}

.placeholder-icon {
    font-size: 3rem;
    color: var(--text-muted);
    opacity: 0.4;
    animation: breathe 3s infinite alternate;
}

@keyframes breathe {
    0% { transform: scale(0.95); opacity: 0.3; }
    100% { transform: scale(1.05); opacity: 0.5; }
}

#image-placeholder p {
    font-size: 0.85rem;
    max-width: 320px;
    line-height: 1.5;
}

/* Scanner Laser Sweep */
.scan-laser {
    position: absolute;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, rgba(0,240,255,0) 0%, rgba(0,240,255,1) 50%, rgba(0,240,255,0) 100%);
    top: 0;
    left: 0;
    z-index: 15;
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.8);
    display: none;
}

.scan-laser.scanning {
    display: block;
    animation: laser-sweep 2.5s ease-in-out infinite;
}

@keyframes laser-sweep {
    0% { top: 0%; }
    50% { top: 100%; }
    100% { top: 0%; }
}

/* Targeting Guides */
.scanner-guide {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: var(--transition-smooth);
}

.scanner-guide.active {
    opacity: 1;
}

.guide-circle {
    position: relative;
    width: 180px;
    height: 180px;
    border: 1px dashed rgba(0, 240, 255, 0.4);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: spin 30s linear infinite;
}

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

.guide-corner {
    position: absolute;
    width: 20px;
    height: 20px;
    border-color: var(--accent-cyan);
    border-style: solid;
    border-width: 0;
}

.guide-corner.tl { top: -2px; left: -2px; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 8px;}
.guide-corner.tr { top: -2px; right: -2px; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 8px;}
.guide-corner.bl { bottom: -2px; left: -2px; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 8px;}
.guide-corner.br { bottom: -2px; right: -2px; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 8px;}

.guide-center-dot {
    width: 6px;
    height: 6px;
    background-color: var(--accent-cyan);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-cyan);
}

.eyelid-guide {
    position: absolute;
    bottom: 12%;
    padding: 8px 16px;
    background: rgba(8, 12, 20, 0.85);
    border: 1px solid rgba(0, 240, 255, 0.2);
    border-radius: 8px;
}

.eyelid-guide span {
    font-size: 0.72rem;
    color: var(--accent-cyan);
    letter-spacing: 0.5px;
}

/* Controls buttons styling */
.scanner-controls {
    display: flex;
    gap: 12px;
    width: 100%;
}

.control-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 20px;
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition-smooth);
}

.primary-btn {
    background: linear-gradient(135deg, var(--accent-blue) 0%, #1d4ed8 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.primary-btn:hover:not(.disabled) {
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
    transform: translateY(-1px);
}

.primary-btn.disabled {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.upload-btn-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    flex: 1;
}

.upload-btn-wrapper input[type=file] {
    font-size: 100px;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
}

.sim-info-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    padding: 10px 16px;
    border-radius: 10px;
    width: 100%;
}

.sim-info-banner i {
    color: var(--accent-blue);
}

.sim-info-banner span {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.hidden {
    display: none !important;
}

/* Right Panel: AI Analytics Results Dashboard */
.results-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
}

/* No Result Idle State */
.no-result-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
    text-align: center;
    padding: 40px 0;
}

.no-result-state i {
    font-size: 3.5rem;
    opacity: 0.25;
}

.no-result-state p {
    font-size: 0.85rem;
}

/* Analyzing Loader Overlay */
.analysis-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 30px;
}

.loader-circle {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(0, 240, 255, 0.1);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: loader-spin 1s linear infinite;
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.15);
}

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

.loader-status {
    text-align: center;
}

.loader-status h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.loader-status p {
    font-size: 0.78rem;
    color: var(--accent-cyan);
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
    border-radius: 10px;
    transition: width 0.1s linear;
}

/* Results Dashboard Output */
.result-dashboard {
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: fade-in 0.5s ease-out forwards;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.risk-badge-container {
    display: flex;
    justify-content: center;
}

.risk-badge {
    padding: 10px 24px;
    border-radius: 30px;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 1px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.risk-badge.normal {
    background: var(--color-normal-glow);
    border: 1px solid var(--color-normal);
    color: var(--color-normal);
}

.risk-badge.mild {
    background: var(--color-mild-glow);
    border: 1px solid var(--color-mild);
    color: var(--color-mild);
}

.risk-badge.moderate {
    background: var(--color-moderate-glow);
    border: 1px solid var(--color-moderate);
    color: var(--color-moderate);
}

.risk-badge.severe {
    background: var(--color-severe-glow);
    border: 1px solid var(--color-severe);
    color: var(--color-severe);
    animation: danger-pulse 1.5s infinite alternate;
}

@keyframes danger-pulse {
    0% { box-shadow: 0 0 10px var(--color-severe-glow); }
    100% { box-shadow: 0 0 25px rgba(239, 68, 68, 0.4); }
}

.metrics-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.metric-card {
    background: rgba(8, 12, 20, 0.4);
    border: 1px solid var(--border-color);
    padding: 14px;
    border-radius: 12px;
}

.metric-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 6px;
}

.metric-value-wrapper {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 8px;
}

.metric-value {
    font-size: 1.6rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
}

.metric-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.metric-bar-container {
    height: 8px;
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    position: relative;
    overflow: visible;
    margin-top: 12px;
}

.metric-bar {
    height: 100%;
    border-radius: 4px;
    width: 100%;
}

.hb-bar {
    background: linear-gradient(90deg, var(--color-severe) 0%, var(--color-moderate) 30%, var(--color-mild) 60%, var(--color-normal) 100%);
}

.ri-bar {
    background: linear-gradient(90deg, var(--color-severe) 0%, var(--color-normal) 100%);
}

.marker {
    position: absolute;
    width: 6px;
    height: 14px;
    background-color: white;
    border-radius: 20px;
    top: -3px;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
    transition: left 0.5s ease-out;
}

.metric-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Spectrum Analysis Chart Layout */
.chart-container {
    background: rgba(8, 12, 20, 0.4);
    border: 1px solid var(--border-color);
    padding: 14px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chart-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.canvas-holder {
    position: relative;
    height: 110px;
    width: 100%;
}

/* Medical Advice Callout */
.advice-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed var(--border-color);
    padding: 14px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.advice-card.normal { border-color: rgba(16, 185, 129, 0.3); }
.advice-card.warning { border-color: rgba(245, 158, 11, 0.3); }
.advice-card.danger { border-color: rgba(239, 68, 68, 0.3); }

.advice-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.advice-header i {
    font-size: 0.85rem;
}

.advice-card.normal .advice-header i { color: var(--color-normal); }
.advice-card.warning .advice-header i { color: var(--color-mild); }
.advice-card.danger .advice-header i { color: var(--color-severe); }

.advice-header h4 {
    font-size: 0.78rem;
    font-weight: 600;
}

#advice-text {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Patient Logs History Footer */
.app-footer {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px;
}

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

.footer-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.footer-title i {
    font-size: 1.1rem;
    color: var(--accent-blue);
}

.footer-title h2 {
    font-size: 0.95rem;
    font-weight: 600;
}

.small-btn {
    padding: 8px 14px;
    font-size: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
}

/* History Log Table Layout */
.table-container {
    overflow-x: auto;
    width: 100%;
}

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

.history-table th, .history-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.history-table th {
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(8, 12, 20, 0.3);
}

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

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

.empty-row {
    text-align: center;
    color: var(--text-muted);
}

.empty-row td {
    padding: 24px !important;
}

.table-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    display: inline-block;
}

.table-badge.normal { background: rgba(16, 185, 129, 0.1); color: var(--color-normal); }
.table-badge.mild { background: rgba(245, 158, 11, 0.1); color: var(--color-mild); }
.table-badge.moderate { background: rgba(249, 115, 22, 0.1); color: var(--color-moderate); }
.table-badge.severe { background: rgba(239, 68, 68, 0.1); color: var(--color-severe); }

.action-icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 0.95rem;
    transition: var(--transition-smooth);
}

.action-icon-btn:hover {
    color: var(--accent-cyan);
}

.action-icon-btn.delete-row-btn:hover {
    color: var(--color-severe);
}

/* Responsive adjust */
@media (max-width: 1100px) {
    .app-content {
        grid-template-columns: 1fr;
    }
    
    .left-panel, .right-panel {
        min-height: auto;
    }
}
