/* ==========================================================================
   components.css — Rhea 风格组件类
   约束：只引用 token；控件圆角 16px、高 40px；焦点是 3px 柔光环（不是 outline）
   ========================================================================== */

/* ---------------- 按钮 ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur-input) var(--ease),
    color var(--dur-input) var(--ease),
    border-color var(--dur-input) var(--ease);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* 主按钮：hover 压暗，不位移不缩放 */
.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 80%, transparent); }

/* 次级 */
.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
}
.btn-secondary:hover { background: color-mix(in srgb, var(--secondary) 70%, transparent); }

/* 描边 */
.btn-outline {
  border-color: var(--border);
  background: var(--background);
  color: var(--foreground);
}
.btn-outline:hover { background: var(--muted); }

/* 幽灵 */
.btn-ghost { color: var(--foreground); }
.btn-ghost:hover { background: color-mix(in srgb, var(--muted) 50%, transparent); }

/* 危险 */
.btn-destructive {
  background: var(--destructive);
  color: var(--destructive-foreground);
}
.btn-destructive:hover { background: color-mix(in srgb, var(--destructive) 80%, transparent); }
.btn-destructive-soft {
  background: color-mix(in srgb, var(--destructive) 12%, transparent);
  color: var(--destructive);
}
.btn-destructive-soft:hover { background: color-mix(in srgb, var(--destructive) 20%, transparent); }

/* 链接式 */
.btn-link {
  height: auto;
  padding: 0;
  border-radius: 0;
  color: var(--foreground);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: color-mix(in srgb, var(--foreground) 30%, transparent);
}
.btn-link:hover { text-decoration-color: var(--foreground); }

/* 尺寸 */
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-lg { height: 44px; padding: 0 24px; font-size: 15px; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }

/* ---------------- 输入控件 ---------------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 13px; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted-foreground); }
.error-text { font-size: 12px; color: var(--destructive); }

.input,
.textarea,
.select {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--input);
  background: var(--card);
  color: var(--foreground);
  font-size: 14px;
  transition: border-color var(--dur-input) var(--ease),
    box-shadow var(--dur-input) var(--ease);
}
.textarea { height: auto; padding: 10px 14px; line-height: 1.5; resize: vertical; min-height: 88px; }

.input::placeholder,
.textarea::placeholder { color: var(--muted-foreground); }

.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--destructive);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--destructive) 20%, transparent);
}

.input:disabled,
.textarea:disabled { opacity: 0.5; cursor: not-allowed; }

.input-sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: var(--radius-sm); }

/* 带图标输入 */
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .icon-l {
  position: absolute;
  left: 13px;
  display: flex;
  color: var(--muted-foreground);
  pointer-events: none;
}
.input-wrap .input { padding-left: 40px; }
.input-wrap .kbd-r {
  position: absolute;
  right: 10px;
  display: flex;
  gap: 4px;
}

/* ---------------- 开关 / 复选 ---------------- */

.switch {
  position: relative;
  width: 40px;
  height: 24px;
  flex: none;
  border: none;
  border-radius: 999px;
  background: var(--input);
  cursor: pointer;
  padding: 0;
  transition: background-color var(--dur-input) var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--background);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-input) var(--ease);
}
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after {
  transform: translateX(16px);
  background: var(--primary-foreground);
}
.switch:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
}

.checkbox {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid var(--input);
  background: var(--card);
  appearance: none;
  display: grid;
  place-content: center;
  cursor: pointer;
  flex: none;
  transition: background-color var(--dur-input) var(--ease),
    border-color var(--dur-input) var(--ease);
}
.checkbox:checked {
  background: var(--primary);
  border-color: var(--primary);
}
.checkbox:checked::after {
  content: "";
  width: 10px;
  height: 6px;
  border-left: 2px solid var(--primary-foreground);
  border-bottom: 2px solid var(--primary-foreground);
  transform: rotate(-45deg) translate(1px, -1px);
}
.checkbox:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
}

/* ---------------- 卡片 ---------------- */

.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.card-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 600; }
.card-desc { font-size: 13px; color: var(--muted-foreground); line-height: 1.55; }
.card-footer { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

.metric { display: flex; flex-direction: column; gap: 8px; }
.metric-label { font-size: 12px; color: var(--muted-foreground); font-weight: 500; }
.metric-value { font-size: 28px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; }
.metric-delta { font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.metric-delta.up { color: var(--destructive); }        /* 上升：全站唯一彩色 */
.metric-delta.down { color: var(--muted-foreground); } /* 下降：回到灰阶，保持零色相 */

/* ---------------- Badge ---------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 10px;
  border-radius: var(--radius);
  background: var(--secondary);
  color: var(--secondary-foreground);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}
.badge-outline { background: transparent; border: 1px solid var(--border); }
.badge-primary { background: var(--primary); color: var(--primary-foreground); }
.badge-soft { background: color-mix(in srgb, var(--primary) 10%, transparent); }
.badge-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.badge-destructive-soft {
  background: color-mix(in srgb, var(--destructive) 12%, transparent);
  color: var(--destructive);
}
.badge-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
}

/* ---------------- 分隔线 ---------------- */

.sep { height: 1px; background: var(--border); border: none; }
.sep-v { width: 1px; align-self: stretch; background: var(--border); }

/* ---------------- 表格 ---------------- */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--card);
}
.table { width: 100%; border-collapse: collapse; }
.table th {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  height: 48px;
}
.table tbody tr { transition: background-color var(--dur-pop) var(--ease); }
.table tbody tr:hover { background: color-mix(in srgb, var(--muted) 50%, transparent); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------- Tabs ---------------- */

.tabs { display: flex; flex-direction: column; gap: 16px; }
.tablist {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--muted);
  align-self: flex-start;
  flex-wrap: wrap;
}
.tab {
  height: 32px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--dur-input) var(--ease),
    color var(--dur-input) var(--ease);
}
.tab:hover { color: var(--foreground); }
.tab[aria-selected="true"] {
  background: var(--card);
  color: var(--foreground);
  box-shadow: var(--shadow-sm);
}
.tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
}
.tabpanel[hidden] { display: none; }

/* ---------------- 侧边栏导航 ---------------- */

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 10px;
  background: var(--primary);
  color: var(--primary-foreground);
  display: grid;
  place-content: center;
  font-size: 14px;
  font-weight: 600;
}
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }

.nav-group { display: flex; flex-direction: column; gap: 4px; }
.nav-group-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
  padding: 0 8px 6px;
}
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--sidebar-foreground);
  cursor: pointer;
  transition: background-color var(--dur-nav) var(--ease),
    color var(--dur-nav) var(--ease);
}
.nav-item:hover { background: var(--sidebar-accent); }
.nav-item.active {
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 500;
}
.nav-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
}
.nav-item .ico { display: flex; opacity: 0.8; }
.nav-item.active .ico { opacity: 1; }

/* ---------------- 顶栏 ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 60px;
  padding: 0 40px;
  background: color-mix(in srgb, var(--background) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .crumb { font-size: 13px; color: var(--muted-foreground); }
.topbar .crumb b { color: var(--foreground); font-weight: 500; }
@media (max-width: 900px) {
  .topbar { padding: 0 20px; gap: 10px; }
  .topbar .crumb { display: none; }
}

/* ---------------- 头像 / 菜单 ---------------- */

.avatar {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  display: grid;
  place-content: center;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  overflow: hidden;
}
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }

/* 下拉菜单 */
.menu {
  min-width: 220px;
  padding: 6px;
  background: var(--popover);
  color: var(--popover-foreground);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), var(--ring-pop);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  cursor: pointer;
  transition: background-color var(--dur-input) var(--ease);
}
.menu-item:hover { background: var(--accent); color: var(--accent-foreground); }
.menu-item.danger { color: var(--destructive); }
.menu-item.danger:hover { background: color-mix(in srgb, var(--destructive) 12%, transparent); }
.menu-sep { height: 1px; margin: 6px 0; background: var(--border); }
.menu-label {
  padding: 6px 12px 4px;
  font-size: 12px;
  color: var(--muted-foreground);
}
.menu-shortcut { margin-left: auto; font-size: 11.5px; color: var(--muted-foreground); }

/* ---------------- 对话框 ---------------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade-in var(--dur-pop) var(--ease);
}
.dialog-backdrop[hidden] { display: none; }
.dialog {
  width: min(440px, 100%);
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: 24px;
  animation: fade-zoom var(--dur-pop) var(--ease);
}
.dialog-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.dialog-title { font-size: 17px; font-weight: 600; }
.dialog-desc { font-size: 13.5px; color: var(--muted-foreground); line-height: 1.55; }
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-zoom {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---------------- 加载动画 ---------------- */

.spin {
  animation: spin 900ms linear infinite;
  transform-origin: center;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------------- 代码 / 命令行 ---------------- */

.code-block {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--muted);
  padding: 14px 16px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--foreground);
}
.code-block .c { color: var(--muted-foreground); }
.code-inline {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

/* ---------------- 令牌色板 ---------------- */

.swatch {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
}
.swatch-chip {
  height: 56px;
  border-bottom: 1px solid var(--border);
}
.swatch-meta { padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.swatch-name { font-size: 12px; font-weight: 500; }
.swatch-hex { font-size: 11.5px; color: var(--muted-foreground); font-family: ui-monospace, Menlo, monospace; }

/* ---------------- 图表 ---------------- */

.chart { width: 100%; height: 240px; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--muted-foreground); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: block; }

/* ---------------- 字阶 ---------------- */

.type-row {
  display: flex;
  align-items: baseline;
  gap: 24px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.type-row:last-child { border-bottom: none; }
.type-meta {
  width: 170px;
  flex: none;
  font-size: 11.5px;
  color: var(--muted-foreground);
  font-family: ui-monospace, Menlo, monospace;
}

/* ---------------- 空态 / 提示条 ---------------- */

.alert {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 13px;
  line-height: 1.55;
}
.alert-title { font-weight: 500; margin-bottom: 2px; }
.alert-desc { color: var(--muted-foreground); font-size: 12.5px; }
.alert-destructive {
  border-color: color-mix(in srgb, var(--destructive) 40%, transparent);
  background: color-mix(in srgb, var(--destructive) 6%, transparent);
}
.alert-destructive .alert-title { color: var(--destructive); }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 24px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  color: var(--muted-foreground);
}
.empty-icon {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--muted);
  display: grid;
  place-content: center;
  color: var(--muted-foreground);
}

/* ---------------- Hero ---------------- */

.hero {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--card);
  padding: 40px;
  margin-bottom: 48px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, var(--border) 1px, transparent 1px),
    linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: 56px 56px;
  opacity: 0.35;
  mask-image: radial-gradient(120% 90% at 88% 0%, #000 0%, transparent 62%);
  -webkit-mask-image: radial-gradient(120% 90% at 88% 0%, #000 0%, transparent 62%);
}
.hero > * { position: relative; z-index: 1; }
.hero h1 { font-size: clamp(26px, 3.4vw, 38px); letter-spacing: -0.035em; max-width: 18ch; }
.hero p { margin-top: 14px; max-width: 56ch; font-size: 15px; line-height: 1.65; color: var(--muted-foreground); }
.hero-actions { margin-top: 26px; display: flex; flex-wrap: wrap; gap: 10px; }
@media (max-width: 900px) { .hero { padding: 28px 22px; } }

/* ---------------- 图标按钮组（主题切换） ---------------- */

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--muted);
}
.seg button {
  width: 30px;
  height: 26px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted-foreground);
  display: grid;
  place-content: center;
  cursor: pointer;
  transition: background-color var(--dur-input) var(--ease),
    color var(--dur-input) var(--ease);
}
.seg button:hover { color: var(--foreground); }
.seg button[aria-pressed="true"] {
  background: var(--card);
  color: var(--foreground);
  box-shadow: var(--shadow-sm);
}
.seg button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 30%, transparent);
}
