/* ==========================================================================
   AI Agent Dashboard — design tokens & layout
   ========================================================================== */

:root {
  --sidebar-width: 250px;
  --topbar-height: 60px;

  --color-page-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-border: #e4e6eb;
  --color-border-strong: #d7dae0;

  --color-sidebar-bg: #12182b;
  --color-sidebar-bg-active: #1c2440;
  --color-sidebar-text: #a6adc4;
  --color-sidebar-text-muted: #6b7290;
  --color-sidebar-text-active: #ffffff;
  --color-sidebar-border: #232a44;

  --color-accent: #2a78d6;
  --color-accent-dark: #1c5cab;
  --color-accent-soft: #eaf2fc;

  --color-text-primary: #0b0e14;
  --color-text-secondary: #52565f;
  --color-text-muted: #898781;

  --status-good: #0ca30c;
  --status-good-soft: #e7f7e7;
  --status-warning: #b9790a;
  --status-warning-soft: #fdf1da;
  --status-serious: #c1552f;
  --status-serious-soft: #fbe9e2;
  --status-critical: #d03b3b;
  --status-critical-soft: #fbe6e6;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;

  --shadow-sm: 0 1px 2px rgba(11, 14, 20, 0.06);
  --shadow-md: 0 4px 14px rgba(11, 14, 20, 0.08);

  --radius-md: 10px;
  --radius-lg: 14px;
}

html, body {
  height: 100%;
}

body {
  background-color: var(--color-page-bg);
  color: var(--color-text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.9rem;
}

a {
  text-decoration: none;
}

/* ---------------------------------------------------------------- Shell */

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

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1040;
  transition: transform 0.2s ease;
}

.app-sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-sidebar-border);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
}

.app-sidebar .brand .brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--color-accent), #1c3f8f);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
}

.app-sidebar .nav-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.6rem;
}

.app-sidebar .nav-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-sidebar-text-muted);
  padding: 0.9rem 0.75rem 0.35rem;
}

.app-sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--color-sidebar-text);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.87rem;
  font-weight: 500;
  margin-bottom: 2px;
}

.app-sidebar .nav-link i {
  font-size: 1rem;
  width: 1.1rem;
  text-align: center;
  flex-shrink: 0;
}

.app-sidebar .nav-link:hover {
  background: var(--color-sidebar-bg-active);
  color: #fff;
}

.app-sidebar .nav-link.active {
  background: var(--color-sidebar-bg-active);
  color: var(--color-sidebar-text-active);
  box-shadow: inset 3px 0 0 var(--color-accent);
}

.app-sidebar .nav-link .badge-count {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
}

.app-sidebar .sidebar-footer {
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--color-sidebar-border);
  font-size: 0.75rem;
  color: var(--color-sidebar-text-muted);
}

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.app-topbar .sidebar-toggle {
  display: none;
  border: none;
  background: transparent;
  font-size: 1.3rem;
  color: var(--color-text-secondary);
}

.app-topbar .topbar-search {
  flex: 1;
  max-width: 420px;
  position: relative;
}

.app-topbar .topbar-search input {
  width: 100%;
  border: 1px solid var(--color-border-strong);
  background: var(--color-page-bg);
  border-radius: 8px;
  padding: 0.45rem 0.75rem 0.45rem 2.1rem;
  font-size: 0.85rem;
}

.app-topbar .topbar-search i {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
}

.app-topbar .topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
}

.system-status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: var(--status-good-soft);
  color: var(--status-good);
  white-space: nowrap;
}

.system-status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-good);
  box-shadow: 0 0 0 3px rgba(12, 163, 12, 0.15);
}

.icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

.icon-btn:hover {
  background: var(--color-page-bg);
}

.icon-btn .dot-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status-critical);
  border: 2px solid var(--color-surface);
}

.app-content {
  padding: 1.5rem;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.page-header .page-subtitle {
  color: var(--color-text-secondary);
  font-size: 0.85rem;
}

/* ---------------------------------------------------------------- Cards */

.card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  box-shadow: var(--shadow-sm);
  height: 100%;
}

.stat-card .stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
}

.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--color-text-secondary);
}

/* ---------------------------------------------------------------- Badges */

.badge-status-pending { background: #eef0f4; color: #52565f; }
.badge-status-running { background: var(--color-accent-soft); color: var(--color-accent-dark); }
.badge-status-completed { background: var(--status-good-soft); color: var(--status-good); }
.badge-status-failed { background: var(--status-critical-soft); color: var(--status-critical); }

.badge-soft {
  font-weight: 600;
  font-size: 0.72rem;
  padding: 0.32rem 0.55rem;
  border-radius: 6px;
}

.badge-rec-buy { background: var(--status-good-soft); color: var(--status-good); }
.badge-rec-hold { background: var(--status-warning-soft); color: var(--status-warning); }
.badge-rec-sell { background: var(--status-critical-soft); color: var(--status-critical); }

.badge-score-high { background: var(--status-good-soft); color: var(--status-good); }
.badge-score-medium { background: var(--status-warning-soft); color: var(--status-warning); }
.badge-score-low { background: #eef0f4; color: #52565f; }

.health-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.health-dot.good { background: var(--status-good); }
.health-dot.warning { background: var(--status-warning); }
.health-dot.critical { background: var(--status-critical); }

/* ---------------------------------------------------------------- Misc components */

.section-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.section-card .section-card-header {
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.section-card .section-card-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
}

.section-card .section-card-body {
  padding: 1.1rem;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--color-border);
}
.list-row:last-child { border-bottom: none; }

.avatar-sq {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--color-accent-soft);
  color: var(--color-accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.sparkline-up { color: var(--status-good); }
.sparkline-down { color: var(--status-critical); }

.symbol-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--color-border-strong);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--color-text-primary);
}
.symbol-chip.active {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent-dark);
}

.nav-tabs .nav-link {
  color: var(--color-text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
}
.nav-tabs .nav-link.active {
  color: var(--color-accent-dark);
  border-bottom: 2px solid var(--color-accent);
}

.table > :not(caption) > * > * {
  font-size: 0.85rem;
  vertical-align: middle;
}

.text-mono {
  font-variant-numeric: tabular-nums;
}

.timeline-item {
  display: flex;
  gap: 0.85rem;
  position: relative;
  padding-bottom: 1.25rem;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item .timeline-marker {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-accent);
  margin-top: 5px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.timeline-item:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 14px;
  bottom: -6px;
  width: 2px;
  background: var(--color-border);
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--color-text-secondary);
}
.empty-state i {
  font-size: 2rem;
  color: var(--color-text-muted);
  margin-bottom: 0.6rem;
  display: block;
}

/* ---------------------------------------------------------------- Backdrop for mobile sidebar */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 14, 20, 0.45);
  z-index: 1030;
}

/* ---------------------------------------------------------------- Responsive */

@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.show {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
  }
  .app-topbar .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .sidebar-backdrop.show {
    display: block;
  }
  .app-topbar .topbar-search {
    display: none;
  }
}

@media (max-width: 575.98px) {
  .app-content {
    padding: 1rem 0.75rem;
  }
  .app-topbar {
    padding: 0 0.75rem;
  }
}

/* ---------------------------------------------------------------- Language switch */

.lang-btn {
  width: auto !important;
  padding: 0 0.55rem;
  gap: 0.3rem;
  display: inline-flex;
  align-items: center;
}
.lang-btn .lang-label { font-size: 0.78rem; font-weight: 600; }
.lang-float { position: absolute; top: 1rem; right: 1rem; }
.lang-float a { color: #a6adc4; font-size: 0.85rem; margin-left: 0.75rem; }
.lang-float a.active { color: #fff; font-weight: 600; }

/* ---------------------------------------------------------------- Strategy pages */

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}
.mode-1 { background: #e7f7e7; color: #0a7f0a; }
.mode-2 { background: #eaf2fc; color: #1c5cab; }
.mode-3 { background: #fdf1da; color: #8a5a00; }
.mode-4 { background: #fbe9e2; color: #a2421f; }

.mode-card {
  border-left: 4px solid var(--color-border-strong);
}
.mode-card.m1 { border-left-color: #0ca30c; }
.mode-card.m2 { border-left-color: #2a78d6; }
.mode-card.m3 { border-left-color: #eda100; }
.mode-card.m4 { border-left-color: #eb6834; }

.score-bar {
  height: 6px;
  border-radius: 3px;
  background: #eef0f4;
  overflow: hidden;
  min-width: 60px;
}
.score-bar > span { display: block; height: 100%; background: var(--color-accent); }

.reason-list { margin: 0; padding-left: 1.1rem; font-size: 0.8rem; }
.reason-list li { margin-bottom: 0.15rem; }
.reason-list.warn li { color: var(--status-serious); }

.signal-row td { vertical-align: top; }
.signal-row .reason-list { color: var(--color-text-secondary); }

.kv { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.82rem; padding: 0.3rem 0; border-bottom: 1px dashed var(--color-border); }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--color-text-muted); }
.kv .v { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 600; text-align: right; }

.chart-box { width: 100%; height: 460px; }
.chart-box.sm { height: 360px; }

.verdict { border-radius: var(--radius-md); padding: 0.75rem 0.9rem; border: 1px solid var(--color-border); }
.verdict.buy { background: var(--status-good-soft); border-color: #bfe6bf; }
.verdict.watch { background: var(--status-warning-soft); border-color: #f1dcaf; }
.verdict.avoid { background: var(--status-critical-soft); border-color: #f1c4c4; }

.log-box {
  background: #0f1424;
  color: #c8cee0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem;
  max-height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.quote-up { color: var(--status-good); }
.quote-down { color: var(--status-critical); }
tr.row-warn { background: var(--status-critical-soft); }
