:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #101828;
  --ink-2: #475467;
  --ink-3: #98a2b3;
  --line: #e4e7ec;
  --line-2: #eef1f6;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eef4ff;
  --green: #12b76a;
  --green-soft: #e8f8f0;
  --red: #f04438;
  --red-soft: #fef0ef;
  --amber: #dc6803;
  --amber-soft: #fff6e8;
  --navy: #0e1729;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px -12px rgba(16, 24, 40, .18);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--ink-3); font-size: 12.5px; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--navy);
  color: #cbd5e1;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px;
  box-shadow: 0 6px 16px -6px rgba(37, 99, 235, .8);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.35; }
.brand-text strong { color: #fff; font-size: 15px; letter-spacing: .02em; }
.brand-text span { color: #64748b; font-size: 10px; letter-spacing: .06em; white-space: nowrap; }
.btn.fit { align-self: flex-start; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: #cbd5e1; font-size: 13.5px; transition: background .16s, color .16s;
}
.nav a .ico {
  width: 20px; height: 20px; display: grid; place-items: center;
  border-radius: 6px; background: rgba(148, 163, 184, .14); font-size: 12px;
}
.nav a:hover { background: rgba(148, 163, 184, .12); color: #fff; }
.nav a.active { background: #1d2939; color: #fff; box-shadow: inset 0 0 0 1px rgba(148,163,184,.18); }
.nav a.active .ico { background: var(--primary); color: #fff; }
.nav-badge {
  margin-left: auto; background: var(--red); color: #fff;
  font-size: 11px; padding: 1px 7px; border-radius: 99px; font-weight: 600;
}

.sidebar-foot { margin-top: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-mini {
  background: rgba(148, 163, 184, .1); border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-mini span { color: #fff; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-mini em { color: #94a3b8; font-style: normal; font-size: 11px; }
.stat-mini.danger span { color: #fca5a5; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 22px 30px 16px; background: var(--bg);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(6px);
}
.topbar h2 { font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.sync-note { color: var(--ink-3); font-size: 12px; }

.view { padding: 4px 30px 40px; }

/* ---------- primitives ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line-2);
}
.card-head h3 { font-size: 14.5px; }
.card-head .muted { margin-top: 2px; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 9px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: .15s;
  font-family: inherit; white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #f9fafb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 6px 14px -8px rgba(37,99,235,.9); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #fecdca; background: var(--red-soft); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.icon-btn {
  border: none; background: transparent; color: var(--ink-3); cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px; font-size: 14px;
}
.icon-btn:hover { background: var(--line-2); color: var(--ink); }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-family: inherit; font-size: 13.5px; color: var(--ink); background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
label.field { display: flex; flex-direction: column; gap: 6px; }
label.field > span { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 500;
  background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.badge.ok { background: var(--green-soft); color: #027a48; }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.danger { background: var(--red-soft); color: var(--red); }
.badge.info { background: var(--primary-soft); color: var(--primary-dark); }
.badge.muted { background: #f2f4f7; color: #667085; }
.dot { width: 6px; height: 6px; border-radius: 99px; background: currentColor; }

/* ---------- query view ---------- */
.query-grid { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }
.query-form { display: flex; flex-direction: column; gap: 14px; }
.agent-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.agent-chip {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
  transition: .15s; text-align: left; font-family: inherit;
}
.agent-chip:hover { border-color: #c7d7fe; background: #fbfcff; }
.agent-chip.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.agent-chip strong { font-size: 13.5px; }
.agent-chip em { font-style: normal; font-size: 11px; color: var(--ink-3); }

.result-empty {
  display: grid; place-items: center; min-height: 420px; text-align: center;
  color: var(--ink-3); gap: 8px;
}
.result-empty .big { font-size: 40px; opacity: .35; }

.result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.result-head .no { font-size: 18px; font-weight: 600; letter-spacing: .01em; }
.result-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 8px; color: var(--ink-2); font-size: 12.5px; }
.result-meta b { font-weight: 500; color: var(--ink); }

.timeline { position: relative; margin: 18px 0 4px; padding-left: 22px; }
.timeline::before {
  content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px;
  width: 2px; background: linear-gradient(var(--line), var(--line-2)); border-radius: 2px;
}
.tl-item { position: relative; padding: 0 0 16px 4px; }
.tl-item::before {
  content: ""; position: absolute; left: -21px; top: 5px;
  width: 10px; height: 10px; border-radius: 99px; background: #fff;
  border: 2px solid #cdd5df;
}
.tl-item:first-child::before { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
.tl-item .t { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tl-item .d { margin-top: 3px; font-size: 13.5px; line-height: 1.55; color: var(--ink); }
.tl-item .loc { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }

/* ---------- table ---------- */
.table-wrap { overflow: auto; border-radius: 0 0 var(--radius) var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl-fixed { table-layout: fixed; }
table.tbl-fixed td { overflow: hidden; }
table.tbl th {
  text-align: left; font-weight: 500; color: var(--ink-3); font-size: 12px;
  padding: 10px 16px; background: #fbfcfe; border-bottom: 1px solid var(--line-2);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
table.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.tbl tbody tr:hover { background: #fafbff; }
table.tbl tbody tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.ellipsis { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.tbl-fixed .ellipsis { max-width: 100%; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar select { width: auto; min-width: 130px; }

.empty {
  padding: 46px 20px; text-align: center; color: var(--ink-3);
}

/* ---------- stats ---------- */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-card { padding: 15px 16px; display: flex; flex-direction: column; gap: 6px; }
.stat-card .k { color: var(--ink-3); font-size: 12px; }
.stat-card .v { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-card.accent .v { color: var(--primary); }
.stat-card.warn .v { color: var(--amber); }
.stat-card.danger .v { color: var(--red); }
.stat-card .sub { font-size: 11.5px; color: var(--ink-3); }

/* ---------- alerts ---------- */
.alert-list { display: flex; flex-direction: column; gap: 10px; }
.alert-item {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 14px 18px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
  border-left: 4px solid var(--red);
}
.alert-item.soft { border-left-color: var(--amber); }
.alert-item h4 { font-size: 14px; display: flex; align-items: center; gap: 8px; }
.alert-item .desc { margin-top: 5px; font-size: 12.5px; color: var(--ink-2); }
.alert-days { font-size: 22px; font-weight: 600; color: var(--red); font-variant-numeric: tabular-nums; text-align: right; }
.alert-days small { display: block; font-size: 11px; color: var(--ink-3); font-weight: 400; }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 10px 14px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.hint { background: #f8fafc; border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px; font-size: 12.5px; color: var(--ink-2); line-height: 1.65; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16, 24, 40, .45); backdrop-filter: blur(2px); }
.modal-panel {
  position: relative; width: min(760px, calc(100vw - 32px)); max-height: 86vh;
  background: #fff; border-radius: 16px; box-shadow: 0 24px 60px -12px rgba(16,24,40,.35);
  display: flex; flex-direction: column; overflow: hidden;
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: .6; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line-2);
}
.modal-body { padding: 18px 20px 22px; overflow: auto; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 12px);
  background: #101828; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 90;
  box-shadow: 0 12px 30px -10px rgba(16,24,40,.5); max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b42318; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--navy); z-index: 100; }
.login-card {
  width: min(360px, calc(100vw - 32px)); background: #fff; border-radius: 16px;
  padding: 28px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 30px 70px -20px rgba(0,0,0,.6);
}
.login-brand { display: flex; align-items: center; gap: 10px; }
.brand-dot { width: 10px; height: 10px; border-radius: 99px; background: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.login-brand h1 { font-size: 18px; }
.login-err { color: var(--red); font-size: 12.5px; min-height: 16px; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .query-grid, .settings-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center;
    padding: 12px 14px; gap: 12px; overflow-x: auto;
  }
  .brand-text, .sidebar-foot { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav a { padding: 8px 10px; white-space: nowrap; }
  .nav a .ico { display: none; }
  .topbar { padding: 16px 16px 10px; }
  .topbar h2 { font-size: 17px; }
  .view { padding: 0 16px 32px; }
  .sync-note { display: none; }
  .ellipsis { max-width: 160px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  table.tbl th, table.tbl td { padding: 10px 12px; }
}

