:root {
    --bg-color: #0d1117;
    --card-bg: rgba(22, 27, 34, 0.7);
    --accent-color: #58a6ff;
    --text-primary: #c9d1d9;
    --text-muted: #8b949e;
    --success: #3fb950;
    --warning: #d29922;
    --danger: #f85149;
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    padding: 2rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    margin-bottom: 3rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#dashboard-meta {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.connection-ok {
    color: var(--success);
}

.connection-error {
    color: var(--danger);
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -1px;
}

h2 {
    margin: 2rem 0 1rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 2px;
}

.badge {
    background: var(--success);
    color: white;
    font-size: 0.4em;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    vertical-align: middle;
    margin-left: 0.5rem;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.endpoint-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
    gap: 1rem;
}

.endpoint-card {
    background: rgba(22, 27, 34, 0.8);
    border: 1px solid var(--glass-border);
    border-left: 4px solid var(--text-muted);
    border-radius: 8px;
    padding: 1rem;
}

.endpoint-green { border-left-color: var(--success); }
.endpoint-yellow { border-left-color: var(--warning); }
.endpoint-red { border-left-color: var(--danger); }

.endpoint-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.endpoint-card h3 {
    font-size: 0.95rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.endpoint-port {
    color: var(--accent-color);
    font-family: monospace;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.endpoint-card-body {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
}

.metric-chip {
    min-width: 0;
}

.metric-chip span {
    display: block;
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.2;
}

.metric-chip strong {
    display: block;
    font-size: 1rem;
    line-height: 1.3;
}

.endpoint-sparkline {
    height: 46px;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    margin-top: 1rem;
    padding-top: 0.4rem;
    border-top: 1px solid var(--glass-border);
}

.endpoint-sparkline span {
    flex: 1;
    min-width: 3px;
    max-width: 12px;
    border-radius: 2px 2px 0 0;
    background: var(--accent-color);
    opacity: 0.85;
}

.endpoint-sparkline-empty {
    background: repeating-linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.04),
        rgba(255, 255, 255, 0.04) 6px,
        transparent 6px,
        transparent 12px
    );
    border-radius: 6px;
}

.endpoint-footnote {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 0.75rem;
}

.empty-state {
    color: var(--text-muted);
    border: 1px dashed var(--glass-border);
    border-radius: 8px;
    padding: 1rem;
}

.system-history {
    margin-top: 1rem;
}

.system-history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
}

.system-history-block {
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    background: rgba(22, 27, 34, 0.72);
    padding: 1rem;
}

.system-history-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.system-history-bars {
    height: 54px;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    margin-top: 0.85rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--glass-border);
}

.system-history-bar {
    flex: 1;
    min-width: 3px;
    max-width: 12px;
    border-radius: 2px 2px 0 0;
    background: var(--accent-color);
    opacity: 0.85;
}

.system-history-block:nth-child(2) .system-history-bar {
    background: var(--success);
}

.system-history-empty {
    background: repeating-linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.04),
        rgba(255, 255, 255, 0.04) 6px,
        transparent 6px,
        transparent 12px
    );
    border-radius: 6px;
}

.alert-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.alert-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border: 1px solid var(--glass-border);
    border-left: 4px solid var(--warning);
    border-radius: 8px;
    padding: 0.85rem 1rem;
    background: rgba(22, 27, 34, 0.72);
}

.alert-red {
    border-left-color: var(--danger);
}

.alert-yellow {
    border-left-color: var(--warning);
}

.alert-main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.alert-main strong,
.alert-main span {
    overflow-wrap: anywhere;
}

.alert-main > span:last-child {
    color: var(--text-muted);
}

.alert-port {
    color: var(--accent-color);
    font-family: monospace;
    font-weight: 700;
    white-space: nowrap;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
    border-color: var(--accent-color);
}

.stat-card .large-val {
    font-size: 2rem;
    font-weight: 700;
    margin: 0.5rem 0;
    color: var(--accent-color);
}

.stat-card .small-val {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.progress-container {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 1rem;
}

.progress-bar {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 1s ease-in-out;
}

/* GPU Cards */
.gpu-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.gpu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gpu-index {
    background: rgba(255, 255, 255, 0.1);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: bold;
}

.gpu-stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.val {
    font-weight: 600;
}

.chart-container {
    position: relative;
    height: 120px;
    width: 100%;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

/* Table */
.table-card {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

.port-link {
    color: var(--accent-color);
    font-weight: 800;
    text-decoration: none;
}

.port-link:visited {
    color: var(--accent-color);
}

.port-link:hover,
.port-link:focus {
    color: #9ed0ff;
    text-decoration: underline;
}

th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.85rem;
}

td {
    font-size: 0.9rem;
}

.slo {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 600;
}

.slo-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
}

.slo-green { background: var(--success); }
.slo-yellow { background: var(--warning); }
.slo-red { background: var(--danger); }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 1px solid var(--glass-border);
    border-radius: 999px;
    padding: 0.18rem 0.55rem;
    white-space: nowrap;
    font-size: 0.78rem;
    font-weight: 700;
}

.status-green {
    color: var(--success);
    background: rgba(63, 185, 80, 0.08);
}

.status-yellow {
    color: var(--warning);
    background: rgba(210, 153, 34, 0.08);
}

.status-red {
    color: var(--danger);
    background: rgba(248, 81, 73, 0.08);
}

.mono {
    font-family: monospace;
}

.accent {
    color: var(--accent-color);
}

.strong {
    font-weight: 700;
}

.muted {
    color: var(--text-muted);
}

.yes {
    color: var(--success);
    font-weight: 700;
}

.danger {
    color: var(--danger);
    font-weight: 700;
}

.recent-errors {
    max-width: 520px;
    white-space: normal;
    overflow-wrap: anywhere;
}

.error-line {
    margin-bottom: 4px;
}

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