:root {
    --bg-color: #0d1117;
    --card-bg: rgba(22, 27, 34, 0.9);
    --accent-primary: #58a6ff;
    --accent-secondary: #bc8cff;
    --accent-success: #3fb950;
    --accent-warning: #d29922;
    --text-main: #c9d1d9;
    --text-muted: #8b949e;
    --border-color: rgba(48, 54, 61, 0.8);
    --sidebar-width: 290px;
    --header-h: 52px;    /* header 实际高度 */
    --metrics-h: 46px;   /* metrics-strip 实际高度 */
    --top-total: 98px;   /* header + metrics 计 */
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', system-ui, sans-serif; }

body {
    background: var(--bg-color);
    background-image: radial-gradient(at 0% 0%, rgba(88, 166, 255, 0.06) 0px, transparent 50%),
                      radial-gradient(at 100% 100%, rgba(188, 140, 255, 0.06) 0px, transparent 50%);
    color: var(--text-main);
    min-height: 100vh;
}

/* ============ HEADER ============ */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(13, 17, 23, 0.95);
    position: sticky;
    top: 0;
    z-index: 200;
    gap: 0.5rem;
    white-space: nowrap;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 0.8rem;
    flex-wrap: nowrap;
    overflow: hidden;
}

.header-title h1 {
    font-size: 2.1rem;
    font-weight: 700;
    flex-shrink: 0;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

.header-title p {
    color: var(--text-muted);
    font-size: 0.72rem;
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-reset {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.7rem;
    padding: 0.15rem 0.45rem;
    white-space: nowrap;
    transition: border-color 0.15s;
}
.header-reset:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

/* ============ METRICS STRIP — 页面级 sticky，紧跟 header ============ */
.metrics-strip {
    position: sticky;
    top: var(--header-h);
    z-index: 130;
    background: rgba(13, 17, 23, 0.97);
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    backdrop-filter: blur(16px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.metric-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.7rem;
    border-right: 1px solid var(--border-color);
    gap: 0.4rem;
    transition: background 0.15s;
}
.metric-item:last-child { border-right: none; }
.metric-item:hover { background: rgba(88, 166, 255, 0.05); }

.metric-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent-primary);
    line-height: 1.2;
    white-space: nowrap;
}

.metric-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ============ 黑客帝国计算特效 ============ */
.metrics-strip.computing .metric-value {
    color: #3fb950 !important;
    font-size: 2.1rem;
    text-shadow: 0 0 12px rgba(63, 185, 80, 0.6);
    transition: all 0.3s ease;
}
.metrics-strip.computing .metric-label {
    color: #3fb950 !important;
    font-size: 0.9rem;
    text-shadow: 0 0 6px rgba(63, 185, 80, 0.4);
    transition: all 0.3s ease;
}

/* ============ MAIN LAYOUT ============ */
/* 页面正常滚动；sidebar 固高独立滚动；main-content 自然伸展 */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    align-items: start;
    min-height: calc(100vh - 52px);
}

/* ============ SIDEBAR ============ */
.sidebar {
    position: sticky;
    top: var(--top-total);
    align-self: start;
    height: calc(100vh - var(--top-total));
    overflow-y: auto;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    border-right: 1px solid var(--border-color);
    scrollbar-width: thin;
    scrollbar-color: rgba(48,54,61,0.5) transparent;
}

/* ============ MAIN CONTENT ============ */
/* 不限高度，页面整体滚动 */
.main-content {
    padding: 0.6rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-width: 0;
    overflow: visible;
}

/* ============ CARD ============ */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.8rem;
}

.card-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 0.6rem;
    display: flex; align-items: center; gap: 0.4rem;
}
.card-title::before {
    content: ''; width: 3px; height: 12px;
    background: var(--accent-secondary); border-radius: 1px; flex-shrink: 0;
}

/* ============ BUTTON CARD (Sticky in sidebar) ============ */
.action-card {
    border: 1px solid rgba(88, 166, 255, 0.4);
    background: rgba(22, 27, 34, 0.98);
    position: sticky;
    top: 0;
    z-index: 10;
}

.btn-group-vertical { display: flex; flex-direction: column; gap: 0.5rem; }

.btn {
    cursor: pointer; border: none; border-radius: 6px;
    padding: 0.55rem 0.8rem;
    font-size: 0.88rem; font-weight: 600; width: 100%;
    display: flex; align-items: center; justify-content: center; gap: 0.4rem;
    transition: opacity 0.15s, transform 0.1s;
}
.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: #238636; color: #fff; box-shadow: 0 0 12px rgba(35,134,54,0.3); }
.btn-secondary { background: #8957e5; color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-muted); font-size: 0.7rem; padding: 0.2rem 0.5rem; }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }

/* ============ FORM GRID ============ */
.input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.form-group { display: flex; flex-direction: column; gap: 0.15rem; }
.form-group.full-width { grid-column: 1 / -1; }

label { font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

input[type=number] {
    background: rgba(13,17,23,0.8); border: 1px solid var(--border-color);
    border-radius: 4px; color: var(--text-main);
    padding: 0.25rem 0.4rem; font-size: 0.78rem; width: 100%; outline: none;
    appearance: textfield;
    -moz-appearance: textfield;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; appearance: none; }
input[type=number]:focus { border-color: var(--accent-primary); }

/* ============ MAIN CONTENT ============ */
.main-content {
    padding: 0.6rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-width: 0;
    overflow: hidden;
}

/* ============ CHART CARDS ============ */
.chart-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.8rem;
    width: 100%;
    min-width: 300px; /* 最小宽度保护 */
}

.chart-card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.5rem;
}

.chart-wrap-short { position: relative; height: 160px; width: 100%; }
.chart-wrap-tall  { position: relative; height: 300px; width: 100%; }

canvas { display: block; }

/* ============ REPORT BOX ============ */
.report-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--accent-success);
    border-radius: 8px;
    padding: 0.8rem;
}
.report-container {
    background: #0a0d12; border: 1px solid #1e2430; border-radius: 6px;
    padding: 0.8rem; min-height: 120px; max-height: 260px;
    overflow-y: auto; font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem; color: #3fb950; line-height: 1.6;
}
.report-container .err { color: #f85149; }

/* ============ MODAL ============ */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.7); z-index: 500;
    align-items: center; justify-content: center;
}
.modal {
    background: #161b22; border: 1px solid #30363d;
    border-radius: 10px; padding: 1.2rem;
    width: 520px; max-width: 95vw;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8rem; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.4rem; cursor: pointer; }
#modal-textarea { width: 100%; height: 220px; background: #0d1117; border: 1px solid #30363d; border-radius: 6px; color: var(--text-main); padding: 0.6rem; font-size: 0.8rem; resize: vertical; }

/* ============ FOOTER ============ */
footer {
    text-align: center; padding: 0.8rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted); font-size: 0.72rem;
}
