/* ============================================================================
 * Project Aether-Archive —— 控制台样式（手写 CSS，无外部 CDN 依赖）
 * 设计：深色「档案室」主题 + 亮色可切换；毛玻璃卡片 + 细描边 + 高对比文本。
 * 结构：变量 → 基础 → 布局 → 组件（按钮/卡片/表格/表单） → 四大板块 → 模态框 → 响应式
 * ========================================================================== */

:root {
  --bg: #070b14;
  --bg-soft: #0c1220;
  --panel: rgba(17, 24, 39, 0.72);
  --panel-solid: #111827;
  --panel-2: rgba(24, 33, 52, 0.86);
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.32);
  --text: #e6edf7;
  --text-dim: #94a3b8;
  --text-faint: #64748b;
  --accent: #38bdf8;
  --accent-2: #a78bfa;
  --accent-3: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px rgba(2, 6, 23, 0.55);
  --mono: "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: "Inter", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-soft: #e2e8f0;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --panel-2: rgba(241, 245, 249, 0.95);
  --border: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.22);
  --text: #0f172a;
  --text-dim: #475569;
  --text-faint: #64748b;
  --accent: #0284c7;
  --accent-2: #7c3aed;
  --accent-3: #059669;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1100px 620px at 8% -10%, rgba(56, 189, 248, 0.16), transparent 62%),
    radial-gradient(900px 520px at 92% 4%, rgba(167, 139, 250, 0.14), transparent 60%),
    radial-gradient(760px 520px at 50% 110%, rgba(52, 211, 153, 0.10), transparent 62%);
  pointer-events: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
::selection { background: rgba(56, 189, 248, 0.32); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.28); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.45); }

/* ---------------------------------------------------------------- 布局 */
.shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(12, 18, 32, 0.96), rgba(7, 11, 20, 0.92));
  backdrop-filter: blur(14px);
}

[data-theme="light"] .sidebar {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(241, 245, 249, 0.92));
}

.brand { display: flex; align-items: center; gap: 11px; padding: 4px 6px 2px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 12px; flex: 0 0 auto;
  background: conic-gradient(from 210deg, #38bdf8, #a78bfa, #34d399, #38bdf8);
  display: grid; place-items: center; color: #04121f; font-weight: 800; font-size: 16px;
  box-shadow: 0 8px 26px rgba(56, 189, 248, 0.35);
}
.brand-text strong { display: block; font-size: 15px; letter-spacing: .2px; }
.brand-text span { display: block; font-size: 11px; color: var(--text-faint); letter-spacing: .4px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 11px; cursor: pointer;
  color: var(--text-dim); border: 1px solid transparent; background: transparent;
  font-size: 13.5px; font-weight: 500; text-align: left; width: 100%;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease;
}
.nav-item:hover { background: rgba(56, 189, 248, 0.08); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.18), rgba(167, 139, 250, 0.10));
  color: var(--text); border-color: rgba(56, 189, 248, 0.34);
}
.nav-item .ico { font-size: 16px; width: 20px; text-align: center; }
.nav-item .badge {
  margin-left: auto; min-width: 20px; padding: 0 6px; height: 18px; border-radius: 9px;
  background: var(--danger); color: #1b0505; font-size: 11px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
}
.nav-item .badge.show { display: inline-flex; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.status-pill {
  display: flex; align-items: center; gap: 8px; padding: 9px 11px;
  border-radius: 11px; border: 1px solid var(--border); background: var(--panel);
  font-size: 12px; color: var(--text-dim);
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint); flex: 0 0 auto; }
.dot.on { background: var(--accent-3); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.16); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.16); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.16); }
.dot.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 20, 0.72); backdrop-filter: blur(16px);
}
[data-theme="light"] .topbar { background: rgba(248, 250, 252, 0.82); }
.topbar h1 { font-size: 16px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.topbar .sub { color: var(--text-faint); font-size: 12px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.content { padding: 20px 24px 46px; display: flex; flex-direction: column; gap: 16px; }

/* ---------------------------------------------------------------- 组件 */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(12px); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px; padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.card-head h3 { margin: 0; font-size: 13.5px; font-weight: 650; letter-spacing: .2px; }
.card-head .hint { font-size: 11.5px; color: var(--text-faint); }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 550;
  border: 1px solid var(--border-strong); background: rgba(148, 163, 184, 0.10); color: var(--text);
  transition: transform .12s ease, background .16s ease, border-color .16s ease, opacity .16s;
  user-select: none; white-space: nowrap;
}
.btn:hover { background: rgba(148, 163, 184, 0.18); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, #38bdf8, #6366f1); border-color: transparent; color: #04121f; font-weight: 700;
}
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(248, 113, 113, .45); color: var(--danger); background: rgba(248, 113, 113, .08); }
.btn.success { border-color: rgba(52, 211, 153, .45); color: var(--accent-3); background: rgba(52, 211, 153, .1); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }

.grid { display: grid; gap: 12px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

.metric { padding: 14px 16px; }
.metric .label { font-size: 11.5px; color: var(--text-faint); letter-spacing: .5px; text-transform: uppercase; }
.metric .value { font-size: 24px; font-weight: 750; margin-top: 4px; letter-spacing: .4px; }
.metric .value small { font-size: 12px; color: var(--text-dim); font-weight: 500; margin-left: 5px; }
.metric .delta { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; border: 1px solid var(--border-strong); color: var(--text-dim);
  background: rgba(148, 163, 184, 0.08); white-space: nowrap;
}
.tag.accent { color: var(--accent); border-color: rgba(56, 189, 248, .42); background: rgba(56, 189, 248, .10); }
.tag.green { color: var(--accent-3); border-color: rgba(52, 211, 153, .42); background: rgba(52, 211, 153, .10); }
.tag.warn { color: var(--warn); border-color: rgba(251, 191, 36, .42); background: rgba(251, 191, 36, .10); }
.tag.danger { color: var(--danger); border-color: rgba(248, 113, 113, .42); background: rgba(248, 113, 113, .10); }
.tag.violet { color: var(--accent-2); border-color: rgba(167, 139, 250, .42); background: rgba(167, 139, 250, .10); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-dim); font-weight: 560; }
.field .desc { font-size: 11px; color: var(--text-faint); }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px; font-size: 13px; font-family: inherit;
  background: rgba(2, 6, 23, 0.42); color: var(--text); border: 1px solid var(--border-strong);
  transition: border-color .16s ease, box-shadow .16s ease;
}
[data-theme="light"] input, [data-theme="light"] select, [data-theme="light"] textarea {
  background: rgba(255, 255, 255, 0.9);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: rgba(56, 189, 248, .68);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .14);
}
textarea { resize: vertical; min-height: 84px; font-family: var(--mono); font-size: 12.5px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }

table.data { width: 100%; border-collapse: collapse; font-size: 12.8px; }
table.data th {
  text-align: left; padding: 9px 12px; color: var(--text-faint); font-weight: 600; font-size: 11.5px;
  letter-spacing: .4px; text-transform: uppercase; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel-2); backdrop-filter: blur(8px); z-index: 1;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:hover td { background: rgba(56, 189, 248, 0.05); }
table.data td .mono { color: var(--text-dim); }
.table-wrap { max-height: 460px; overflow: auto; }

.empty { padding: 34px 16px; text-align: center; color: var(--text-faint); font-size: 13px; }
.empty .big { font-size: 28px; margin-bottom: 8px; opacity: .7; }

/* ---------------------------------------------------------------- 实时流 */
.live-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; align-items: start; }
.live-feed { max-height: calc(100vh - 250px); overflow: auto; padding: 4px 0; }
.msg {
  display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); animation: slideIn .28s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.msg:hover { background: rgba(56, 189, 248, 0.04); }
.msg .meta { font-size: 11px; color: var(--text-faint); }
.msg .meta strong { display: block; color: var(--text-dim); font-size: 12px; font-weight: 600; }
.msg .body { min-width: 0; }
.msg .body .text { word-break: break-word; white-space: pre-wrap; }
.msg .body .flags { margin-top: 5px; display: flex; gap: 6px; flex-wrap: wrap; }
.msg .anchor { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }

.stream-item { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.stream-item .t { color: var(--text-faint); font-family: var(--mono); font-size: 11px; }
.stream-item .type { color: var(--accent); font-family: var(--mono); font-size: 11.5px; }
.stream-item .payload { color: var(--text-dim); word-break: break-all; }

/* ---------------------------------------------------------------- 人机协同弹窗 */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200; display: none; place-items: center;
  background: rgba(2, 6, 23, 0.74); backdrop-filter: blur(6px); padding: 24px;
}
.modal-backdrop.show { display: grid; }
.modal {
  width: min(680px, 100%); max-height: 86vh; overflow: auto;
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.98), rgba(12, 18, 32, 0.98));
  border: 1px solid rgba(56, 189, 248, .38); border-radius: 18px;
  box-shadow: 0 30px 80px rgba(2, 6, 23, .75), 0 0 0 1px rgba(56, 189, 248, .12) inset;
  animation: modalIn .22s ease;
}
[data-theme="light"] .modal { background: #fff; }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; gap: 12px; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head .icon {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 18px;
  background: rgba(251, 191, 36, .14); border: 1px solid rgba(251, 191, 36, .4);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-head .sub { font-size: 12px; color: var(--text-faint); }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; gap: 10px; padding: 14px 20px 20px; flex-wrap: wrap; }
.option-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.option-btn {
  padding: 13px 14px; border-radius: 12px; text-align: left; cursor: pointer;
  border: 1px solid var(--border-strong); background: rgba(148, 163, 184, 0.08); color: var(--text);
  transition: all .15s ease; font-size: 13px;
}
.option-btn:hover { border-color: var(--accent); background: rgba(56, 189, 248, .12); transform: translateY(-1px); }
.option-btn .k { display: block; font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }

/* ---------------------------------------------------------------- 知识库 / 研报 */
.entity-card {
  padding: 15px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel);
  display: flex; flex-direction: column; gap: 9px; cursor: pointer; transition: all .16s ease;
}
.entity-card:hover { border-color: rgba(56, 189, 248, .5); transform: translateY(-2px); box-shadow: 0 16px 40px rgba(2, 6, 23, .45); }
.entity-card h4 { margin: 0; font-size: 14.5px; }
.entity-card .aliases { font-size: 11.5px; color: var(--text-faint); }
.entity-card .sum { font-size: 12.5px; color: var(--text-dim); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.conf-bar { height: 4px; border-radius: 4px; background: rgba(148, 163, 184, .18); overflow: hidden; }
.conf-bar > i { display: block; height: 100%; background: linear-gradient(90deg, #38bdf8, #34d399); }

.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: linear-gradient(180deg, rgba(56,189,248,.6), rgba(167,139,250,.25)); }
.timeline-item { position: relative; padding: 0 0 14px 8px; }
.timeline-item::before { content: ""; position: absolute; left: -16px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, .18); }
.timeline-item .date { font-family: var(--mono); font-size: 11.5px; color: var(--accent); }
.timeline-item .event { font-size: 13px; }
.timeline-item .ev { font-size: 11.5px; color: var(--text-faint); }

.markdown { font-size: 13.5px; line-height: 1.75; word-break: break-word; }
.markdown h1, .markdown h2, .markdown h3 { margin: 18px 0 8px; line-height: 1.35; }
.markdown h1 { font-size: 20px; }
.markdown h2 { font-size: 16px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown h3 { font-size: 14px; color: var(--accent); }
.markdown p { margin: 8px 0; }
.markdown ul, .markdown ol { padding-left: 22px; margin: 8px 0; }
.markdown blockquote { margin: 8px 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: rgba(56, 189, 248, .07); border-radius: 0 8px 8px 0; color: var(--text-dim); }
.markdown pre { background: rgba(2, 6, 23, .55); padding: 12px; border-radius: 10px; overflow: auto; border: 1px solid var(--border); }
.markdown code { background: rgba(148, 163, 184, .14); padding: 1px 5px; border-radius: 5px; }
.markdown pre code { background: none; padding: 0; }
.markdown table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.markdown th, .markdown td { border: 1px solid var(--border-strong); padding: 6px 10px; font-size: 12.5px; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.media-tile {
  border: 1px solid var(--border); border-radius: 11px; overflow: hidden; background: var(--panel-2);
  display: flex; flex-direction: column; transition: all .16s ease;
}
.media-tile:hover { border-color: rgba(56, 189, 248, .5); transform: translateY(-2px); }
.media-tile .thumb { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; background: rgba(148,163,184,.08); }
.media-tile .cap { padding: 7px 9px; font-size: 11.5px; color: var(--text-dim); }
.media-tile .cap .size { color: var(--text-faint); font-size: 10.5px; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 14px; align-items: start; }

/* ---------------------------------------------------------------- 供应商管理 */
.provider {
  border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--panel);
  display: flex; flex-direction: column; gap: 10px;
}
.provider.active { border-color: rgba(52, 211, 153, .55); box-shadow: 0 0 0 1px rgba(52, 211, 153, .2) inset; }
.provider-head { display: flex; align-items: center; gap: 8px; }
.provider-head .name { font-weight: 650; font-size: 13.5px; }
.provider .row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* ---------------------------------------------------------------- 提示 / Toast */
.toast-wrap { position: fixed; right: 18px; bottom: 18px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 220px; max-width: 380px; padding: 11px 14px; border-radius: 11px; font-size: 12.8px;
  background: var(--panel-solid); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  animation: toastIn .2s ease;
}
.toast.ok { border-color: rgba(52, 211, 153, .55); }
.toast.err { border-color: rgba(248, 113, 113, .6); }
.toast.info { border-color: rgba(56, 189, 248, .55); }
@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 14px; height: 14px; border-radius: 50%; display: inline-block;
  border: 2px solid rgba(148, 163, 184, .3); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }
.muted { color: var(--text-faint); }
.right { margin-left: auto; }
.flex { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }
.scroll-y { overflow-y: auto; }

/* ---------------------------------------------------------------- 响应式 */
@media (max-width: 1180px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-layout { grid-template-columns: minmax(0, 1fr); }
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 232px; z-index: 120;
    transform: translateX(-105%); transition: transform .22s ease;
  }
  .sidebar.open { transform: none; }
  .content { padding: 14px 14px 40px; }
  .topbar { padding: 12px 14px; }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
  .msg { grid-template-columns: 1fr; gap: 4px; }
  .mobile-toggle { display: inline-flex !important; }
}
.mobile-toggle { display: none; }
