:root {
  --bg: #07111f;
  --bg-soft: #0b1728;
  --panel: rgba(14, 26, 46, .92);
  --panel-strong: #101f35;
  --card: rgba(18, 34, 58, .88);
  --line: rgba(142, 173, 213, .18);
  --text: #e7f0ff;
  --muted: #8aa0bd;
  --faint: #61718b;
  --primary: #42d3ff;
  --primary-2: #7c5cff;
  --success: #48e4a7;
  --warning: #ffc857;
  --danger: #ff5d7a;
  --shadow: 0 24px 80px rgba(0,0,0,.38);
  --radius: 18px;
  --sidebar: 282px;
  font-family: "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body.light {
  --bg: #edf4ff;
  --bg-soft: #f8fbff;
  --panel: rgba(255,255,255,.94);
  --panel-strong: #ffffff;
  --card: rgba(255,255,255,.9);
  --line: rgba(53, 84, 124, .18);
  --text: #132238;
  --muted: #53657c;
  --faint: #748296;
  --shadow: 0 24px 70px rgba(36, 72, 120, .16);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  background:
    radial-gradient(circle at 10% 0%, rgba(66, 211, 255, .16), transparent 28%),
    radial-gradient(circle at 80% 10%, rgba(124, 92, 255, .18), transparent 28%),
    linear-gradient(135deg, var(--bg), var(--bg-soft));
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: 22px 16px; border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(9, 18, 33, .98), rgba(9, 18, 33, .86));
  backdrop-filter: blur(16px);
}
body.light .sidebar { background: rgba(255,255,255,.82); }
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 22px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 16px; display: grid; place-items: center;
  font-weight: 900; color: #001625; background: linear-gradient(135deg, var(--primary), var(--success));
  box-shadow: 0 0 32px rgba(66, 211, 255, .42);
}
.brand strong { display: block; letter-spacing: .4px; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.side-section { color: var(--faint); font-size: 12px; margin: 18px 10px 8px; letter-spacing: 1.8px; }
.nav-item {
  width: 100%; border: 0; color: var(--muted); background: transparent; display: flex; align-items: center;
  justify-content: space-between; padding: 11px 12px; margin: 3px 0; border-radius: 14px; text-align: left;
}
.nav-item span { font-size: 14px; }
.nav-item em { font-style: normal; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: rgba(255,255,255,.06); color: var(--faint); }
.nav-item:hover { background: rgba(66, 211, 255, .08); color: var(--text); }
.nav-item.active { background: linear-gradient(135deg, rgba(66,211,255,.22), rgba(124,92,255,.18)); color: var(--text); border: 1px solid rgba(66,211,255,.25); }
.nav-item.active em { background: rgba(66,211,255,.18); color: var(--primary); }
.advanced-nav { margin-top: 16px; border: 1px dashed var(--line); border-radius: 16px; padding: 8px; background: rgba(255,255,255,.025); }
.advanced-nav summary {
  list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 12px; color: var(--text); cursor: pointer; user-select: none;
}
.advanced-nav summary::-webkit-details-marker { display: none; }
.advanced-nav summary:before { content: "›"; color: var(--primary); font-size: 18px; transition: transform .16s ease; }
.advanced-nav[open] summary:before { transform: rotate(90deg); }
.advanced-nav summary em { font-style: normal; color: var(--faint); font-size: 11px; padding: 2px 7px; border-radius: 999px; background: rgba(255,255,255,.06); }
.advanced-nav .side-section { margin-top: 12px; }

.main { min-width: 0; padding: 24px clamp(18px, 3vw, 34px) 42px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 16px; }
.eyebrow { margin: 0 0 6px; color: var(--primary); font-size: 12px; letter-spacing: 1.8px; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(26px, 3vw, 38px); }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.secure-pill {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); background: var(--panel); font-size: 13px;
}
.pulse { width: 9px; height: 9px; border-radius: 999px; background: var(--success); box-shadow: 0 0 0 6px rgba(72,228,167,.12); }
.notice { border: 1px solid rgba(66,211,255,.18); background: linear-gradient(135deg, rgba(66,211,255,.09), rgba(124,92,255,.08)); border-radius: var(--radius); padding: 14px 16px; color: var(--muted); margin-bottom: 18px; }
.notice strong { color: var(--text); }
.content { display: grid; gap: 18px; }

.btn, .chip, .icon-btn {
  border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--card); padding: 10px 14px;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.btn:hover, .chip:hover, .icon-btn:hover { transform: translateY(-1px); border-color: rgba(66,211,255,.42); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #02101f; border: 0; font-weight: 800; }
.btn.danger { background: rgba(255, 93, 122, .14); border-color: rgba(255,93,122,.35); color: #ffd3dc; }
.btn.success { background: rgba(72, 228, 167, .14); border-color: rgba(72,228,167,.35); color: #c9ffe8; }
body.light .btn.danger { color: #ab1730; }
body.light .btn.success { color: #087b51; }
.btn.ghost { color: var(--muted); }
.btn.small { padding: 7px 10px; font-size: 12px; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.accent-card { border-color: rgba(66,211,255,.35); background: linear-gradient(160deg, rgba(66,211,255,.12), rgba(124,92,255,.08), var(--panel)); }
.card.tight { padding: 14px; }
.card h2, .card h3 { margin: 0 0 12px; }
.card h3 { font-size: 17px; }
.metric { position: relative; overflow: hidden; min-height: 122px; }
.metric:after { content: ""; position: absolute; right: -28px; top: -28px; width: 92px; height: 92px; border-radius: 999px; background: rgba(66,211,255,.1); }
.metric .label { color: var(--muted); font-size: 13px; }
.metric .value { font-size: 34px; font-weight: 900; margin: 10px 0 6px; }
.metric .delta { font-size: 12px; color: var(--success); }
.metric.warn .delta { color: var(--warning); }
.metric.danger .delta { color: var(--danger); }
.card > .metric { min-height: auto; font-size: 30px; font-weight: 900; color: var(--primary); margin: 4px 0 10px; }
.danger-text { color: var(--danger) !important; }

.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .left, .toolbar .right { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search, .field, select, textarea, input {
  background: rgba(2, 9, 18, .34); border: 1px solid var(--line); border-radius: 12px; color: var(--text); padding: 10px 12px; outline: none;
}
body.light .search, body.light .field, body.light select, body.light textarea, body.light input { background: #f6f9ff; }
.search { width: min(320px, 100%); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; min-width: 840px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; font-weight: 700; background: rgba(255,255,255,.025); }
td { color: var(--text); font-size: 13px; }
tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.status:before { content: ""; width: 7px; height: 7px; border-radius: 999px; background: var(--muted); }
.status.ok { color: var(--success); background: rgba(72,228,167,.08); }
.status.ok:before { background: var(--success); }
.status.warn { color: var(--warning); background: rgba(255,200,87,.08); }
.status.warn:before { background: var(--warning); }
.status.bad { color: var(--danger); background: rgba(255,93,122,.08); }
.status.bad:before { background: var(--danger); }
.status.info { color: var(--primary); background: rgba(66,211,255,.08); }
.status.info:before { background: var(--primary); }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px; margin: 9px 0; color: var(--muted); }
.kv strong { color: var(--text); }
.list { display: grid; gap: 10px; }
.list-item { display: flex; justify-content: space-between; gap: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.03); }
.list-item p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.progress { height: 8px; border-radius: 999px; background: rgba(255,255,255,.08); overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--success)); border-radius: inherit; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row { display: grid; gap: 6px; }
.form-row.full { grid-column: 1 / -1; }
.form-row label { color: var(--muted); font-size: 12px; }
.check-row { display: flex; align-items: center; gap: 9px; color: var(--muted); }
.check-row input { width: auto; }
.codebox { border: 1px solid var(--line); background: rgba(0,0,0,.28); border-radius: 14px; padding: 12px; color: #b8f7ff; font-family: Consolas, monospace; font-size: 12px; overflow-x: auto; }
body.light .codebox { background: #eef5ff; color: #145166; }

.modal-backdrop {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 20px; z-index: 40;
  background: rgba(0,0,0,.58); backdrop-filter: blur(12px);
}
.modal-backdrop.open { display: flex; }
.modal { width: min(720px, 96vw); max-height: 88vh; overflow-y: auto; position: relative; background: var(--panel-strong); border: 1px solid var(--line); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); }
.close { position: absolute; top: 14px; right: 14px; }
.modal h2 { margin: 0 44px 16px 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.drawer {
  position: fixed; top: 0; right: 0; width: min(520px, 94vw); height: 100vh; z-index: 35; transform: translateX(105%);
  transition: transform .22s ease; background: var(--panel-strong); border-left: 1px solid var(--line); box-shadow: var(--shadow); padding: 24px; overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer .close { top: 16px; right: 16px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 60; opacity: 0; transform: translateY(12px); transition: .18s; background: #101f35; border: 1px solid rgba(66,211,255,.28); color: var(--text); padding: 12px 14px; border-radius: 14px; box-shadow: var(--shadow); }
.toast.open { opacity: 1; transform: translateY(0); }

.badge-row { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; color: var(--muted); background: rgba(255,255,255,.05); border: 1px solid var(--line); font-size: 12px; }
.timeline { border-left: 1px solid var(--line); padding-left: 16px; display: grid; gap: 14px; }
.timeline .event { position: relative; }
.timeline .event:before { content: ""; position: absolute; left: -22px; top: 5px; width: 10px; height: 10px; border-radius: 999px; background: var(--primary); box-shadow: 0 0 0 5px rgba(66,211,255,.12); }
.timeline p { margin: 4px 0 0; color: var(--muted); }
.empty-note { color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; padding: 16px; background: rgba(255,255,255,.025); }

@media (max-width: 1180px) {
  :root { --sidebar: 246px; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; width: 100%; height: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
  .brand, .side-section { grid-column: 1 / -1; }
  .topbar { flex-direction: column; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
