/* ==================== RESET & BASE ==================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #5b47e0;
  --primary-hover: #4a38c9;
  --primary-light: #ede9ff;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --running: #3b82f6;
  --running-light: #dbeafe;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

/* ==================== APP SHELL ==================== */
.app-layout {
  display: flex;
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: white;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 16px 16px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.sidebar-brand-icon {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 700;
}

.sidebar-brand-name { font-size: 15px; font-weight: 700; color: var(--gray-900); }

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 16px 16px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  color: var(--gray-600);
  font-size: 13.5px;
  font-weight: 500;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: all .15s;
  text-decoration: none;
}

.nav-item:hover { background: var(--gray-50); color: var(--gray-900); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-item-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.nav-item-text { flex: 1; min-width: 0; }
.nav-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: .45;
  transition: transform .2s;
}
.nav-group { display: flex; flex-direction: column; }
.nav-group.expanded .nav-chevron { transform: rotate(90deg); }
.nav-item-parent { padding-right: 12px; }
.nav-submenu {
  display: none;
  flex-direction: column;
  padding: 2px 0 6px 8px;
}
.nav-group.expanded .nav-submenu { display: flex; }
.nav-subitem {
  display: block;
  width: 100%;
  padding: 7px 12px 7px 36px;
  border: none;
  background: none;
  text-align: left;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 8px;
  transition: all .15s;
  font-family: inherit;
}
.nav-subitem:hover { background: var(--gray-50); color: var(--gray-800); }
.nav-subitem.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--gray-100);
}

.credit-box {
  background: var(--gray-50);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.credit-label { font-size: 11px; color: var(--gray-500); margin-bottom: 4px; }
.credit-value { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.credit-sub { font-size: 11px; color: var(--gray-400); }
.credit-bar-bg { background: var(--gray-200); border-radius: 4px; height: 4px; margin-top: 8px; }
.credit-bar-fill { background: var(--primary); height: 4px; border-radius: 4px; transition: width .4s; }

.user-row { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 12.5px; font-weight: 600; color: var(--gray-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 11px; color: var(--gray-400); }

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.topbar-title { font-size: 16px; font-weight: 700; color: var(--gray-900); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.inner-page { display: none; }
.inner-page.active { display: block; }

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  text-decoration: none;
  line-height: 1;
  font-family: inherit;
}

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-xs { padding: 3px 8px; font-size: 12px; }
.btn-solid, .btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-solid:hover, .btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline, .btn { background: white; color: var(--gray-700); border-color: var(--gray-300); }
.btn-outline:hover, .btn:hover { background: var(--gray-50); }
.btn-danger { background: white; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: var(--danger-light); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ==================== CARDS ==================== */
.card {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  padding: 0;
  margin-bottom: 16px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-900);
}

.card-body { padding: 20px; }

/* ==================== STAT CARDS ==================== */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  padding: 20px;
}
.stat-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; margin-bottom: 12px;
}
.stat-label { font-size: 12px; color: var(--gray-500); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--gray-900); line-height: 1; }
.stat-change { font-size: 11.5px; margin-top: 4px; }
.stat-change.pos { color: var(--success); }
.stat-change.neutral { color: var(--gray-500); }

.quick-actions { display: flex; gap: 12px; margin-bottom: 24px; }
.quick-card {
  position: relative;
  flex: 1;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all .2s;
  text-align: left;
}
.quick-card:hover { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91,71,224,.08); }
.quick-card-icon { font-size: 24px; margin-bottom: 10px; }
.quick-card-title { font-size: 14px; font-weight: 700; color: var(--gray-900); margin-bottom: 4px; }
.quick-card-desc { font-size: 12px; color: var(--gray-500); }

/* ==================== FORMS ==================== */
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.hint { font-weight: 400; color: var(--gray-400); font-size: 11px; text-transform: none; letter-spacing: 0; }

/* ==================== TIP TRIGGER ==================== */
.tip-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--gray-300);
  border-radius: 50%;
  background: var(--gray-50);
  color: var(--gray-400);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  font-family: inherit;
  transition: all .15s;
  vertical-align: middle;
}
.tip-trigger:hover,
.tip-trigger.active {
  background: var(--primary-light);
  border-color: rgba(91, 71, 224, .45);
  color: var(--primary);
}
.tip-trigger-card {
  position: absolute;
  top: 12px;
  right: 12px;
}
.tip-trigger-inline {
  margin-left: 6px;
}
.page-header-title-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.page-header--center {
  text-align: center;
  margin-bottom: 36px;
}
.page-header--center .page-header-title-row {
  justify-content: center;
}
.field-label-with-tip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.label-with-tip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.card-title-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tip-popover {
  position: fixed;
  z-index: 10001;
  max-width: 360px;
  padding: 10px 14px;
  background: var(--gray-800);
  color: #f9fafb;
  font-size: 12.5px;
  line-height: 1.6;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  white-space: pre-wrap;
  word-break: break-word;
}
.tip-popover.hidden { display: none !important; }

.field { flex: 1; min-width: 160px; margin-bottom: 16px; }
.field.grow { flex: 2; min-width: 220px; }
.field-row { display: flex; gap: 16px; flex-wrap: wrap; }
.field-row.align-center { align-items: center; }

.input-text,
.input-area,
select.input-text {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border .2s;
  color: var(--gray-800);
  background: white;
}

.input-text:focus,
.input-area:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,71,224,.1);
}

.input-area {
  resize: vertical;
  min-height: 140px;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.45;
}

.input-text.narrow { max-width: 120px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ==================== MODE SWITCH ==================== */
.mode-switch {
  display: flex;
  gap: 0;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}

.mode-btn {
  flex: 1;
  padding: 10px 0;
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  background: none;
  border: none;
  transition: all .2s;
  font-family: inherit;
}

.mode-btn.active { background: var(--primary); color: white; }
.mode-btn:hover:not(.active) { background: var(--gray-50); }

.mode-block.hidden { display: none !important; }
.hidden { display: none !important; }

/* ==================== MODE NAV ==================== */
#taskModeNav {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--topbar-h) - 80px);
  padding: 8px 0 48px;
}
.mode-nav-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 300px));
  gap: 20px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  justify-content: center;
}
.mode-nav-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  text-align: center;
  background: white;
  border: 1.5px solid var(--gray-200);
  border-radius: 16px;
  padding: 32px 24px 28px;
  cursor: pointer;
  transition: all .22s ease;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
}
.mode-nav-card:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 24px rgba(91, 71, 224, .12);
  transform: translateY(-3px);
}
.mode-nav-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--primary-light), #f5f3ff);
  border-radius: 14px;
}
.mode-nav-title { font-size: 16px; font-weight: 700; color: var(--gray-900); margin-bottom: 8px; }
.mode-nav-desc { font-size: 13px; color: var(--gray-500); line-height: 1.55; max-width: 240px; }
.m2-kw-only.hidden,
.m2-all-only.hidden { display: none !important; }
#taskConfigPanel.hidden { display: none !important; }
#taskModeNav.hidden { display: none !important; }

@media (max-width: 720px) {
  .mode-nav-grid { grid-template-columns: 1fr; }
}

/* ==================== PILLS ==================== */
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.pill {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--gray-200);
  background: var(--gray-50);
  color: var(--gray-600);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}

.pill:hover { border-color: var(--gray-300); }
.pill.active { background: var(--primary-light); color: var(--primary); border-color: rgba(91,71,224,.35); }
.pill-accent.active { background: var(--success-light); color: var(--success); border-color: rgba(16,185,129,.35); }

.sort-panel.hidden { display: none !important; }

/* ==================== GROUP ROWS ==================== */
.group-rows { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.group-row.field-row { align-items: flex-end; }
.group-row-actions { flex: 0 0 auto; display: flex; align-items: flex-end; padding-bottom: 2px; }
.group-row-spacer { display: inline-block; width: 42px; height: 1px; }
.add-group-btn { margin-top: 10px; font-size: 1.35rem; font-weight: 600; padding: 6px 18px; line-height: 1; }
.field-guide > summary::-webkit-details-marker { display: none; }
.field-guide[open] > summary .small { opacity: .7; }
.group-remove { min-width: 42px; padding: 10px 12px; }

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--gray-700);
  cursor: pointer;
}

.check-row input { width: 18px; height: 18px; accent-color: var(--primary); }
.check-row.big { font-weight: 500; }

/* ==================== TASK CONTROL ==================== */
.control-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--gray-100);
  color: var(--gray-500);
}

.status-pill.running { background: var(--running-light); color: var(--running); }
.status-pill.paused { background: var(--warning-light); color: var(--warning); }
.status-pill.finished { background: var(--success-light); color: #059669; }

.mono { font-family: var(--mono); }
.small { font-size: 12px; color: var(--gray-500); }
.muted { color: var(--gray-400); }

/* ==================== TABS ==================== */
.subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--gray-200);
  padding-bottom: 2px;
}

.subtab {
  padding: 10px 14px;
  border: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--gray-500);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, background .15s;
}

.subtab:hover { color: var(--gray-700); }
.subtab.active { color: var(--primary); background: var(--primary-light); }

.tab-body { min-height: 120px; }
.tab-body.hidden { display: none !important; }

/* ==================== PROGRESS ==================== */
.progress-panel-wrap { position: relative; min-height: 72px; }

.progress-dl-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--gray-100);
}

.progress-mount ul { margin: 0; padding-left: 18px; color: var(--gray-600); font-size: 13px; }
.progress-mount li { margin: 4px 0; }
.progress-mount strong { color: var(--gray-800); }

.progress-bar-wrap,
.progress-bg {
  height: 8px;
  background: var(--gray-200);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 10px;
}

.progress-bar-fill,
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  border-radius: 99px;
  transition: width .3s ease;
}

.progress-fill.success { background: var(--success); }
.progress-fill.danger { background: var(--danger); }

.progress-wrap { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.progress-text { font-size: 11.5px; color: var(--gray-500); min-width: 32px; text-align: right; }

/* ==================== BADGES ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.badge-running { background: var(--running-light); color: var(--running); }
.badge-success { background: var(--success-light); color: #059669; }
.badge-failed { background: var(--danger-light); color: #dc2626; }
.badge-pending { background: var(--gray-100); color: var(--gray-500); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.badge-running .badge-dot { background: var(--running); animation: pulse 1.5s ease-in-out infinite; }
.badge-success .badge-dot { background: #059669; }
.badge-failed .badge-dot { background: #dc2626; }
.badge-pending .badge-dot { background: var(--gray-400); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.8); }
}

/* ==================== LOGS ==================== */
.log-pre {
  margin: 0;
  padding: 14px;
  max-height: 320px;
  overflow: auto;
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--gray-600);
}

.fail-pre { background: var(--danger-light); border-color: #fca5a5; color: #991b1b; }

/* ==================== TABLES ==================== */
.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  font-family: var(--mono);
}

table.data th,
table.data td {
  border: 1px solid var(--gray-200);
  padding: 6px 8px;
  text-align: left;
}

table.data th {
  background: var(--gray-50);
  color: var(--gray-500);
  position: sticky;
  top: 0;
  z-index: 1;
  font-weight: 600;
}

table.data td { color: var(--gray-700); background: white; }

table.data.preview-data {
  table-layout: auto;
  width: max-content;
  min-width: 100%;
  max-width: none;
}

table.data.preview-data td.preview-cell {
  max-width: 18rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

table.data.preview-data td.preview-cell:hover { background: rgba(91,71,224,.06); }

.table-scroll {
  margin-top: 12px;
  max-height: 420px;
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  background: white;
}

.table-scroll.short { max-height: 280px; }

.hist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
}

.hist-row:last-child { border-bottom: none; }
.hist-meta { color: var(--gray-400); font-size: 11px; }
.hist-search-row { margin: 8px 0 10px; }
.hist-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ==================== TASK TABLE ==================== */
.task-table { width: 100%; border-collapse: collapse; }
.task-table thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
  white-space: nowrap;
}
.task-table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13.5px;
  color: var(--gray-700);
  vertical-align: middle;
}
.task-table tbody tr:last-child td { border-bottom: none; }
.task-table tbody tr:hover td { background: var(--gray-50); }
.task-table .empty-cell { text-align: center; padding: 32px 16px; }

.task-filter-select {
  width: auto;
  padding: 4px 28px 4px 8px;
  font-size: 12.5px;
  min-width: 120px;
}

.task-actions-cell {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.preview-panel.hidden { display: none !important; }

/* ==================== ESTIMATE PANEL ==================== */
.estimate-sticky { position: sticky; top: 0; }

.estimate-highlight {
  background: linear-gradient(135deg, #f0edff 0%, #e8f4ff 100%);
  border: 1px solid #d6d0ff;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
}

.estimate-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 12px;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  margin: 2px;
}

/* ==================== BILLING ==================== */
.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }

.plan-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all .2s;
  position: relative;
}

.plan-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.plan-card.popular { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(91,71,224,.2); }

.plan-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}

.plan-name { font-size: 16px; font-weight: 700; color: var(--gray-900); margin-bottom: 6px; }
.plan-desc { font-size: 12.5px; color: var(--gray-500); margin-bottom: 20px; }
.plan-price { font-size: 36px; font-weight: 800; color: var(--gray-900); line-height: 1; margin-bottom: 4px; }
.plan-price-period { font-size: 13px; color: var(--gray-500); margin-bottom: 20px; }
.plan-features { list-style: none; margin-bottom: 20px; }
.plan-features li { font-size: 13px; color: var(--gray-600); padding: 5px 0; display: flex; align-items: center; gap: 7px; }
.plan-features li::before { content: "✓"; color: var(--success); font-weight: 700; font-size: 12px; }

.plan-buy-btn {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .2s;
  font-family: inherit;
}

.plan-buy-btn.primary { background: var(--primary); color: white; }
.plan-buy-btn.primary:hover { background: var(--primary-hover); }
.plan-buy-btn.outline { background: white; color: var(--primary); border: 1.5px solid var(--primary); }
.plan-buy-btn.outline:hover { background: var(--primary-light); }
.plan-buy-btn:disabled,
.plan-buy-btn:disabled:hover {
  background: var(--gray-100);
  color: var(--gray-400);
  border-color: var(--gray-200);
  cursor: not-allowed;
  opacity: 1;
}

.billing-notice {
  border: 1px solid #fde68a;
  background: #fffbeb;
}

/* ==================== TASK LOG MODAL ==================== */
.task-log-modal__panel {
  width: min(92vw, 520px);
  max-height: min(82vh, 640px);
}
.task-log-modal__meta {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--gray-500);
  border-bottom: 1px solid var(--gray-100);
}
.task-log-modal__body {
  padding: 12px 16px 18px;
  overflow: auto;
  flex: 1;
  min-height: 180px;
}

/* ==================== PENDING TASK MODAL ==================== */
.pending-task-modal__panel {
  width: min(92vw, 520px);
}
.pending-task-modal__body {
  padding: 16px 20px 8px;
}
.pending-task-modal__lead {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--gray-700);
  margin: 0 0 12px;
}
.pending-task-modal__list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}
.pending-task-modal__list li {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
  line-height: 1.55;
  cursor: pointer;
}
.pending-task-modal__list li:last-child { border-bottom: none; }
.pending-task-modal__list li.is-selected {
  background: color-mix(in srgb, var(--primary) 8%, white);
}
.pending-task-modal__hint {
  font-size: 12px;
  color: var(--gray-500);
  margin: 10px 0 0;
  min-height: 1.4em;
}
.pending-task-modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 20px 18px;
}
.task-log-step {
  display: flex;
  gap: 12px;
  position: relative;
  padding-bottom: 14px;
}
.task-log-step:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 14px;
  bottom: 0;
  width: 2px;
  background: var(--gray-200);
}
.task-log-step__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gray-300);
  margin-top: 3px;
  flex-shrink: 0;
  z-index: 1;
}
.task-log-step.is-latest .task-log-step__dot {
  background: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 71, 224, 0.18);
}
.task-log-step__text {
  font-size: 13.5px;
  color: var(--gray-800);
  line-height: 1.5;
  font-weight: 500;
}
.task-log-step.is-latest .task-log-step__text {
  color: var(--primary);
}
.task-log-step__ts {
  font-size: 11.5px;
  color: var(--gray-400);
  margin-top: 2px;
}

.billing-banner {
  background: linear-gradient(135deg, #5b47e0, #8b5cf6);
  border: none;
  color: white;
  margin-bottom: 24px;
}

/* ==================== PAGE HEADER ==================== */
.page-header { margin-bottom: 20px; }
.page-header-title { font-size: 20px; font-weight: 700; color: var(--gray-900); }
.page-header-desc { font-size: 13.5px; color: var(--gray-500); margin-top: 4px; }

.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.empty-state { text-align: center; padding: 48px 20px; color: var(--gray-400); }
.empty-state-icon { font-size: 36px; margin-bottom: 12px; opacity: .6; }

.coming-soon-banner {
  background: var(--warning-light);
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: #92400e;
  margin-bottom: 16px;
}

/* ==================== MODAL ==================== */
.preview-cell-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.preview-cell-modal.hidden { display: none !important; }

.preview-cell-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
  cursor: pointer;
}

.preview-cell-modal__panel {
  position: relative;
  z-index: 1;
  width: min(92vw, 720px);
  max-height: min(82vh, 640px);
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.preview-cell-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  font-weight: 600;
}

.preview-cell-modal__close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-500);
}

.preview-cell-modal__body {
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ==================== 模式示例弹窗 ==================== */
.mode-example-modal__panel {
  width: min(96vw, 980px);
  max-height: min(90vh, 760px);
}

.mode-example-modal__body {
  flex: 1;
  overflow: auto;
  padding: 16px 18px;
}

.mode-example-modal__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 800px) {
  .mode-example-modal__grid { grid-template-columns: 1fr; }
}

.mode-example-pane {
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--gray-50);
  padding: 12px;
  min-height: 0;
}

.mode-example-pane__caption {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 10px;
}

.mode-example-pane__img-wrap {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}

.mode-example-pane__img-wrap img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: contain;
  background: #fff;
}

.mode-example-modal__note {
  margin: 14px 0 0;
  padding: 0;
  font-size: 13px;
  color: var(--gray-700);
  line-height: 1.6;
  white-space: pre-wrap;
  background: none;
  border: none;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: white;
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  max-width: 440px;
  width: 90%;
  text-align: center;
}

.modal-icon { font-size: 48px; margin-bottom: 16px; }
.modal-title { font-size: 20px; font-weight: 700; color: var(--gray-900); margin-bottom: 8px; }
.modal-desc { font-size: 14px; color: var(--gray-500); margin-bottom: 24px; line-height: 1.6; }
.modal-btn {
  padding: 11px 32px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

/* ==================== TOAST ==================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--gray-900);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: all;
  min-width: 280px;
  animation: toastIn .25s ease;
}

.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ==================== LOGIN ==================== */
.page-login {
  min-height: 100vh;
  height: 100vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0edff 0%, #e8f4ff 100%);
}

.login-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 400px;
  max-width: 95vw;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  font-weight: 700;
}

.login-logo-name { font-size: 20px; font-weight: 700; color: var(--gray-900); }

.login-logo-badge {
  font-size: 10px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.login-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 28px;
}
.login-title { font-size: 22px; font-weight: 700; color: var(--gray-900); margin-bottom: 0; }
.login-sub { color: var(--gray-500); margin-bottom: 28px; font-size: 13px; }

.btn-primary {
  width: 100%;
  padding: 11px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
  font-family: inherit;
}

.btn-primary:hover { background: var(--primary-hover); }

.alert-error {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--danger-light);
  border: 1px solid #fca5a5;
  color: #991b1b;
  font-size: 13px;
  margin-bottom: 16px;
}

.login-footer { text-align: center; margin-top: 20px; font-size: 12px; color: var(--gray-400); }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .plan-grid { grid-template-columns: 1fr; }
  .quick-actions { flex-direction: column; }
  .task-layout { grid-template-columns: 1fr !important; }
}

@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
  }
  .sidebar-footer { display: none; }
  .sidebar-section-label { display: none; }
  .nav-item { flex: 1; justify-content: center; padding: 10px 8px; font-size: 12px; }
  body { overflow: auto; height: auto; }
  .main-area { height: auto; min-height: calc(100vh - 120px); }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
