/* ============================================
   LongevityCreation Digital Twin - Dark Sci-Fi Theme v2.0
   ============================================ */

/* ============== THEME VARIABLES ============== */

body.page-digital-twin {
    --dt-bg: #0a0a1a;
    --dt-bg-panel: #0f0f2a;
    --dt-accent: #00D4FF;
    --dt-accent-dim: rgba(0, 212, 255, 0.15);
    --dt-text: #e0e0f0;
    --dt-text-muted: #8888aa;
    --dt-border: rgba(0, 212, 255, 0.12);
    --dt-optimal: #00ff88;
    --dt-high: #ff4466;
    --dt-low: #ffaa00;
    background: var(--dt-bg);
}

/* ============== MAIN LAYOUT ============== */

.digital-twin-main {
    background: var(--dt-bg);
    min-height: 100vh;
    padding: 24px 32px;
}

.digital-twin-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

/* ============== BREADCRUMB ============== */

.dt-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--dt-text-muted);
    margin-bottom: 20px;
}

.dt-breadcrumb a {
    color: var(--dt-accent);
    text-decoration: none;
    transition: opacity 200ms;
}

.dt-breadcrumb a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.dt-breadcrumb-sep {
    color: var(--dt-text-muted);
    opacity: 0.5;
}

/* ============== 70/30 LAYOUT ============== */

.dt-layout {
    display: flex;
    gap: 24px;
    height: calc(100vh - 140px);
}

/* ============== LEFT: 3D CANVAS ============== */

.dt-canvas-wrapper {
    flex: 7;
    position: relative;
    border: 1px solid var(--dt-border);
    border-radius: 16px;
    overflow: hidden;
    background: radial-gradient(ellipse at center, #0a0a2e 0%, #050510 100%);
}

#dtCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* R3F container (replaces #dtCanvas at runtime) */
#dtCanvas-r3f-container {
    width: 100%;
    height: 100%;
}

#dtCanvas-r3f-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* ============== RIGHT: DETAIL PANEL ============== */

.dt-detail-panel {
    flex: 3;
    background: var(--dt-bg-panel);
    border: 1px solid var(--dt-border);
    border-radius: 16px;
    padding: 24px;
    overflow-y: auto;
    color: var(--dt-text);
}

.dt-detail-panel.dt-panel-fade {
    opacity: 0.4;
    transition: opacity 0.15s ease-out;
}

.dt-panel-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--dt-text);
    margin: 0 0 4px 0;
}

.dt-panel-header p {
    font-size: 13px;
    color: var(--dt-text-muted);
    margin: 0 0 20px 0;
}

/* ============== METRIC CARDS ============== */

.dt-metrics-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Card enter animation */
@keyframes dt-card-enter {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.dt-metric-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--dt-border);
    border-radius: 12px;
    padding: 16px;
    transition: all 200ms;
    animation: dt-card-enter 0.3s ease-out both;
}

.dt-metric-card:nth-child(1) { animation-delay: 0.0s; }
.dt-metric-card:nth-child(2) { animation-delay: 0.05s; }
.dt-metric-card:nth-child(3) { animation-delay: 0.05s; }
.dt-metric-card:nth-child(4) { animation-delay: 0.1s; }
.dt-metric-card:nth-child(5) { animation-delay: 0.15s; }
.dt-metric-card:nth-child(6) { animation-delay: 0.2s; }
.dt-metric-card:nth-child(7) { animation-delay: 0.25s; }
.dt-metric-card:nth-child(8) { animation-delay: 0.3s; }
.dt-metric-card:nth-child(9) { animation-delay: 0.35s; }
.dt-metric-card:nth-child(10) { animation-delay: 0.4s; }

.dt-metric-card:hover {
    background: rgba(0, 212, 255, 0.05);
    border-color: rgba(0, 212, 255, 0.25);
}

.dt-metric-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.dt-metric-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--dt-text);
}

.dt-metric-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 100px;
}

.dt-metric-badge.status-optimal {
    color: var(--dt-optimal);
    background: rgba(0, 255, 136, 0.1);
}

.dt-metric-badge.status-high {
    color: var(--dt-high);
    background: rgba(255, 68, 102, 0.1);
}

.dt-metric-badge.status-low {
    color: var(--dt-low);
    background: rgba(255, 170, 0, 0.1);
}

.dt-metric-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--dt-text);
    margin-bottom: 8px;
}

/* ============== RANGE BAR ============== */

.dt-range-bar-container {
    width: 100%;
}

.dt-range-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    position: relative;
    overflow: visible;
}

.dt-range-optimal {
    position: absolute;
    height: 100%;
    background: rgba(0, 255, 136, 0.2);
    border-radius: 3px;
}

.dt-range-marker {
    position: absolute;
    top: -3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--dt-accent);
    border: 2px solid var(--dt-bg-panel);
    transform: translateX(-50%);
}

.dt-range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--dt-text-muted);
    margin-top: 4px;
}

/* Reference range "Normal" label */
.dt-range-label-normal {
    position: absolute;
    top: -16px;
    font-size: 9px;
    color: var(--dt-text-muted);
    transform: translateX(-50%);
}

/* ============== METRIC ANALYSIS (expandable) ============== */

.dt-metric-analysis {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--dt-border);
    font-size: 12px;
    color: var(--dt-text-muted);
    line-height: 1.5;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.dt-metric-card.expanded .dt-metric-analysis {
    max-height: 200px;
}

.dt-metric-expand-btn {
    display: inline-block;
    margin-top: 6px;
    font-size: 11px;
    color: var(--dt-accent);
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    font-family: inherit;
}

.dt-metric-expand-btn:hover {
    text-decoration: underline;
}

/* ============== HEALTH SUMMARY DASHBOARD ============== */

.dt-health-summary {
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.08), rgba(0, 255, 136, 0.05));
    border: 1px solid var(--dt-border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.dt-health-score {
    font-size: 36px;
    font-weight: 700;
    color: var(--dt-accent);
    line-height: 1;
}

.dt-health-score-label {
    font-size: 11px;
    color: var(--dt-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dt-health-summary-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dt-health-summary-stat {
    font-size: 12px;
    color: var(--dt-text);
    display: flex;
    align-items: center;
    gap: 6px;
}

.dt-health-summary-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ============== SYSTEM INDICATOR CARDS ============== */

.dt-system-indicators {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.dt-system-card {
    flex: 1;
    min-width: 120px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--dt-border);
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: all 200ms;
}

.dt-system-card:hover {
    background: rgba(0, 212, 255, 0.08);
    border-color: rgba(0, 212, 255, 0.3);
}

.dt-system-card.active {
    background: rgba(0, 212, 255, 0.1);
    border-color: var(--dt-accent);
}

.dt-system-card-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--dt-text);
    margin-bottom: 2px;
}

.dt-system-card-count {
    font-size: 11px;
    color: var(--dt-text-muted);
}

.dt-system-card-status {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
}

/* ============== HOVER TOOLTIP ============== */

.dt-hover-tooltip {
    position: fixed;
    z-index: 1000;
    background: rgba(10, 10, 26, 0.95);
    border: 1px solid var(--dt-accent);
    border-radius: 8px;
    padding: 8px 12px;
    pointer-events: none;
}

.dt-tooltip-region {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--dt-accent);
}

.dt-tooltip-count {
    display: block;
    font-size: 11px;
    color: var(--dt-text-muted);
}

/* ============== EMPTY STATE OVERLAY ============== */

.dt-empty-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 26, 0.8);
    z-index: 10;
}

.dt-empty-content {
    text-align: center;
    color: var(--dt-text);
}

.dt-empty-content h3 {
    font-size: 20px;
    margin: 16px 0 8px;
}

.dt-empty-content p {
    font-size: 14px;
    color: var(--dt-text-muted);
    margin-bottom: 20px;
}

.dt-upload-btn {
    display: inline-block;
    padding: 10px 24px;
    background: var(--dt-accent);
    color: #0a0a1a;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    transition: opacity 200ms;
}

.dt-upload-btn:hover {
    opacity: 0.85;
}

/* ============== LEGEND BAR ============== */

.dt-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    padding: 16px 0;
    margin-top: 12px;
}

.dt-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--dt-text-muted);
}

.dt-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dt-legend-btn {
    background: rgba(0, 212, 255, 0.08);
    border: 1px solid var(--dt-border);
    color: var(--dt-accent);
    padding: 6px 14px;
    border-radius: 100px;
    font-size: 12px;
    font-family: 'DM Sans', sans-serif;
    cursor: pointer;
    transition: all 200ms;
}

.dt-legend-btn:hover {
    background: rgba(0, 212, 255, 0.15);
}

/* ============== LOADING SKELETON ============== */

.dt-loading-skeleton {
    animation: dt-skeleton-pulse 1.5s infinite ease-in-out;
}

@keyframes dt-skeleton-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

.dt-skeleton-bar {
    background: var(--dt-border);
    border-radius: 4px;
    height: 16px;
    margin-bottom: 12px;
}

.dt-skeleton-bar.short { width: 60%; }
.dt-skeleton-bar.medium { width: 80%; }
.dt-skeleton-bar.long { width: 100%; }

/* ============== METRICS EMPTY STATE ============== */

.dt-metrics-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--dt-text-muted);
    font-size: 14px;
}

/* ============== SCROLLBAR ============== */

.dt-detail-panel::-webkit-scrollbar {
    width: 4px;
}

.dt-detail-panel::-webkit-scrollbar-track {
    background: transparent;
}

.dt-detail-panel::-webkit-scrollbar-thumb {
    background: rgba(0, 212, 255, 0.2);
    border-radius: 2px;
}

/* ============== AUTH SCREENS (DARK OVERRIDES) ============== */

body.page-digital-twin .auth-check-screen {
    color: var(--dt-text);
}

body.page-digital-twin .auth-check-screen p {
    color: var(--dt-text-muted);
}

body.page-digital-twin .not-auth-card {
    background: var(--dt-bg-panel);
    border: 1px solid var(--dt-border);
    color: var(--dt-text);
}

body.page-digital-twin .not-auth-card h2 {
    color: var(--dt-text);
}

body.page-digital-twin .not-auth-card p {
    color: var(--dt-text-muted);
}

body.page-digital-twin .spinner-large {
    border-color: var(--dt-border);
    border-top-color: var(--dt-accent);
}

/* ============== BACKGROUND STATS ============== */

.dt-background-stats {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 5;
    pointer-events: none;
}

.dt-bg-stat {
    display: flex;
    flex-direction: column;
    background: rgba(0, 212, 255, 0.06);
    border: 1px solid var(--dt-border);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 100px;
}

.dt-bg-stat-label {
    font-size: 10px;
    color: var(--dt-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dt-bg-stat-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--dt-accent);
}

/* ============== COMPARTMENT PANELS ============== */

.dt-compartment-wrapper {
    pointer-events: auto;
}

.dt-compartment {
    background: rgba(10, 10, 26, 0.92);
    border: 1px solid rgba(0, 212, 255, 0.2);
    border-radius: 8px;
    padding: 6px 10px;
    min-width: 100px;
    max-width: 160px;
    cursor: grab;
    transition: all 200ms ease;
    animation: dt-comp-enter 0.3s ease-out both;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    font-family: 'DM Sans', sans-serif;
    user-select: none;
}

@keyframes dt-comp-enter {
    from { opacity: 0; }
    to { opacity: 1; }
}

.dt-compartment:hover,
.dt-compartment.active {
    background: rgba(10, 10, 36, 0.96);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.15);
}

.dt-compartment.status-high { border-color: rgba(255, 68, 102, 0.4); }
.dt-compartment.status-high.active { border-color: #ff4466; box-shadow: 0 0 12px rgba(255, 68, 102, 0.2); }
.dt-compartment.status-low { border-color: rgba(255, 170, 0, 0.4); }
.dt-compartment.status-low.active { border-color: #ffaa00; box-shadow: 0 0 12px rgba(255, 170, 0, 0.2); }
.dt-compartment.status-optimal { border-color: rgba(0, 255, 136, 0.3); }
.dt-compartment.status-optimal.active { border-color: #00ff88; box-shadow: 0 0 12px rgba(0, 255, 136, 0.15); }

.dt-comp-header {
    display: flex;
    align-items: center;
    gap: 5px;
}

.dt-comp-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dt-comp-label {
    font-size: 11px;
    font-weight: 600;
    color: #e0e0f0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dt-comp-count {
    font-size: 9px;
    color: #8888aa;
    background: rgba(255, 255, 255, 0.06);
    padding: 1px 5px;
    border-radius: 100px;
}

.dt-comp-metrics {
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dt-comp-metric {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 10px;
}

.dt-comp-metric-name {
    color: #8888aa;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 6px;
}

.dt-comp-metric-value {
    color: #e0e0f0;
    font-weight: 600;
    white-space: nowrap;
}

.dt-comp-metric.status-high .dt-comp-metric-value { color: #ff4466; }
.dt-comp-metric.status-low .dt-comp-metric-value { color: #ffaa00; }
.dt-comp-metric.status-optimal .dt-comp-metric-value { color: #00ff88; }

.dt-compartment.dragging {
    cursor: grabbing;
    opacity: 0.85;
    transition: none;
}

/* ============== RESPONSIVE ============== */

@media (max-width: 1024px) {
    .dt-layout {
        flex-direction: column;
        height: auto;
    }

    .dt-canvas-wrapper {
        flex: none;
        height: 55vh;
    }

    .dt-detail-panel {
        flex: none;
        max-height: 45vh;
    }
}

@media (max-width: 768px) {
    .digital-twin-main {
        padding: 12px;
    }

    .dt-layout {
        gap: 12px;
    }

    .dt-background-stats {
        display: none !important;
    }

    .dt-canvas-wrapper {
        height: 45vh;
    }

    .dt-detail-panel {
        max-height: none;
        border-radius: 12px 12px 0 0;
    }

    .dt-health-summary {
        flex-direction: column;
        text-align: center;
    }

    .dt-system-indicators {
        gap: 6px;
    }

    .dt-system-card {
        min-width: 90px;
        padding: 8px;
    }

    .dt-breadcrumb {
        margin-bottom: 12px;
    }

    .dt-compartment {
        min-width: 70px;
        max-width: 100px;
        padding: 4px 6px;
    }
    .dt-comp-metrics { display: none; }
    .dt-comp-label { font-size: 9px; }
    .dt-comp-count { font-size: 8px; }
}
