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

/* ── Design tokens ─────────────────────────────────────────────── */
:root {
    --bg:           #f1f4f8;
    --surface:      #ffffff;
    --surface-2:    #f8fafc;
    --border:       #e2e8f0;
    --border-2:     #cbd5e1;

    --text:         #1a2332;
    --text-2:       #475569;
    --text-3:       #94a3b8;

    --cpu:          #2563eb;
    --mem:          #059669;
    --disk:         #d97706;
    --net-recv:     #0891b2;
    --net-sent:     #7c3aed;

    --ok:           #059669;
    --warn:         #d97706;
    --danger:       #dc2626;

    --radius:       8px;
    --radius-sm:    5px;
    --shadow:       0 1px 3px rgba(0, 0, 0, 0.07);
}

/* ── Base ──────────────────────────────────────────────────────── */
body {
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Page wrapper ──────────────────────────────────────────────── */
.page {
    max-width: 1480px;
    margin: 0 auto;
    padding: 20px 24px 48px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ── Header ────────────────────────────────────────────────────── */
.header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.header-title h1 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.header-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.meta-chip {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-2);
    white-space: nowrap;
}

.meta-chip.meta-time {
    color: var(--text-3);
    font-weight: 500;
}

/* ── Metric Cards ──────────────────────────────────────────────── */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--border-2);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
    display: grid;
    grid-template-areas:
        "label  ring"
        "value  ring"
        "unit   ring"
        "sub    ring";
    grid-template-columns: 1fr auto;
    column-gap: 14px;
    row-gap: 2px;
    align-content: center;
    transition: border-top-color 0.3s;
}

.metric-card.status-ok     { border-top-color: var(--ok); }
.metric-card.status-warn   { border-top-color: var(--warn); }
.metric-card.status-danger { border-top-color: var(--danger); }

.metric-label {
    grid-area: label;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
}

.metric-value {
    grid-area: value;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text);
    margin-top: 2px;
}

.metric-unit {
    grid-area: unit;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-2);
}

.metric-sub {
    grid-area: sub;
    font-size: 0.7rem;
    color: var(--text-3);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ring {
    grid-area: ring;
    width: 54px;
    height: 54px;
}

.ring-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 5;
}

.ring-fill {
    fill: none;
    stroke-width: 5;
    stroke-linecap: butt;
    transform-origin: 32px 32px;
    transform: rotate(-90deg);
    transition: stroke-dashoffset 0.4s ease;
}

#card-cpu     .ring-fill { stroke: var(--cpu); }
#card-memory  .ring-fill { stroke: var(--mem); }
#card-disk    .ring-fill { stroke: var(--disk); }
#card-network .ring-fill { stroke: var(--net-recv); }

/* ── Charts ────────────────────────────────────────────────────── */
.charts-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    min-width: 0;
}

.chart-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 18px;
    min-width: 0;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 10px;
}

.panel-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
}

.panel-subtitle {
    font-size: 0.72rem;
    color: var(--text-3);
}

.chart-panel canvas {
    display: block;
    width: 100% !important;
    min-width: 0;
    max-height: 190px;
}

/* ── Sections ──────────────────────────────────────────────────── */
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 16px;
    cursor: pointer;
    user-select: none;
    background: var(--surface);
    transition: background 0.12s;
}

.section-header:hover {
    background: var(--surface-2);
}

.section-toggle-icon {
    font-size: 0.85rem;
    color: var(--text-3);
    transition: transform 0.2s ease;
    line-height: 1;
    flex-shrink: 0;
}

.section.collapsed .section-toggle-icon {
    transform: rotate(-90deg);
}

.section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
}

.section-meta {
    font-size: 0.73rem;
    color: var(--text-3);
}

.section-badge {
    display: inline-block;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-3);
    line-height: 1.5;
}

.section-body {
    border-top: 1px solid var(--border);
}

.section.collapsed .section-body {
    display: none;
}

/* ── Subsections ───────────────────────────────────────────────── */
.subsection + .subsection {
    border-top: 1px solid var(--border);
}

.subsection-title {
    padding: 8px 16px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-3);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

/* ── Tables ────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 480px;
}

.data-table th {
    padding: 8px 14px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    text-align: left;
}

.data-table th.th-r {
    text-align: right;
}

.data-table th.th-narrow {
    width: 72px;
}

.data-table td {
    padding: 8px 14px;
    font-size: 0.82rem;
    color: var(--text-2);
    border-bottom: 1px solid var(--border);
    font-weight: 500;
    text-align: left;
}

.data-table td.td-r {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.data-table td.td-name {
    font-weight: 600;
    color: var(--text);
}

.data-table td.td-muted {
    color: var(--text-3);
    font-size: 0.78rem;
}

.data-table td.td-mono {
    font-family: "SF Mono", "Consolas", "Liberation Mono", monospace;
    font-size: 0.78rem;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover td {
    background: #f5f8fc;
}

.td-empty {
    text-align: center !important;
    color: var(--text-3) !important;
    padding: 18px 14px !important;
    font-style: italic;
    font-size: 0.8rem !important;
}

/* ── Disk mount cards ──────────────────────────────────────────── */
.mounts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    padding: 14px 16px;
}

.mount-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: var(--surface-2);
}

.mount-path {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.mount-path-label {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mount-pct {
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

.mount-bar {
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin: 6px 0;
}

.mount-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.mount-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-3);
}

/* ── System Info Bar ───────────────────────────────────────────── */
.sysinfo-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-wrap: wrap;
    overflow: hidden;
}

.sysinfo-item {
    flex: 1;
    min-width: 110px;
    padding: 10px 16px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sysinfo-item:last-child {
    border-right: none;
}

.sysinfo-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-3);
}

.sysinfo-value {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 1100px) {
    .metrics-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .page {
        padding: 12px 12px 36px;
        gap: 10px;
    }

    .metrics-row {
        grid-template-columns: 1fr 1fr;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    .sysinfo-bar {
        flex-direction: column;
    }

    .sysinfo-item {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sysinfo-item:last-child {
        border-bottom: none;
    }

    .mounts-grid {
        grid-template-columns: 1fr;
    }
}
