/* ============================================================
   广告归因与路由系统 — 管理后台 Design System
   ============================================================ */

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Brand */
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --primary-bg: rgba(99,102,241,.08);

  /* Semantic */
  --success: #22c55e;
  --success-bg: rgba(34,197,94,.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245,158,11,.1);
  --danger: #ef4444;
  --danger-bg: rgba(239,68,68,.1);
  --info: #3b82f6;
  --info-bg: rgba(59,130,246,.1);

  /* Neutral */
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  /* Sidebar */
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: var(--primary);
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  --sidebar-width: 240px;

  /* Layout */
  --header-h: 60px;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.04);
  --transition: .2s ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}
.sidebar-brand {
  height: var(--header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}
.sidebar-brand .logo {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 16px;
}
.sidebar-brand h1 {
  font-size: 15px; font-weight: 600; color: #fff;
  white-space: nowrap;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav-section {
  padding: 8px 20px 4px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: rgba(148,163,184,.5);
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  border-radius: 0;
  transition: all var(--transition);
  cursor: pointer;
  border-left: 3px solid transparent;
  font-size: 13.5px;
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}
.nav-item.active {
  background: rgba(99,102,241,.12);
  color: var(--sidebar-text-active);
  border-left-color: var(--primary-light);
  font-weight: 500;
}
.nav-item .icon { font-size: 17px; width: 22px; text-align: center; }

/* Content Area */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: auto;
}
.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.topbar .breadcrumb {
  font-size: 13px; color: var(--text-secondary);
}
.topbar .breadcrumb strong { color: var(--text); font-weight: 600; }
.topbar .user-info {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-secondary);
}
.topbar .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 13px;
}
.content {
  padding: 24px 28px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

/* ---------- Page Header ---------- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-header .subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 14px; font-weight: 600; }
.card-body { padding: 20px; }

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  display: flex; align-items: flex-start; gap: 14px;
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.kpi-info { flex: 1; }
.kpi-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.kpi-change { font-size: 12px; margin-top: 4px; font-weight: 500; }
.kpi-change.up { color: var(--success); }
.kpi-change.down { color: var(--danger); }

/* ---------- Tables ---------- */
.table-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: #f8fafc;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  white-space: nowrap;
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-hover); }
td.mono { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; color: var(--primary-dark); }
td.number { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-dot {
  width: 6px; height: 6px; border-radius: 50%;
  display: inline-block;
}
.badge-active { background: var(--success-bg); color: #15803d; }
.badge-active .badge-dot { background: var(--success); }
.badge-disabled { background: var(--warning-bg); color: #b45309; }
.badge-disabled .badge-dot { background: var(--warning); }
.badge-archived { background: rgba(100,116,139,.1); color: #475569; }
.badge-archived .badge-dot { background: #94a3b8; }
.badge-info { background: var(--info-bg); color: #1d4ed8; }
.badge-primary { background: var(--primary-bg); color: var(--primary-dark); }
.badge-danger { background: var(--danger-bg); color: #dc2626; }
.badge-warning { background: var(--warning-bg); color: #b45309; }
.badge-success { background: var(--success-bg); color: #15803d; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
  transition: all var(--transition);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 2px 8px rgba(99,102,241,.35); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }
.btn-group { display: flex; gap: 8px; }

/* ---------- Filter Toolbar ---------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  flex-wrap: wrap; gap: 12px;
}
.toolbar-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 6px; }
.page-size-label { font-size: 12px; color: var(--text-secondary); }
.toolbar .search-box {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  transition: border-color var(--transition);
}
.toolbar .search-box:focus-within { border-color: var(--primary); }
.toolbar .search-box input {
  border: none; background: transparent; outline: none;
  padding: 7px 0; width: 200px; color: var(--text);
}
.toolbar select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.toolbar select:focus { border-color: var(--primary); }

/* ---------- Pagination ---------- */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  flex-wrap: wrap; gap: 12px;
}
.page-info { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.page-btns { display: flex; gap: 4px; }
.page-btns .btn { min-width: 32px; justify-content: center; }
.page-dots { display: flex; align-items: center; padding: 0 4px; color: var(--text-muted); font-size: 12px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0;
  animation: fadeIn .2s ease forwards;
}
@keyframes fadeIn { to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 90%; max-width: 640px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  transform: translateY(10px);
  animation: slideUp .25s ease forwards;
}
@keyframes slideUp { to { transform: translateY(0); } }
.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  width: 28px; height: 28px; border-radius: 6px;
  border: none; background: transparent;
  font-size: 18px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* Form inside modal */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.form-group input, .form-group select, .form-group textarea {
  padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none;
  transition: border-color var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
}
.campaign-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}
.modal-section-head {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}
.modal-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.modal-section-desc {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-secondary);
}
.form-group input.readonly-lock {
  background: #f8fafc;
  color: #475569;
  border-style: dashed;
}
.form-group .text-code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}
.form-group textarea.text-code {
  min-height: 110px;
  line-height: 1.45;
}
.form-hint {
  font-size: 12px;
  color: var(--text-muted);
}
.form-control-static {
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Tree View ---------- */
.tree-list { list-style: none; }
.tree-item {
  border-bottom: 1px solid var(--border-light);
}
.tree-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; cursor: pointer;
  transition: background var(--transition);
}
.tree-row:hover { background: var(--surface-hover); }
.tree-toggle {
  width: 20px; height: 20px; border-radius: 4px;
  border: none; background: transparent;
  font-size: 12px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--transition);
}
.tree-toggle.open { transform: rotate(90deg); }
.tree-children {
  padding-left: 28px;
  display: none;
}
.tree-children.open { display: block; }
.tree-name { font-weight: 500; flex: 1; }

/* ---------- Matrix Grid ---------- */
.matrix-container { overflow-x: auto; }
.matrix-table { border-collapse: collapse; min-width: 100%; }
.matrix-table th, .matrix-table td {
  padding: 10px 14px; border: 1px solid var(--border);
  text-align: center; font-size: 12.5px;
  white-space: nowrap;
}
.matrix-table th {
  background: #f8fafc; font-weight: 600; color: var(--text-secondary);
  position: sticky; top: 0;
}
.matrix-table th:first-child {
  position: sticky; left: 0; z-index: 2; background: #f1f5f9;
}
.matrix-table td:first-child {
  position: sticky; left: 0; background: var(--surface);
  font-weight: 500; text-align: left; z-index: 1;
}
.matrix-cell {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 500;
}
.matrix-cell.assigned { background: var(--success-bg); color: #15803d; }
.matrix-cell.empty { color: var(--text-muted); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}
.tab-item {
  padding: 9px 18px;
  font-size: 13px; font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all var(--transition);
}
.tab-item:hover { color: var(--text); }
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Charts ---------- */
.chart-grid {
  display: grid; grid-template-columns: 2fr 1fr; gap: 16px;
  margin-bottom: 20px;
}
.chart-container { position: relative; height: 280px; }

/* ---------- Entity Cards (Media / Advertiser expand) ---------- */
.entity-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.entity-card:hover { box-shadow: var(--shadow-md); }
.entity-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  transition: background var(--transition);
}
.entity-header:hover { background: var(--surface-hover); }
.entity-header .left { display: flex; align-items: center; gap: 12px; }
.entity-header .entity-icon {
  width: 38px; height: 38px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.entity-header .entity-name { font-weight: 600; font-size: 14px; }
.entity-header .entity-meta { font-size: 12px; color: var(--text-secondary); }
.entity-header .arrow {
  font-size: 12px; color: var(--text-muted);
  transition: transform var(--transition);
}
.entity-header .arrow.open { transform: rotate(180deg); }
.entity-body {
  border-top: 1px solid var(--border-light);
  display: none;
}
.entity-body.open { display: block; }

/* ---------- Log Hint ---------- */
.log-hint {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--info-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--info);
  font-size: 13px; color: #1e40af;
  margin-bottom: 16px;
}

/* ---------- Empty State ---------- */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ---------- Stats row ---------- */
.stat-row {
  display: flex; gap: 20px; padding: 12px 0;
  flex-wrap: wrap;
}
.stat-item {
  display: flex; flex-direction: column; gap: 2px;
}
.stat-item .label { font-size: 11px; color: var(--text-muted); font-weight: 500; }
.stat-item .value { font-size: 18px; font-weight: 700; }

/* ---------- Utilities ---------- */
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 12px; }
.text-mono { font-family: 'JetBrains Mono', 'Fira Code', monospace; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.hidden { display: none !important; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 24px; left: 50%; transform: translateX(-50%) translateY(-80px);
  padding: 12px 24px; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: transform .3s ease, opacity .3s ease;
  border-left: 4px solid var(--success);
  pointer-events: none;
}
.toast-show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast-error { border-left-color: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .chart-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
