/* frontend/shared/tokens.css
 * Apple / Linear / TDesign cohesive visual system (Light cloud-white + Deep Space Dark, dynamic brand derivation).
 */
:root,
html[data-theme="light"] {
  --bg-canvas: #F5F7FB;
  --bg-surface: #FFFFFF;
  --bg-surface-glass: rgba(255, 255, 255, 0.84);
  --bg-subtle: #F3F5F9;
  --bg-code: #0F141E;
  --border-1: rgba(15, 23, 42, 0.08);
  --border-2: rgba(15, 23, 42, 0.14);
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-tertiary: #94A3B8;
  --brand: #0052D9;
  --brand-hover: color-mix(in srgb, var(--brand) 86%, #ffffff);
  --brand-active: color-mix(in srgb, var(--brand) 82%, #000000);
  --brand-soft: color-mix(in srgb, var(--brand) 10%, #ffffff);
  --brand-border: color-mix(in srgb, var(--brand) 28%, #ffffff);
  --success: #16A34A;
  --success-bg: #ECFDF3;
  --success-border: #A6F4C5;
  --warning: #D97706;
  --warning-bg: #FFFBEB;
  --warning-border: #FDE68A;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --danger-border: #FECACA;
  --radius-card: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 20px rgba(15, 23, 42, 0.04);
  --shadow-hover: 0 4px 12px rgba(15, 23, 42, 0.06), 0 12px 28px rgba(0, 82, 217, 0.08);
  --shadow-modal: 0 20px 50px rgba(15, 23, 42, 0.22), 0 4px 12px rgba(15, 23, 42, 0.08);
  --font-sans: "PingFang SC", "SF Pro Display", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg-canvas: #0D1117;
  --bg-surface: #161B22;
  --bg-surface-glass: rgba(22, 27, 34, 0.84);
  --bg-subtle: #1E2530;
  --bg-code: #090C12;
  --border-1: rgba(240, 246, 252, 0.09);
  --border-2: rgba(240, 246, 252, 0.16);
  --text-primary: #F0F6FC;
  --text-secondary: #9CA3AF;
  --text-tertiary: #6B7280;
  --brand: #4D8BF5;
  --brand-hover: color-mix(in srgb, var(--brand) 85%, #ffffff);
  --brand-active: color-mix(in srgb, var(--brand) 80%, #000000);
  --brand-soft: color-mix(in srgb, var(--brand) 18%, transparent);
  --brand-border: color-mix(in srgb, var(--brand) 42%, transparent);
  --success: #34D399;
  --success-bg: rgba(16, 185, 129, 0.14);
  --success-border: rgba(52, 211, 153, 0.35);
  --warning: #FBBF24;
  --warning-bg: rgba(245, 158, 11, 0.14);
  --warning-border: rgba(251, 191, 36, 0.35);
  --danger: #F87171;
  --danger-bg: rgba(239, 68, 68, 0.14);
  --danger-border: rgba(248, 113, 113, 0.35);
  --shadow-card: 0 2px 14px rgba(0, 0, 0, 0.36);
  --shadow-hover: 0 8px 28px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.hidden { display: none; }

@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); }
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  animation: pulseDot 2.2s ease-in-out infinite;
}
.live-dot.warn { background: var(--warning); animation: none; }
.live-dot.danger { background: var(--danger); animation: none; }

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--border-1) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.bento-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 20px 22px;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.kpi-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-card);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-tertiary); }

.td-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.16s ease;
}
.td-btn:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.td-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.td-btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 2px 6px color-mix(in srgb, var(--brand) 28%, transparent);
}
.td-btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.td-btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.td-btn-danger:hover { opacity: 0.92; color: #fff; background: var(--danger); }
.td-btn-ghost { background: transparent; border-color: transparent; }
.td-btn-ghost:hover { background: var(--bg-subtle); border-color: transparent; color: var(--text-primary); }
.td-btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; }

.td-input, .td-select, .td-textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.td-input:focus, .td-select:focus, .td-textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.td-textarea { min-height: 88px; resize: vertical; }

.td-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}
.td-tag-ok { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.td-tag-warn { background: var(--warning-bg); color: var(--warning); border-color: var(--warning-border); }
.td-tag-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.td-tag-brand { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-border); }
.td-tag-neutral { background: var(--bg-subtle); color: var(--text-secondary); border-color: var(--border-1); }

.table-wrap { width: 100%; overflow-x: auto; }
.td-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.td-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border-1);
  white-space: nowrap;
}
.td-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-1);
  vertical-align: middle;
}
.td-table tr:hover td { background: var(--bg-subtle); }

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border-1);
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success) 0%, #22C55E 100%);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-fill.warn { background: linear-gradient(90deg, #F59E0B 0%, var(--warning) 100%); }
.progress-fill.danger { background: linear-gradient(90deg, #EF4444 0%, var(--danger) 100%); }

.code-block {
  background: var(--bg-code);
  color: #E6EDF3;
  padding: 13px 15px;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow-x: auto;
  word-break: break-all;
  white-space: pre-wrap;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 36px 20px;
  color: var(--text-secondary);
}
.empty-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 390px;
}
.toast-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-2);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius-sm);
  padding: 11px 15px;
  box-shadow: var(--shadow-modal);
  font-size: 13px;
}
.toast-item.ok { border-left-color: var(--success); }
.toast-item.warn { border-left-color: var(--warning); }
.toast-item.err { border-left-color: var(--danger); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 9000;
}
.modal-panel {
  width: 100%;
  max-width: 540px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-modal);
  padding: 22px;
}
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: flex-end;
  z-index: 8800;
}
.drawer-panel {
  width: min(680px, 100vw);
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-1);
  box-shadow: var(--shadow-modal);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-field label { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.row-flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
