/* ═══════════════════════════════════════════════════════════════
   Dashboard — Main Stylesheet
   Dark theme, responsive, panel-based layout
   ═══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0d1117;
    --bg-glass: rgba(255, 255, 255, 0.10);
    --bg-glass-strong: rgba(255, 255, 255, 0.14);
    --bg-glass-card: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.18);
    --border-hover: rgba(255, 255, 255, 0.5);
    --glass-blur: blur(12px);
    --text-primary: #e6edf3;
    --text-secondary: #c9d1d9;
    --text-muted: #d0d7de;
    --text-dim: #8b949e;

    --green: #3fb950;
    --green-bg: #238636;
    --blue: #58a6ff;
    --blue-bg: #1f6feb;
    --purple: #bc8cff;
    --purple-bg: #8957e5;
    --yellow: #d29922;
    --yellow-bg: #9e6a03;
    --red: #f85149;
    --orange: #db6d28;

    --bar-height: 6px;
    --bar-radius: 3px;
    --card-radius: 8px;
    --transition: 0.2s ease;
}

html {
    font-size: 14px;
}

body {
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Background layers ──────────────────────────────────────── */
#background-layer {
    position: fixed;
    top: -10%; left: -10%;
    width: 120%; height: 120%;
    background: var(--bg-image) center/cover no-repeat;
    z-index: -2;
    transform-origin: center center;
}




#overlay-soft {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, var(--overlay-opacity, 0.55));
    backdrop-filter: blur(var(--overlay-blur, 0px));
    -webkit-backdrop-filter: blur(var(--overlay-blur, 0px));
    z-index: 0;
    pointer-events: none;
}

.container {
    max-width: 1920px;
    margin: 0 auto;
    padding: 24px 20px 40px;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Push monitor + footer to bottom via elastic spacing */
#services {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
    align-content: start;
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

/* ── Monitor Section ──────────────────────────────────────────── */
.monitor-section {
    margin-top: 12px;
}

.monitor-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}

/* ── Master-Detail Layout ─────────────────────────────────────── */
.dashboard-layout {
    display: flex;
    gap: 20px;
    align-items: stretch;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
    width: 340px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: sticky;
    top: 20px;
    align-self: flex-start;
    height: 252px;
}

/* ── Sidebar Item ──────────────────────────────────────────────── */
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-glass);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: border-color var(--transition), background var(--transition), transform var(--transition);
    flex: 1;
    min-height: 0;
}

.sidebar-item:hover {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.18);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.06);
    transform: scale(1.02);
}

.sidebar-item.active {
    border-color: rgba(88, 166, 255, 0.7);
    background: rgba(88, 166, 255, 0.15);
    box-shadow: 0 0 24px rgba(88, 166, 255, 0.1);
}

.sidebar-item .panel-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
    line-height: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-item .panel-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    min-width: 36px;
}

.sidebar-item .panel-summary {
    margin-left: auto;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
}

.sidebar-item .panel-arrow {
    font-size: 0.65rem;
    color: var(--text-dim);
    flex-shrink: 0;
    width: 12px;
    text-align: center;
}

/* ── Detail Area ───────────────────────────────────────────────── */
.detail {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 252px;
}

.detail-placeholder {
    background: var(--bg-glass);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px dashed var(--border);
    border-radius: var(--card-radius);
    padding: 60px 20px;
    text-align: center;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.placeholder-text {
    font-size: 0.9rem;
    color: var(--text-dim);
}

.detail-content {
    display: none;
    flex: 1;
    background: var(--bg-glass);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    padding: 14px 20px 16px;
    animation: fadeIn 0.25s ease forwards;
}

.detail-content.visible {
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
}

/* ── Detail Panel Body ───────────────────────────────────────── */
.detail-content .panel-body {
    display: block !important;
    padding: 0;
    animation: none;
    flex: 1;
}

/* 2-column stat grid for CPU/Memory compact layout */
.detail-body-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 24px;
    align-items: baseline;
}

.detail-body-stats .bar {
    grid-column: 1 / -1;
    margin-bottom: 6px;
    height: 8px;
}

.detail-body-stats .stat-row {
    padding: 3px 0;
}

.detail-body-stats .stat-label {
    min-width: 66px;
    font-size: 0.82rem;
}

.detail-body-stats .stat-value {
    font-size: 0.82rem;
}

.detail-body-stats .core-grid {
    grid-column: 1 / -1;
    margin-top: 8px;
}

.detail-body-stats .core-grid {
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    gap: 3px;
}

.detail-body-stats .core-bar {
    height: 28px;
}

/* ── GPU detail grid (2-column stat rows) ───────────────────── */
.gpu-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 24px;
    align-items: baseline;
}

.gpu-detail-grid .stat-row {
    padding: 2px 0;
}

.gpu-detail-grid .stat-label {
    min-width: 60px;
    font-size: 0.82rem;
}

.gpu-detail-grid .stat-value {
    font-size: 0.82rem;
}

/* ── GPU grid (stacked rows with divider) ──────────────────── */
.gpu-grid {
}

.gpu-grid .gpu-card {
    padding: 0 0 10px;
}

.gpu-grid .gpu-card + .gpu-card {
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

/* ── GPU card flex layout (stats left + chart right) ─────── */
.gpu-body {
    display: flex;
    flex-direction: row;
    gap: 10px;
    align-items: stretch;
}
.gpu-stats {
    flex: 0 0 auto;
    min-width: 280px;
}
.gpu-chart-wrap {
    flex: 1;
    min-width: 0;
    position: relative;
    height: 100px;
    align-self: center;
}
.gpu-chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ── Disk grid (stacked rows with divider) ─────────────────── */
.disk-grid {
}

.disk-grid .gpu-card {
    padding: 0 0 10px;
}

.disk-grid .gpu-card + .gpu-card {
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

/* ── Card (service links) ──────────────────────────────────── */
.card {
    background: var(--bg-glass-strong);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    padding: 16px;
    text-decoration: none;
    color: inherit;
    transition: border-color var(--transition), background var(--transition), transform var(--transition);
    display: flex;
    flex-direction: column;
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.18);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.06);
    transform: scale(1.02);
}

.card-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-icon {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* SVG icons for sidebar and cards */
.svg-icon {
    width: 18px;
    height: 18px;
    display: block;
    filter: brightness(0) saturate(100%) invert(80%) sepia(10%) saturate(200%) hue-rotate(180deg);
    opacity: 0.85;
    transition: opacity var(--transition);
}
.sidebar-item:hover .svg-icon,
.card:hover .svg-icon {
    opacity: 1;
}
.card .svg-icon {
    width: 20px;
    height: 20px;
}

.card .url {
    font-size: 0.8rem;
    color: var(--blue);
    margin-top: 4px;
    word-break: break-all;
}

.card .desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Responsive: stack on small screens ──────────────────────── */
@media (max-width: 820px) {
    .dashboard-layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .sidebar-item {
        flex: 1;
        min-width: 140px;
    }
}

/* ── Progress Bar ────────────────────────────────────────────── */
.bar {
    height: var(--bar-height);
    background: var(--bg-tertiary);
    border-radius: var(--bar-radius);
    overflow: hidden;
    margin-bottom: 8px;
}

.bar-fill {
    height: 100%;
    border-radius: var(--bar-radius);
    transition: width 1s ease;
    min-width: 2px;
}

.bar-green  { background: linear-gradient(90deg, var(--green), var(--green-bg)); }
.bar-blue   { background: linear-gradient(90deg, var(--blue), var(--blue-bg)); }
.bar-purple { background: linear-gradient(90deg, var(--purple), var(--purple-bg)); }
.bar-yellow { background: linear-gradient(90deg, var(--yellow), var(--yellow-bg)); }
.bar-orange { background: linear-gradient(90deg, var(--orange), #b7611e); }
.bar-red    { background: linear-gradient(90deg, var(--red), #b73a3a); }

/* ── Memory chart (Chart.js) ──────────────────────────────────── */
.mem-chart-wrap {
    margin-top: 4px;
    height: 105px;
}
.mem-chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ── Network charts ──────────────────────────────────────────── */
.net-charts {
    display: flex;
    flex-direction: row;
    gap: 6px;
    margin-top: 4px;
    height: 155px;
    overflow: hidden;
}
.net-chart-wrap {
    flex: 1;
    position: relative;
}
.net-chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ── Stat Rows (key-value layout) ─────────────────────────────── */
.stat-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 0;
    min-height: 22px;
}

.stat-row + .stat-row {
    margin-top: 2px;
}

.stat-label {
    color: var(--text-muted);
    min-width: 60px;
    flex-shrink: 0;
    font-size: 0.82rem;
}

.stat-value {
    color: var(--text-primary);
    font-weight: 500;
    margin-left: auto;
    text-align: right;
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
}

.stat-sub-value {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-left: 4px;
}

/* ── Per-Core Grid ───────────────────────────────────────────── */
.core-grid {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 4px;
    margin-top: 8px;
    flex: 1;
}

.core-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.core-label {
    font-size: 0.65rem;
    color: var(--text-dim);
}

.core-bar {
    width: 100%;
    height: 40px;
    background: var(--bg-glass-card);
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}

.core-fill {
    position: absolute;
    bottom: 0;
    width: 100%;
    border-radius: 3px;
    transition: height 1s ease;
    min-height: 2px;
}

.core-val {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ── Grid for services / bookmarks ──────────────────────────── */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 8px;
}

.grid-title {
    grid-column: 1 / -1;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 0 4px;
}

/* ── Header / Title ──────────────────────────────────────────── */
.header {
    display: none;
}

/* ── Footer ──────────────────────────────────────────────────── */
footer {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.75rem;
    margin-top: 8px;
    padding: 6px 0;
    border-top: 1px solid var(--border);
}
#footer-img {
    width: 20%;
    height: auto;
    display: inline-block;
    opacity: 0.5;
}

/* ── Loading state ──────────────────────────────────────────── */
.panel-loading {
    opacity: 0.4;
    pointer-events: none;
}

.panel-error {
    border-color: var(--red);
}

.panel-error .panel-body {
    color: var(--red);
    font-size: 0.8rem;
}

/* ── Animations ─────────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.panel {
    animation: fadeIn 0.3s ease forwards;
}

.panel:nth-child(2) { animation-delay: 0.05s; }
.panel:nth-child(3) { animation-delay: 0.1s; }
.panel:nth-child(4) { animation-delay: 0.15s; }
.panel:nth-child(5) { animation-delay: 0.2s; }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(33, 38, 45, 0.6); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ═══════════════════════════════════════════════════════════════
   Responsive — Mobile / Tablet Adaptations
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .container {
        padding: 16px 12px 24px;
    }
    .header h1 {
        font-size: 1.1rem;
    }
    .header {
        margin-bottom: 16px;
        padding-bottom: 10px;
    }
    /* Services: single column */
    .grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    /* Master-detail: stack vertically */
    .dashboard-layout {
        flex-direction: column;
        gap: 12px;
    }
    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: column;
        gap: 6px;
        position: static;
        align-self: auto;
    }
    .sidebar-item {
        flex: none;
        padding: 8px 10px;
        gap: 6px;
    }
    .sidebar-item .panel-icon {
        font-size: 0.95rem;
        width: 20px;
    }
    .sidebar-item .panel-title {
        font-size: 0.75rem;
        min-width: 28px;
    }
    .sidebar-item .panel-summary {
        font-size: 0.7rem;
    }
    .sidebar-item .panel-arrow {
        font-size: 0.55rem;
    }
    .detail {
        height: auto;
        min-height: 200px;
    }
    .detail-content {
        padding: 10px 12px 12px;
    }
    /* Stats: single column on very narrow */
    .detail-body-stats,
    .gpu-detail-grid {
        grid-template-columns: 1fr;
        gap: 2px 12px;
    }
    .detail-body-stats .stat-row,
    .gpu-detail-grid .stat-row {
        min-height: 20px;
        padding: 1px 0;
    }
    /* Core grid: 8 columns instead of 16 */
    .detail-body-stats .core-grid {
        grid-template-columns: repeat(8, 1fr);
    }
    /* 移动端隐藏所有核心的百分比数值 */
    .core-grid > .core-item > .core-val {
        display: none;
    }
    .core-bar {
        height: 30px;
    }
    /* GPU layout: stack vertically */
    .gpu-body {
        flex-direction: column;
        gap: 6px;
    }
    .gpu-stats {
        min-width: 0;
    }
    .gpu-chart-wrap {
        height: 100px;
        width: 100%;
    }
    .gpu-card {
        padding: 0 0 8px;
    }
    /* Network charts: shorter */
    .net-charts {
        height: 100px;
    }
    /* Memory chart: shorter */
    .mem-chart-wrap {
        height: 80px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 0.95rem;
    }
    .sidebar-item {
        padding: 6px 8px;
    }
    .sidebar-item .panel-title {
        display: none;
    }
    .sidebar-item .panel-summary {
        font-size: 0.65rem;
        min-width: 0;
    }
    .detail {
        min-height: 160px;
    }
    .detail-body-stats .core-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .core-grid > .core-item > .core-val {
        display: none;
    }
    .core-bar {
        height: 24px;
    }
    .gpu-chart-wrap {
        height: 70px;
    }
    .net-charts {
        height: 75px;
    }
    .mem-chart-wrap {
        height: 60px;
    }
}
