/* ═══════════════════════════════════════════════════════════════
   غِراس — Interactive Sensor Network Simulation
   Premium dark theme · glassmorphism · animated data flow
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
    --bg-base: #04060b;
    --bg-primary: #06090f;
    --bg-secondary: #0a0f1a;
    --bg-tertiary: #0e1525;
    --bg-card: rgba(12, 18, 32, 0.7);
    --bg-card-solid: #0c1220;
    --bg-glass: rgba(8, 14, 28, 0.85);
    --bg-glass-light: rgba(14, 22, 40, 0.6);
    --bg-glass-ultra: rgba(6, 10, 20, 0.92);

    --border-dim: rgba(255, 255, 255, 0.04);
    --border-subtle: rgba(255, 255, 255, 0.07);
    --border-accent: rgba(74, 222, 128, 0.2);
    --border-glow: rgba(74, 222, 128, 0.4);

    --text-primary: #ffffff;
    --text-secondary: #cdd6e4;
    --text-muted: #99a8bc;
    --text-accent: #4ade80;
    --text-accent-bright: #6aee9a;

    --accent-green: #4ade80;
    --accent-emerald: #34d399;
    --accent-cyan: #22d3ee;
    --accent-blue: #3b82f6;
    --accent-purple: #a78bfa;
    --accent-amber: #fbbf24;
    --accent-rose: #fb7185;
    --accent-orange: #fb923c;

    --gradient-main: linear-gradient(135deg, #4ade80, #22d3ee);
    --gradient-hero: linear-gradient(135deg, #4ade80 0%, #22d3ee 50%, #3b82f6 100%);
    --gradient-card: linear-gradient(160deg, rgba(74, 222, 128, 0.05), rgba(34, 211, 238, 0.03));

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 16px 64px rgba(0, 0, 0, 0.6);
    --shadow-glow-sm: 0 0 20px rgba(74, 222, 128, 0.06);
    --shadow-glow-md: 0 0 40px rgba(74, 222, 128, 0.1);
    --shadow-glow-lg: 0 4px 60px rgba(74, 222, 128, 0.15);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --font-sans: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-fast: 0.2s var(--ease-out);
    --transition-normal: 0.35s var(--ease-out);
    --transition-slow: 0.6s var(--ease-out);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(74, 222, 128, 0.15) transparent;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    line-height: 1.6;
    cursor: default;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(74, 222, 128, 0.15);
    border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(74, 222, 128, 0.3);
}

/* ── Loading Screen ────────────────────────────────────────── */
#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    transition: opacity 0.8s ease, visibility 0.8s ease;
}

#loading-screen.fade-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

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

.loader-orb {
    width: 80px;
    height: 80px;
    margin: 0 auto 32px;
    position: relative;
}

.loader-orb::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent 0%, var(--accent-green) 40%, var(--accent-cyan) 60%, transparent 100%);
    animation: orb-spin 1.5s linear infinite;
}

.loader-orb::after {
    content: '';
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    background: var(--bg-base);
}

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

.loader-content h1 {
    font-size: 28px;
    font-weight: 800;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.loader-content p {
    font-size: 13px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-bottom: 32px;
}

.loader-track {
    width: 240px;
    height: 3px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 auto;
}

.loader-fill {
    height: 100%;
    width: 0%;
    background: var(--gradient-main);
    border-radius: 4px;
    animation: fill-progress 2s ease-in-out forwards;
}

@keyframes fill-progress {
    0% { width: 0%; }
    30% { width: 50%; }
    70% { width: 85%; }
    100% { width: 100%; }
}

/* ── Background Effects ────────────────────────────────────── */
.bg-grid {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(74, 222, 128, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(74, 222, 128, 0.03) 1px, transparent 1px);
    background-size: 80px 80px;
    mask-image: radial-gradient(ellipse 80% 60% at 50% 50%, black 20%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 50%, black 20%, transparent 70%);
}

.bg-glow {
    position: fixed;
    z-index: 0;
    pointer-events: none;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.3;
}

.bg-glow-1 {
    width: 600px;
    height: 600px;
    top: -200px;
    left: -100px;
    background: rgba(74, 222, 128, 0.08);
}

.bg-glow-2 {
    width: 500px;
    height: 500px;
    top: 40%;
    right: -150px;
    background: rgba(34, 211, 238, 0.06);
}

.bg-glow-3 {
    width: 400px;
    height: 400px;
    bottom: -100px;
    left: 30%;
    background: rgba(59, 130, 246, 0.05);
}

/* ── Navigation ────────────────────────────────────────────── */
#top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 28px;
    background: var(--bg-glass-ultra);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    border-bottom: 1px solid var(--border-dim);
    transition: all var(--transition-normal);
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.nav-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition-fast);
}

.nav-back:hover {
    background: rgba(74, 222, 128, 0.1);
    color: var(--accent-green);
    border-color: var(--border-accent);
    transform: translateX(-2px);
}

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

.brand-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #22d3ee, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.brand-text {
    font-size: 16px;
    font-weight: 800;
    background: var(--gradient-main);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.brand-tag {
    font-size: 9px;
    font-weight: 700;
    font-family: var(--font-mono);
    padding: 3px 10px;
    border-radius: 20px;
    background: rgba(34, 211, 238, 0.1);
    color: var(--accent-cyan);
    border: 1px solid rgba(34, 211, 238, 0.2);
    text-transform: uppercase;
}

.nav-center {
    display: flex;
    align-items: center;
    gap: 16px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.net-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: var(--bg-glass-light);
    border: 1px solid var(--border-dim);
    border-radius: 20px;
    font-size: 12px;
    transition: all var(--transition-fast);
}

.net-stat:hover {
    border-color: var(--border-accent);
    box-shadow: var(--shadow-glow-sm);
}

.net-stat-icon {
    font-size: 14px;
}

.net-stat-value {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--accent-green);
    font-size: 13px;
}

.net-stat-label {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.nav-btn:hover {
    background: rgba(74, 222, 128, 0.08);
    color: var(--text-primary);
    border-color: var(--border-accent);
}

.nav-btn svg {
    width: 16px;
    height: 16px;
}

/* ── 3D Canvas ─────────────────────────────────────────────── */
#network-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    cursor: grab;
}

#network-canvas:active {
    cursor: grabbing;
}

/* ── Sensor Detail Panel ───────────────────────────────────── */
.detail-panel {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 500;
    width: 380px;
    max-height: calc(100vh - 120px);
    background: var(--bg-glass-ultra);
    backdrop-filter: blur(30px) saturate(1.4);
    -webkit-backdrop-filter: blur(30px) saturate(1.4);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-lg);
    box-shadow:
        var(--shadow-lg),
        var(--shadow-glow-md),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    overflow: hidden;
    transition: all 0.4s var(--ease-out);
    overflow-y: auto;
}

.detail-panel.hidden {
    opacity: 0;
    transform: translateX(40px) scale(0.95);
    pointer-events: none;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-dim);
    background: rgba(0, 0, 0, 0.2);
}

.detail-title-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.detail-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(74, 222, 128, 0.15), rgba(34, 211, 238, 0.1));
    border: 1px solid var(--border-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.detail-header h3 {
    font-size: 16px;
    font-weight: 800;
    margin-bottom: 2px;
}

.detail-zone {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.detail-close-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.detail-close-btn:hover {
    background: rgba(244, 63, 94, 0.15);
    border-color: var(--accent-rose);
    color: var(--accent-rose);
}

.detail-body {
    padding: 18px 22px;
}

/* Status Row */
.detail-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.status-badge.online {
    background: rgba(74, 222, 128, 0.1);
    color: var(--accent-green);
    border: 1px solid rgba(74, 222, 128, 0.25);
}

.status-badge.warning {
    background: rgba(251, 191, 36, 0.1);
    color: var(--accent-amber);
    border: 1px solid rgba(251, 191, 36, 0.25);
}

.status-badge.offline {
    background: rgba(251, 113, 133, 0.1);
    color: var(--accent-rose);
    border: 1px solid rgba(251, 113, 133, 0.25);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 currentColor; }
    50% { opacity: 0.6; box-shadow: 0 0 0 4px transparent; }
}

.detail-id {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 6px;
}

/* Data Grid */
.detail-data-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 18px;
}

.data-card {
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.data-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 3px;
    height: 100%;
    border-radius: 0 3px 3px 0;
    opacity: 0.6;
}

.data-card:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border-accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow-sm);
}

.data-card .data-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 6px;
}

.data-card .data-value {
    font-size: 22px;
    font-weight: 800;
    font-family: var(--font-mono);
    line-height: 1.2;
}

.data-card .data-unit {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    margin-right: 4px;
}

.data-card .data-trend {
    font-size: 10px;
    margin-top: 4px;
    font-weight: 600;
}

.data-card .data-trend.up { color: var(--accent-rose); }
.data-card .data-trend.down { color: var(--accent-green); }
.data-card .data-trend.stable { color: var(--text-muted); }

/* Mini Chart */
.detail-chart-container {
    margin-bottom: 18px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-sm);
}

.detail-chart-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 10px;
}

#detail-mini-chart {
    width: 100%;
    height: 80px;
    border-radius: 6px;
}

/* Metadata */
.detail-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.015);
    border-radius: 6px;
    font-size: 12px;
}

.meta-row .meta-key {
    color: var(--text-muted);
    font-weight: 600;
}

.meta-row .meta-val {
    font-family: var(--font-mono);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 11px;
}

/* ── Legend Panel ──────────────────────────────────────────── */
#legend-panel {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 500;
    padding: 14px 18px;
    background: var(--bg-glass-ultra);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    transition: all var(--transition-normal);
}

#legend-panel:hover {
    border-color: var(--border-accent);
    box-shadow: var(--shadow-glow-md);
}

.legend-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-accent);
    margin-bottom: 10px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.legend-divider {
    width: 100%;
    height: 1px;
    background: var(--border-dim);
    margin: 4px 0;
}

/* ── Controls Hint ─────────────────────────────────────────── */
#controls-hint {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 8px 22px;
    background: var(--bg-glass-ultra);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-dim);
    border-radius: 30px;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    opacity: 0.7;
    transition: opacity var(--transition-normal);
}

#controls-hint:hover {
    opacity: 1;
}

#controls-hint span {
    white-space: nowrap;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .nav-center {
        display: none;
    }

    .detail-panel {
        width: calc(100vw - 32px);
        right: 16px;
        top: auto;
        bottom: 16px;
        max-height: 50vh;
    }

    #legend-panel {
        bottom: auto;
        top: 70px;
        left: 16px;
        padding: 10px 14px;
    }

    .legend-items {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }

    #controls-hint {
        display: none;
    }
}

@media (max-width: 640px) {
    #top-nav {
        padding: 10px 14px;
    }

    .brand-tag {
        display: none;
    }

    .nav-right {
        gap: 6px;
    }

    .nav-btn span {
        display: none;
    }

    .nav-btn {
        padding: 8px;
    }

    #legend-panel {
        display: none;
    }
}
