/* ═══════════════════════════════════════════════════════════
   theme.css — Linear 风精制主题(在 style.css 之后加载)
   · 浅色为基调的令牌精调 + 新组件类
   · html[data-theme="dark"] 深色主题
   · 新组件:.kpi-card / .data-table / .chip / .icon-btn / .panel
   ═══════════════════════════════════════════════════════════ */

/* ── 浅色精制 ─────────────────────────────────────────────── */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-secondary: #6b7280;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #eef2ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --info: #2563eb;
  --info-soft: #eff6ff;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow: 0 4px 8px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, .1), 0 4px 6px -2px rgba(16, 24, 40, .04);
  --font-num: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;

  /* 映射旧变量,存量组件自动升级 */
  --primary: var(--accent);
  --primary-dark: var(--accent-strong);
  --primary-light: var(--accent-soft);
  --success: var(--ok);
  --success-bg: var(--ok-soft);
  --danger: var(--bad);
  --danger-bg: var(--bad-soft);
  --warning: var(--warn);
  --warning-bg: var(--warn-soft);
  --info-bg: var(--info-soft);
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 10px;
}

html { scroll-behavior: smooth; }
body {
  background: var(--bg) !important;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  transition: background-color .2s ease, color .2s ease;
}
.container { max-width: 1200px; }

/* 标题层级收紧 */
.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.page-header h1 .svg-icon { color: var(--accent); }
.page-header .subtitle { font-size: 13px; }

/* 卡片精制:更轻的阴影、更清晰的边框 */
.card {
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  border-radius: 12px;
}
.card:hover { box-shadow: var(--shadow-sm); }
.card h2 { letter-spacing: -0.01em; }

/* 数字等宽 */
.stat-num, .kpi-num, td.num, .mono { font-variant-numeric: tabular-nums; font-family: var(--font-num); }

/* 按钮 focus ring */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
::-webkit-scrollbar-track { background: transparent; }

/* SVG 图标基线对齐 */
.svg-icon { vertical-align: -3px; flex-shrink: 0; }
h1 .svg-icon, h2 .svg-icon { vertical-align: -4px; }
.btn .svg-icon { vertical-align: -3px; }

/* 标签内小图标对齐 */
.tag .svg-icon { vertical-align: -2px; }

/* 侧边栏 logo 图标与页面标题一致(品牌色) */
.sidebar-logo { display: inline-flex; align-items: center; gap: 7px; }
.sidebar-logo .svg-icon { color: var(--accent); }

/* ── 状态徽章:小圆点 + 文字(成功·绿 / 待确认·橙 / 失败·红) ── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 7px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  background: var(--gray-100); color: var(--text-secondary);
  border: 1px solid transparent;
}
.badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.badge.success { background: var(--ok-soft); color: var(--ok); }
.badge.fail { background: var(--bad-soft); color: var(--bad); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.inactive { background: var(--bad-soft); color: var(--bad); }

/* ── 按钮现代化(柔和边框风,替代旧实心按钮) ── */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: all .12s ease; box-shadow: none; line-height: 1.4;
}
button:hover, .btn:hover { background: var(--gray-50); border-color: var(--border-strong); }
button:active, .btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-success { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.btn-success:hover { background: var(--ok); color: #fff; }
.btn-danger { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.btn-danger:hover { background: var(--bad); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text-secondary); }
.btn-warning { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.btn-warning:hover { background: var(--warn); color: #fff; }
.btn-sm, .btn-sm button { padding: 4px 10px; font-size: 12px; }

/* ── 表单控件现代化 ── */
input[type="text"], input[type="number"], input[type="date"], input[type="search"],
input:not([type]), select, textarea {
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  padding: 8px 10px; font-size: 13px; transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
label { font-size: 12.5px; font-weight: 500; color: var(--text-secondary); }

/* 复选框/单选框不受全局 input 100% 宽度影响(部件管理等场景) */
input[type="checkbox"], input[type="radio"] { width: auto; }

/* ── 弹窗现代化 ── */
.modal-overlay {
  background: rgba(15, 17, 22, .45) !important;
  backdrop-filter: blur(3px);
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg);
}
.modal-header {
  font-size: 15px; font-weight: 700; letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.modal-header h3 { display: flex; align-items: center; gap: 8px; }
.modal-close {
  color: var(--text-secondary); border-radius: 6px;
  width: 28px; height: 28px; padding: 0; font-size: 16px; line-height: 1;
}
.modal-close:hover { color: var(--text); background: var(--gray-100); }
.modal-footer {
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; padding-top: 14px;
}
html[data-theme="dark"] .modal-overlay { background: rgba(0, 0, 0, .6) !important; }

/* 侧边栏图标 */
.sidebar-nav a { display: flex; align-items: center; gap: 9px; }
.sidebar-nav a .svg-icon { color: var(--gray-500); transition: color .15s ease; }
.sidebar-nav a:hover .svg-icon, .sidebar-nav a.active .svg-icon { color: var(--accent); }

/* 深色模式:侧边栏文字改浅色(近白) */
html[data-theme="dark"] .sidebar-nav a { color: var(--text); }
html[data-theme="dark"] .sidebar-nav a:hover { color: var(--accent); }
html[data-theme="dark"] .sidebar-logo { color: var(--text); }
html[data-theme="dark"] .sidebar-nav a .svg-icon { color: var(--text-secondary); }
html[data-theme="dark"] .sidebar-nav a:hover .svg-icon,
html[data-theme="dark"] .sidebar-nav a.active .svg-icon { color: var(--accent); }

/* ── 新组件:P1/P2 共用 ────────────────────────────────────── */

/* KPI 卡(驾驶舱首行/工作台) */
.kpi-strip { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; scrollbar-width: none; }
.kpi-strip::-webkit-scrollbar { display: none; }
.kpi-card {
  flex: 1 0 150px; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow-xs);
  display: flex; flex-direction: column; gap: 2px;
  transition: box-shadow .15s ease, transform .15s ease;
}
.kpi-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.kpi-label { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.kpi-label .svg-icon { color: var(--gray-500); }
.kpi-num { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); line-height: 1.2; }
.kpi-num .unit { font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.kpi-sub { font-size: 11px; color: var(--text-secondary); }
.kpi-card.accent .kpi-num { color: var(--accent); }
.kpi-card.ok .kpi-num { color: var(--ok); }
.kpi-card.bad .kpi-num { color: var(--bad); }
.kpi-card.warn .kpi-num { color: var(--warn); }

/* 数据表格 */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-secondary);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--gray-100); vertical-align: top; }
.data-table tbody tr:hover { background: var(--gray-50); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* 筛选 chip */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
  cursor: pointer; user-select: none; transition: all .12s ease; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .n { font-family: var(--font-num); font-size: 11px; opacity: .75; }

/* 图标按钮 */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary); cursor: pointer; transition: all .12s ease;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* 区块标题 */
.section-title {
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .05em; margin: 0 0 10px;
  display: flex; align-items: center; gap: 6px;
}

/* 驾驶舱部件壳 */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-xs); padding: 14px 16px;
  display: flex; flex-direction: column; min-height: 0;
  transition: box-shadow .15s ease;
}
.panel:hover { box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.panel-head .svg-icon { color: var(--accent); }
.panel-title { font-size: 13px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.panel-tools { margin-left: auto; display: flex; gap: 4px; }
.panel-body { flex: 1; min-height: 0; font-size: 12.5px; color: var(--text-secondary); }

/* ── 深色主题 ─────────────────────────────────────────────── */
html[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #161b24;
  --border: #262e3d;
  --border-strong: #364154;
  --text: #e6e9ef;
  --text-secondary: #8b94a7;
  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: #262c48;
  --ok: #34d399;
  --ok-soft: #0f2e24;
  --bad: #f87171;
  --bad-soft: #3a1d1d;
  --warn: #fbbf24;
  --warn-soft: #33270d;
  --info: #60a5fa;
  --info-soft: #14273f;
  --gray-50: #171d28;
  --gray-100: #1d2431;
  --gray-200: #262e3d;
  --gray-300: #364154;
  --gray-500: #8b94a7;
  --gray-700: #c3cad8;
  --gray-900: #e6e9ef;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow: 0 4px 10px rgba(0, 0, 0, .45);
  --shadow-lg: 0 12px 24px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

html[data-theme="dark"] body { background: var(--bg) !important; }
/* 浮动北京时间钟:深色下换深色底,避免白底白字看不见 */
.floating-time {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.floating-time .time { color: var(--text); }
.floating-time .date { color: var(--text-secondary); }
.floating-time .label { color: var(--text-secondary); opacity: .7; }
/* 存量组件暗色适配(主要表面) */
html[data-theme="dark"] .card,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .hamburger,
html[data-theme="dark"] .modal-box,
html[data-theme="dark"] .modal-close,
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .msg,
html[data-theme="dark"] .list-item,
html[data-theme="dark"] table,
html[data-theme="dark"] .month-banner,
html[data-theme="dark"] .info-card,
html[data-theme="dark"] .rule-toggle,
html[data-theme="dark"] .rule-body,
html[data-theme="dark"] .il-nav-bar,
html[data-theme="dark"] .cal-wrap,
html[data-theme="dark"] .tooltip-box,
html[data-theme="dark"] .mb-tip,
html[data-theme="dark"] .il-admin-body,
html[data-theme="dark"] .il-ev-list .op-btns button,
html[data-theme="dark"] .month-banner .mb-tip {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
html[data-theme="dark"] .cal-cell { background: var(--gray-50); }
html[data-theme="dark"] .cal-cell.other-month { background: transparent; }
html[data-theme="dark"] pre, html[data-theme="dark"] code { background: var(--gray-100); color: var(--text); }
html[data-theme="dark"] a { color: var(--accent); }

/* 投资月历信息卡小标签(全年/半年/季度):深色下换深色底 */
html[data-theme="dark"] .info-card .ic-hdr .tag.yearly { background: var(--accent-soft); color: #a5b4fc; }
html[data-theme="dark"] .info-card .ic-hdr .tag.half { background: var(--ok-soft); color: #34d399; }
html[data-theme="dark"] .info-card .ic-hdr .tag.quarterly { background: var(--warn-soft); color: #fbbf24; }

/* 方法论多选组件(ms-*):深色适配 */
html[data-theme="dark"] .ms-display { background: var(--surface); border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .ms-dropdown { background: var(--surface); border-color: var(--border); }
html[data-theme="dark"] .ms-option { color: var(--text-secondary); }
html[data-theme="dark"] .ms-option:hover { color: var(--text); }
html[data-theme="dark"] .ms-option input[type="checkbox"] { background: var(--surface); border-color: var(--border-strong); }
html[data-theme="dark"] .ms-option input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }

/* 主题切换按钮(基础样式在 style.css,双主题变量此处覆盖) */
html[data-theme="dark"] .theme-toggle {
  border-color: var(--border); color: var(--text-secondary);
}
html[data-theme="dark"] .theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* 移动端微调 */
@media (max-width: 768px) {
  .page-header h1 { font-size: 20px; }
  .kpi-card { flex: 0 0 132px; min-width: 132px; padding: 12px 14px; }
  .kpi-num { font-size: 20px; }
  .panel { padding: 12px; }
  /* 头部按钮:占满整行、均分宽度,避免 flex-shrink:0 导致横向溢出 */
  .page-header .btn { width: auto; flex: 1 1 0; min-width: 0; }
  .dash-actions { width: 100%; }
  .dash-actions .btn { flex: 1; }
  /* KPI 条:折叠为 3列×2行 网格,不再横滑 */
  .kpi-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; overflow: visible; }
  .kpi-card { flex: none; min-width: 0; width: auto; padding: 10px 12px; }
  .kpi-card .kpi-label { white-space: normal; line-height: 1.3; }
  /* 浮动时钟:强制固定在视口左下,避免横滚溢出时 fixed 定位漂移 */
  .floating-time { position: fixed !important; left: 8px; right: auto; bottom: max(8px, env(safe-area-inset-bottom)); }
  /* 卡片内字段表(数值预测等)允许收缩,不被全局 min-width:600px 撑破右缘 */
  .card table { min-width: 0; }
}

/* ═══ 驾驶舱栅格与部件管理 ═══ */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  align-items: stretch;
}
.dash-grid .panel { margin: 0; min-height: 230px; min-width: 0; }  /* min-width:0 允许收缩,避免 canvas 撑破栅格 */
.panel-body { min-width: 0; }
.panel-body canvas { max-width: 100%; }
.dash-w-sm { grid-column: span 4; }
.dash-w-md { grid-column: span 6; }
.dash-w-lg { grid-column: span 8; }
.dash-w-xl { grid-column: span 12; }
.panel.dragging { opacity: .55; border: 1px dashed var(--accent); z-index: 10; }
.panel-drag-hint {
  margin-left: auto; cursor: grab; color: var(--gray-500);
  font-size: 14px; padding: 0 4px; user-select: none; touch-action: none;
}
.panel-drag-hint:active { cursor: grabbing; }

.dash-manager {
  position: fixed; right: 16px; bottom: 16px; z-index: 999;
  width: 380px; max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 14px; font-size: 13px;
}
.dash-mgr-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; white-space: nowrap; }
.dash-mgr-head button { padding: 3px 10px; font-size: 12px; margin-left: 6px; }
.dash-mgr-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 7px 4px; border-bottom: 1px solid var(--gray-100);
}
.dash-mgr-row label {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
.dash-mgr-row label input { flex-shrink: 0; }
.dash-mgr-ops { flex-shrink: 0; display: flex; }
.dash-mgr-ops button {
  border: 1px solid var(--border); background: var(--surface); border-radius: 6px;
  width: 24px; height: 24px; cursor: pointer; color: var(--text-secondary); margin-left: 4px;
}
.dash-mgr-ops button:hover { border-color: var(--accent); color: var(--accent); }

/* 部件内的迷你条形(方法论/类型等纯 DOM 图) */
.mini-bar-row { margin-bottom: 9px; }
.mini-bar-row .lbl { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.mini-bar-track { height: 7px; background: var(--gray-100); border-radius: 4px; overflow: hidden; }
.mini-bar-fill { height: 100%; border-radius: 4px; transition: width .5s ease; }

/* 驾驶舱 Feed / 列表通用行 */
.feed-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--gray-100); font-size: 12.5px;
}
.feed-item:last-child { border-bottom: none; }
.feed-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-item .time { color: var(--text-secondary); font-size: 11px; white-space: nowrap; }

@media (max-width: 1100px) {
  .dash-w-sm { grid-column: span 6; }
  .dash-w-md, .dash-w-lg { grid-column: span 12; }
}
/* 驾驶舱热力图部件 */
.hm-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; font-size: 11px; color: var(--text-secondary); margin-bottom: 6px; }
.hm-legend .sq { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.hm-scroll { overflow-x: auto; padding-bottom: 2px; }
.hm-months { display: grid; grid-auto-flow: column; gap: 3px; font-size: 10px; color: var(--text-secondary); margin-bottom: 3px; }
.hm-months span { width: 11px; overflow: visible; white-space: nowrap; }
.hm-grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 11px); gap: 3px; width: max-content; }
.hm-cell { width: 11px; height: 11px; border-radius: 2px; }
.hm-cell.hm-empty { background: transparent; }
.hm-l0 { background: var(--gray-200); }
.hm-l1 { background: #bbf7d0; }
.hm-l2 { background: #4ade80; }
.hm-l3 { background: #22c55e; }
.hm-l4 { background: #15803d; }
.hm-cell:hover { outline: 1px solid var(--accent); }
@media (max-width: 768px) {
  .hm-legend { justify-content: flex-start; }
}

@media (max-width: 768px) {
  .dash-grid { grid-template-columns: 1fr; }
  .dash-w-sm, .dash-w-md, .dash-w-lg, .dash-w-xl { grid-column: span 1; }
  .dash-grid .panel { min-height: 0; }
  .dash-manager { left: 12px; right: 12px; width: auto; bottom: 12px; }
}

