/* ═══════════════════════════════════════════════════════════════
   LBVC Dashboard — Glassmorphism Theme
   ═══════════════════════════════════════════════════════════════ */

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

:root {
    --bg-primary: #0a0a1a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.07);
    --border-card: rgba(255, 255, 255, 0.08);
    --border-card-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #e8e8f0;
    --text-secondary: rgba(255, 255, 255, 0.55);
    --text-muted: rgba(255, 255, 255, 0.35);
    --accent-1: #7c5cfc;
    --accent-2: #5b8def;
    --accent-3: #c084fc;
    --green: #34d399;
    --red: #f87171;
    --orange: #fb923c;
    --gold: #fbbf24;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
}

/* ── Light Theme ─────────────────────────────────────────────── */

html.light {
    --bg-primary: #f0f2f5;
    --bg-card: rgba(255, 255, 255, 0.7);
    --bg-card-hover: rgba(255, 255, 255, 0.9);
    --border-card: rgba(0, 0, 0, 0.08);
    --border-card-hover: rgba(0, 0, 0, 0.15);
    --text-primary: #1a1a2e;
    --text-secondary: rgba(0, 0, 0, 0.55);
    --text-muted: rgba(0, 0, 0, 0.35);
    --accent-1: #6c4ce6;
    --accent-2: #4a7de0;
    --accent-3: #a855f7;
    --green: #059669;
    --red: #dc2626;
    --orange: #ea580c;
    --gold: #d97706;
}

html.light .orb { opacity: 0.12; }
html.light .total-number {
    background: linear-gradient(135deg, #1a1a2e, var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    overflow-x: clip;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: clip;
    width: 100%;
    max-width: 100vw;
    -webkit-font-smoothing: antialiased;
    transition: background 0.3s, color 0.3s;
}

/* ── Background Orbs ─────────────────────────────────────────── */

.bg-orbs {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    max-width: 100vw;
    max-height: 100vh;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.35;
    animation: float 20s infinite ease-in-out;
    transition: opacity 0.3s;
}

.orb-1 { width: 500px; height: 500px; background: var(--accent-1); top: -10%; left: -5%; animation-delay: 0s; }
.orb-2 { width: 400px; height: 400px; background: var(--accent-2); bottom: -10%; right: -5%; animation-delay: -7s; }
.orb-3 { width: 350px; height: 350px; background: var(--accent-3); top: 40%; left: 50%; animation-delay: -14s; }

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33%      { transform: translate(40px, -30px) scale(1.05); }
    66%      { transform: translate(-20px, 20px) scale(0.95); }
}

/* ── Container ───────────────────────────────────────────────── */

.container {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem 3rem;
    overflow-x: hidden;
}

/* ── Header ──────────────────────────────────────────────────── */

.header {
    text-align: center;
    margin-bottom: 2rem;
    animation: fadeInDown 0.6s ease-out;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.title {
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2), var(--accent-3));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s;
}

.status.connected .status-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status.disconnected .status-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }

/* ── Theme Toggle ────────────────────────────────────────────── */

.theme-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 999px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s, border-color 0.3s;
    font-size: 1rem;
    color: var(--text-primary);
}
.theme-toggle:hover { background: var(--bg-card-hover); border-color: var(--border-card-hover); }

.total-counter {
    margin-top: 0.75rem;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.5rem;
}

.total-number {
    font-size: 3rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fff, var(--accent-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    transition: opacity 0.3s;
}

.total-label {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Record Banner ───────────────────────────────────────────── */

.record-banner {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-card);
    border-radius: 16px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: fadeInUp 0.5s ease-out 0.1s both;
    overflow: hidden;
    max-width: 100%;
}

.record-icon { font-size: 1.5rem; flex-shrink: 0; }
.record-text { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.record-text .record-name { color: var(--gold); }
.record-text .record-value { color: var(--text-secondary); font-weight: 400; }

/* ── Search Bar ──────────────────────────────────────────────── */

.search-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-card);
    border-radius: 12px;
    padding: 0.6rem 1rem;
    margin-bottom: 1.5rem;
    transition: border-color 0.3s;
}
.search-bar:focus-within { border-color: var(--accent-2); }
.search-icon { font-size: 1rem; opacity: 0.5; }
#searchInput {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9rem;
    width: 100%;
}
#searchInput::placeholder { color: var(--text-muted); }

/* ── Server Grid ─────────────────────────────────────────────── */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
    gap: 1rem;
    max-width: 100%;
}

/* ── Server Card ─────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border-card);
    border-radius: 16px;
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    transition: background 0.3s, border-color 0.3s, transform 0.3s, box-shadow 0.3s;
    animation: fadeInUp 0.5s ease-out both;
    will-change: transform;
    overflow: hidden;
    max-width: 100%;
}

.card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-card-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(124, 92, 252, 0.08);
}

.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.card-rank { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); min-width: 28px; }
.card-rank.top-1 { color: var(--gold); }
.card-rank.top-2 { color: #c0c0c0; }
.card-rank.top-3 { color: #cd7f32; }

.card-name {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 700;
    margin-left: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-trend {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    margin-left: 0.5rem;
    white-space: nowrap;
}

.card-trend.up { color: var(--green); background: rgba(52, 211, 153, 0.1); }
.card-trend.down { color: var(--red); background: rgba(248, 113, 113, 0.1); }
.card-trend.stable { color: var(--text-muted); background: rgba(255, 255, 255, 0.04); }

.card-members { font-size: 2rem; font-weight: 800; margin-bottom: 0.5rem; letter-spacing: -0.02em; }
.card-members .unit { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); margin-left: 0.25rem; }

/* ── Sparkline ───────────────────────────────────────────────── */

.card-sparkline { width: 100%; height: 40px; margin-bottom: 0.75rem; overflow: hidden; }
.card-sparkline svg { width: 100%; height: 100%; display: block; max-width: 100%; }
.sparkline-line { fill: none; stroke: var(--accent-2); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.sparkline-area { fill: url(#sparkGradient); opacity: 0.3; }

/* ── Stats Row ───────────────────────────────────────────────── */

.card-stats { display: flex; gap: 1rem; flex-wrap: wrap; }
.stat { display: flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; color: var(--text-secondary); }
.stat-icon { font-size: 0.85rem; opacity: 0.7; }
.stat-value { font-weight: 600; color: var(--text-primary); }

/* ── Toast Notifications ─────────────────────────────────────── */

.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    padding: 0.7rem 1.2rem;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    animation: toastIn 0.4s ease-out;
    pointer-events: auto;
}
.toast-up { background: rgba(52, 211, 153, 0.15); border: 1px solid rgba(52, 211, 153, 0.3); color: var(--green); }
.toast-down { background: rgba(248, 113, 113, 0.15); border: 1px solid rgba(248, 113, 113, 0.3); color: var(--red); }
.toast-exit { animation: toastOut 0.3s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }

/* ═══════════════════════════════════════════════════════════════
   Detail Overlay
   ═══════════════════════════════════════════════════════════════ */

.detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    overflow-y: auto;
    opacity: 0;
    transition: opacity 0.3s;
}
.detail-overlay.active { display: block; opacity: 1; }

.detail-panel {
    max-width: 800px;
    margin: 2rem auto;
    background: var(--bg-primary);
    border: 1px solid var(--border-card);
    border-radius: 20px;
    padding: 2rem;
    animation: fadeInUp 0.4s ease-out;
}

.detail-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }

.detail-back {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 10px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s;
}
.detail-back:hover { background: var(--bg-card-hover); }

.detail-title { flex: 1; font-size: 1.5rem; font-weight: 800; }
.detail-rank { font-size: 1rem; font-weight: 700; color: var(--text-muted); }

/* ── Detail Stats Grid ───────────────────────────────────────── */

.detail-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
    margin-bottom: 2rem;
}
.detail-stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
}
.detail-stat-value { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.25rem; }
.detail-stat-label { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Section Titles ──────────────────────────────────────────── */

.detail-section { margin-bottom: 2rem; }
.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

/* ── 12h Chart ───────────────────────────────────────────────── */

.detail-chart {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 12px;
    padding: 1rem;
    height: 220px;
}
#chartCanvas { width: 100%; height: 100%; display: block; }
.chart-tooltip {
    position: absolute;
    display: none;
    background: var(--bg-primary);
    border: 1px solid var(--border-card-hover);
    border-radius: 8px;
    padding: 0.4rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
}

/* ── Hourly Bar Chart ────────────────────────────────────────── */

.hourly-chart {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 120px;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 12px;
    padding: 1rem 0.75rem 1.5rem;
}
.hourly-bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
}
.hourly-bar {
    width: 100%;
    max-width: 20px;
    border-radius: 4px 4px 0 0;
    background: var(--accent-2);
    transition: height 0.5s ease-out;
    min-height: 2px;
}
.hourly-bar.peak { background: var(--accent-1); }
.hourly-label { font-size: 0.55rem; color: var(--text-muted); margin-top: 4px; }

/* ── History List ────────────────────────────────────────────── */

.history-list { display: flex; flex-direction: column; gap: 0.5rem; }
.history-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
}
.history-date { color: var(--text-secondary); }
.history-peak { font-weight: 700; }
.history-time { color: var(--text-muted); font-size: 0.8rem; }

/* ── Footer ──────────────────────────────────────────────────── */

.footer {
    text-align: center;
    margin-top: 2.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Animations ──────────────────────────────────────────────── */

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 640px) {
    body { overflow-x: hidden; -webkit-overflow-scrolling: touch; }
    .container { padding: 1.25rem 0.75rem 2rem; }
    .title { font-size: 1.4rem; }
    .total-number { font-size: 2.2rem; }
    .total-label { font-size: 0.85rem; }
    .grid { grid-template-columns: 1fr; }
    .card { padding: 1rem 1.1rem; backdrop-filter: none; -webkit-backdrop-filter: none; }
    .card-members { font-size: 1.6rem; }
    .card-name { font-size: 0.95rem; }
    .card-stats { gap: 0.6rem; }
    .stat { font-size: 0.72rem; }
    .record-banner { padding: 0.75rem 1rem; border-radius: 12px; backdrop-filter: none; -webkit-backdrop-filter: none; }
    .record-text { font-size: 0.85rem; }
    .search-bar { padding: 0.5rem 0.85rem; backdrop-filter: none; -webkit-backdrop-filter: none; }
    .bg-orbs { display: none; }
    .toast { backdrop-filter: none; -webkit-backdrop-filter: none; }

    /* Detail overlay — full screen on mobile */
    .detail-overlay {
        background: var(--bg-primary);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        overflow-x: hidden;
    }
    .detail-panel {
        margin: 0;
        padding: 1rem 1rem 2rem;
        border: none;
        border-radius: 0;
        min-height: 100vh;
        min-height: 100dvh;
        overflow-x: hidden;
        max-width: 100vw;
    }
    .detail-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--bg-primary);
        padding: 0.75rem 0;
        margin-bottom: 1rem;
        border-bottom: 1px solid var(--border-card);
    }
    .detail-title { font-size: 1.2rem; }
    .detail-rank { font-size: 0.85rem; }
    .detail-back { width: 36px; height: 36px; font-size: 1rem; }
    .detail-stats { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; margin-bottom: 1.5rem; }
    .detail-stat-card { padding: 0.75rem 0.5rem; }
    .detail-stat-value { font-size: 1.25rem; }
    .detail-stat-label { font-size: 0.65rem; }
    .detail-section { margin-bottom: 1.5rem; }
    .detail-section { overflow: hidden; }
    .detail-chart { height: 180px; padding: 0.75rem; max-width: 100%; overflow: hidden; }
    #chartCanvas { max-width: 100%; }
    .hourly-chart { height: 100px; padding: 0.75rem 0.4rem 1.25rem; gap: 1px; max-width: 100%; overflow: hidden; }
    .hourly-bar { max-width: 10px; }
    .hourly-label { font-size: 0.45rem; }
    .history-entry { padding: 0.6rem 0.85rem; font-size: 0.8rem; }

    /* Toast on mobile — bottom center */
    .toast-container {
        top: auto;
        bottom: 1.25rem;
        right: 0.75rem;
        left: 0.75rem;
        align-items: stretch;
    }
    .toast { text-align: center; font-size: 0.8rem; }
}
