/* CodeConsole 管理后台样式。
 * 严格引用 docs/design/DESIGN.md 的 token（颜色/字体/圆角/间距/组件），
 * 不自造色板。Berkeley Mono 不可用时回落到等宽字体栈。
 * 视觉规则：cream 画布、ink 文字、4px 圆角交互元素、0px 圆角容器、1px hairline 分隔、无阴影无渐变、ASCII 标记。 */

:root {
  /* colors */
  --ink: #201d1d;
  --ink-deep: #0f0000;
  --charcoal: #302c2c;
  --body: #424245;
  --mute: #646262;
  --stone: #6e6e73;
  --ash: #9a9898;
  --canvas: #fdfcfc;
  --surface-soft: #f8f7f7;
  --surface-card: #f1eeee;
  --surface-dark: #201d1d;
  --surface-dark-elevated: #302c2c;
  --hairline: rgba(15, 0, 0, 0.12);
  --hairline-strong: #646262;
  --on-dark: #fdfcfc;
  --on-dark-mute: #9a9898;
  --accent: #007aff;
  --danger: #ff3b30;
  --warning: #ff9f0a;
  --success: #30d158;

  /* typography */
  --font-mono: "Berkeley Mono", "JetBrains Mono", "IBM Plex Mono", ui-monospace,
    SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* rounded */
  --r-sm: 4px;
  --r-none: 0px;

  /* spacing */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 12px;
  --sp-lg: 16px;
  --sp-xl: 24px;
  --sp-xxl: 32px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body[data-view="login"] { min-height: 100vh; }
body[data-view="app"] { min-height: 100vh; }

.mute { color: var(--mute); }
.mute-dark { color: var(--on-dark-mute); }

/* ===== 登录视图 ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-xl);
}
.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-none);
  padding: var(--sp-xxl);
}
.login-head { margin-bottom: var(--sp-xl); }
.wordmark {
  font-weight: 700;
  letter-spacing: 0;
  color: var(--ink);
  margin-bottom: var(--sp-lg);
}
.wordmark-dark { color: var(--on-dark); }
.login-title { font-size: 22px; font-weight: 700; margin: 0 0 var(--sp-xs); }
.login-sub { font-size: 14px; color: var(--mute); margin: 0; }

.login-form { display: flex; flex-direction: column; gap: var(--sp-lg); }
.field { display: flex; flex-direction: column; gap: var(--sp-xs); }
.field-label { font-size: 14px; color: var(--ink); }
.field-row { display: flex; gap: var(--sp-sm); align-items: flex-end; }
.field-grow { flex: 1; }

.input {
  background: var(--surface-soft);
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: var(--sp-sm) var(--sp-md);
  height: 40px;
  font-family: var(--font-mono);
  font-size: 16px;
  width: 100%;
}
.input:focus {
  outline: none;
  background: var(--canvas);
  border-color: var(--ink);
}
.code-input { letter-spacing: 0.25em; font-weight: 500; }

/* ===== 按钮 ===== */
.btn {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  line-height: 2;
  border-radius: var(--r-sm);
  cursor: pointer;
  border: 1px solid transparent;
  padding: 0 var(--sp-xl);
  height: 40px;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: var(--canvas); }
.btn-primary:active { background: var(--ink-deep); }
.btn-primary:disabled { background: var(--surface-card); color: var(--ash); cursor: not-allowed; }
.btn-secondary {
  background: var(--canvas);
  color: var(--ink);
  border-color: var(--hairline-strong);
}
.btn-secondary:active { background: var(--surface-soft); }
.btn-secondary:disabled { color: var(--ash); border-color: var(--hairline); cursor: not-allowed; }
.btn-ghost-dark {
  background: transparent;
  color: var(--on-dark-mute);
  border-color: var(--surface-dark-elevated);
  height: 36px;
}
.btn-ghost-dark:hover { color: var(--on-dark); }

.login-foot { margin-top: var(--sp-xl); font-size: 14px; }

/* ===== 控制台布局 ===== */
body[data-view="app"] #login-view { display: none; }
body[data-view="login"] #app-view { display: none; }

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

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--surface-dark);
  color: var(--on-dark);
  display: flex;
  flex-direction: column;
  padding: var(--sp-xl) 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { padding: 0 var(--sp-xl) var(--sp-xl); border-bottom: 1px solid var(--surface-dark-elevated); }
.sidebar-sub { font-size: 14px; margin-top: var(--sp-xs); }
.menu { display: flex; flex-direction: column; padding: var(--sp-lg) 0; flex: 1; }
.menu-item {
  display: block;
  padding: var(--sp-sm) var(--sp-xl);
  color: var(--on-dark-mute);
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
  border-left: 2px solid transparent;
}
.menu-item.is-active {
  color: var(--on-dark);
  background: var(--surface-dark-elevated);
  border-left-color: var(--on-dark);
}
.menu-item.is-disabled { opacity: 0.45; cursor: not-allowed; }
.sidebar-foot { padding: var(--sp-lg) var(--sp-xl) 0; border-top: 1px solid var(--surface-dark-elevated); }
.admin-email { font-size: 14px; margin-bottom: var(--sp-sm); word-break: break-all; }

.content {
  flex: 1;
  min-width: 0;
  padding: var(--sp-xxl);
  display: flex;
  flex-direction: column;
  gap: var(--sp-xl);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 1px solid var(--hairline);
  padding-bottom: var(--sp-lg);
}
.page-title { margin: 0; font-size: 20px; font-weight: 700; }
.page-sub { font-size: 14px; }

/* ===== 指标卡片 ===== */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-md);
}
.metric-card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-none);
  padding: var(--sp-lg);
}
.metric-label { font-size: 14px; color: var(--mute); }
.metric-value { font-size: 30px; font-weight: 700; color: var(--ink); margin: var(--sp-xs) 0; line-height: 1.2; }
.metric-hint { font-size: 14px; }

/* ===== 图表 ===== */
.chart-section { display: flex; flex-direction: column; gap: var(--sp-md); }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-md);
}
.section-title { margin: 0; font-size: 16px; font-weight: 700; }
.tab-strip { display: flex; gap: var(--sp-xs); border-bottom: 1px solid var(--hairline); }
.tab {
  background: transparent;
  color: var(--mute);
  border: none;
  border-bottom: 2px solid transparent;
  padding: var(--sp-sm) var(--sp-lg);
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--r-none);
}
.tab.is-active { color: var(--ink); border-bottom-color: var(--ash); }

.chart-tile {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-none);
  padding: var(--sp-lg);
  position: relative;
  min-height: 280px;
}
.chart-svg { width: 100%; height: 280px; display: block; }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 14px; }

/* SVG 图表元素 */
.chart-svg .axis { stroke: var(--hairline); stroke-width: 1; }
.chart-svg .grid { stroke: var(--hairline); stroke-width: 1; stroke-dasharray: 2 4; }
.chart-svg .bar { fill: var(--ink); }
.chart-svg .bar-accent { fill: var(--accent); }
.chart-svg .label-x { fill: var(--mute); font-size: 11px; font-family: var(--font-mono); }
.chart-svg .label-y { fill: var(--mute); font-size: 11px; font-family: var(--font-mono); }
.chart-svg .value-label { fill: var(--ink); font-size: 11px; font-family: var(--font-mono); font-weight: 500; }

/* ===== 明细表 ===== */
.data-table-wrap { border: 1px solid var(--hairline); border-radius: var(--r-none); }
.data-table-summary {
  cursor: pointer;
  padding: var(--sp-md) var(--sp-lg);
  font-size: 14px;
  color: var(--ink);
  font-weight: 500;
  list-style: none;
}
.data-table-summary::-webkit-details-marker { display: none; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td {
  text-align: right;
  padding: var(--sp-sm) var(--sp-lg);
  border-top: 1px solid var(--hairline);
  white-space: nowrap;
}
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table thead th { color: var(--mute); font-weight: 500; border-top: none; }
.data-table tbody tr:hover { background: var(--surface-soft); }

.content-foot { margin-top: auto; padding-top: var(--sp-xl); border-top: 1px solid var(--hairline); font-size: 14px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: var(--sp-xl);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-dark);
  color: var(--on-dark);
  padding: var(--sp-sm) var(--sp-lg);
  border-radius: var(--r-sm);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  max-width: 90vw;
  z-index: 50;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.is-error { background: var(--danger); color: var(--canvas); }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .sidebar { position: static; height: auto; width: 100%; }
  .sidebar-brand { border-bottom: 1px solid var(--surface-dark-elevated); }
  .menu { flex-direction: row; flex-wrap: wrap; padding: var(--sp-sm); }
  .menu-item { border-left: none; border-bottom: 2px solid transparent; padding: var(--sp-xs) var(--sp-md); }
  .menu-item.is-active { border-left: none; border-bottom-color: var(--on-dark); }
  .sidebar-foot { border-top: 1px solid var(--surface-dark-elevated); display: flex; align-items: center; justify-content: space-between; }
  .app-layout { flex-direction: column; }
  .content { padding: var(--sp-lg); }
  .metric-value { font-size: 24px; }
}
