:root {
    --ink: #14201b;
    --ink-soft: #3f4d46;
    --muted: #7a8a82;
    --line: #e4eae6;
    --bg: #f4f7f5;
    --card: #ffffff;
    --green: #1f9d63;
    --green-soft: #e5f5ec;
    --orange: #f28c28;
    --orange-soft: #fdf0e2;
    --blue: #3b82f6;
    --blue-soft: #e8f0fe;
    --red: #e5484d;
    --red-soft: #fdeaea;
    --radius: 14px;
    --shadow: 0 8px 24px rgba(20, 32, 27, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.shell { display: flex; min-height: 100vh; }

/* 侧栏 */
.sidebar {
    width: 216px;
    flex: 0 0 216px;
    background: #10201a;
    color: #d9e6df;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 26px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand-mark {
    width: 38px; height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--green), #4fce93);
    color: #fff;
    font-weight: 700;
    font-size: 20px;
    display: grid;
    place-items: center;
}
.brand-name { font-size: 16px; font-weight: 700; color: #fff; letter-spacing: 0.4px; }
.brand-sub { font-size: 11px; color: #8fa79b; }

.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #b9cdc3;
    font-size: 14px;
    transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-item.is-active { background: rgba(31, 157, 99, 0.22); color: #fff; font-weight: 600; }
.nav-icon { width: 18px; text-align: center; opacity: 0.85; }

.sidebar-foot {
    margin-top: auto;
    display: flex; align-items: center; gap: 8px;
    font-size: 12px; color: #789186;
    padding: 0 6px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(31, 157, 99, 0.2); }

/* 主区域 */
.main { flex: 1; padding: 26px 30px 48px; min-width: 0; }
.topbar {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; margin-bottom: 18px;
}
.page-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: 0.2px; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* 卡片 */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 700; }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat { margin: 0; position: relative; overflow: hidden; }
.stat::after {
    content: ""; position: absolute; right: -30px; top: -30px;
    width: 96px; height: 96px; border-radius: 50%; background: var(--green-soft);
}
.stat-orange::after { background: var(--orange-soft); }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 28px; font-weight: 700; margin: 4px 0 2px; letter-spacing: 0.4px; }
.stat-value .unit { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 5px; }
.stat-foot { font-size: 12px; color: var(--muted); position: relative; z-index: 1; }
.stat-green .stat-value { color: var(--green); }
.stat-orange .stat-value { color: var(--orange); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-2 > .card { margin-bottom: 18px; }

/* 图表 */
.chart {
    display: flex; align-items: flex-end; gap: 10px;
    height: 150px; padding: 6px 4px 0;
    border-bottom: 1px solid var(--line);
}
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.chart-bar { width: 100%; max-width: 34px; border-radius: 7px 7px 3px 3px; transition: opacity 0.15s ease; }
.chart-bar:hover { opacity: 0.8; }
.bar-green { background: linear-gradient(180deg, #4fce93, var(--green)); }
.bar-blue { background: linear-gradient(180deg, #79b0ff, var(--blue)); }
.chart-label { font-size: 11px; color: var(--muted); margin-top: 8px; }

/* 睡眠分期 */
.stage-list { display: flex; flex-direction: column; gap: 12px; }
.stage-row { display: grid; grid-template-columns: 44px 1fr 92px; align-items: center; gap: 10px; }
.stage-name { font-size: 13px; color: var(--ink-soft); }
.stage-track { height: 10px; border-radius: 999px; background: #eef2ef; overflow: hidden; }
.stage-fill { height: 100%; border-radius: 999px; }
.stage-deep { background: #2f6fd0; }
.stage-light { background: #6fa8f5; }
.stage-rem { background: #9bc6ff; }
.stage-awake { background: var(--orange); }
.stage-value { font-size: 12px; color: var(--muted); text-align: right; }

/* 表格 */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
    text-align: left; font-weight: 600; color: var(--muted);
    font-size: 12px; padding: 9px 10px; border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid #f0f4f1; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafcfa; }
.mono { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 12px; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }

/* 徽标 */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 11px; font-weight: 600; letter-spacing: 0.2px;
}
.badge-green { background: var(--green-soft); color: #157a4c; }
.badge-orange { background: var(--orange-soft); color: #b5650f; }
.badge-blue { background: var(--blue-soft); color: #245bb5; }
.badge-ink { background: #eef2ef; color: var(--ink-soft); }
.badge-red { background: var(--red-soft); color: #b3282c; }

/* 表单 */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.field-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field > span { font-weight: 600; }
.input {
    height: 36px; padding: 0 10px;
    border: 1px solid var(--line); border-radius: 9px;
    background: #fff; color: var(--ink); font-size: 13px;
    font-family: inherit;
}
.input:focus, .textarea:focus { outline: 2px solid rgba(31, 157, 99, 0.25); border-color: var(--green); }
.input-sm { height: 30px; font-size: 12px; padding: 0 8px; }
.input-num { width: 76px; }
.textarea {
    width: 100%; min-height: 360px; padding: 12px 14px;
    border: 1px solid var(--line); border-radius: 10px;
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
    font-size: 12px; line-height: 1.6; resize: vertical;
    background: #fbfdfb;
}

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    height: 36px; padding: 0 16px; border-radius: 9px;
    border: 1px solid transparent; font-size: 13px; font-weight: 600;
    cursor: pointer; font-family: inherit; transition: transform 0.1s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: #188554; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { border-color: #cfdad3; }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12px; }

.link { color: var(--green); font-size: 12px; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* 分页 / 空态 */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding-top: 16px; }
.pager-info { font-size: 12px; color: var(--muted); }
.empty { padding: 34px 0; text-align: center; color: var(--muted); font-size: 13px; }

.flash {
    background: var(--green-soft); color: #157a4c;
    border: 1px solid #bfe6d2; border-radius: 10px;
    padding: 10px 14px; margin-bottom: 16px; font-size: 13px; font-weight: 600;
}

/* 调试 */
.debug-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; }
.debug-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.debug-actions code { background: #eef2ef; padding: 2px 6px; border-radius: 6px; font-size: 12px; }
.code-block {
    margin: 0; background: #0f1c16; color: #cfe7db;
    border-radius: 10px; padding: 14px; min-height: 220px;
    font-family: "SF Mono", ui-monospace, Menlo, monospace;
    font-size: 12px; line-height: 1.55; overflow: auto;
    white-space: pre-wrap; word-break: break-all;
}
.code-sm { min-height: 0; margin-top: 8px; max-height: 240px; }
details summary { cursor: pointer; }

@media (max-width: 1080px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2, .debug-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .sidebar { display: none; }
    .main { padding: 20px 16px 40px; }
    .stat-grid { grid-template-columns: 1fr; }
    .table { display: block; overflow-x: auto; }
}
