@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap");
@import url("../brand/tokens.css");
@import url("trust.css");
@import url("polish.css");

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body.dashboard-app {
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-bg);
  background-image:
    radial-gradient(ellipse 60% 40% at 90% 0%, rgba(0, 194, 255, 0.06) 0%, transparent 55%),
    radial-gradient(ellipse 40% 30% at 0% 50%, rgba(77, 227, 255, 0.03) 0%, transparent 50%);
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
  position: relative;
}

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(0, 194, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 194, 255, 0.02) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 30%, black 15%, transparent 80%);
}

a { color: inherit; text-decoration: none; }

.mono { font-family: var(--font-mono); font-size: var(--text-body-sm); }

/* ─── Sidebar ─── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: rgba(7, 17, 31, 0.95);
  border-right: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  line-height: 0;
  padding: var(--space-3) var(--space-2) var(--space-5);
  margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.sidebar-logo img {
  height: 34px;
  width: auto;
  display: block;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-body-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  border-radius: var(--radius-md);
  transition: background 150ms ease, color 150ms ease;
}

.sidebar-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text);
}

.sidebar-item.active {
  background: var(--color-info-muted);
  color: var(--color-primary);
  border-left: 2px solid var(--color-primary);
  margin-left: -2px;
  padding-left: calc(var(--space-3) + 2px);
}

.sidebar-item.active svg { opacity: 1; color: var(--color-primary); }

/* ─── Shell ─── */
.dashboard-shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  z-index: 1;
}

/* ─── Topbar ─── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: 56px;
  padding: 0 var(--space-5);
  background: rgba(7, 17, 31, 0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--color-border);
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-toggle svg { width: 18px; height: 18px; }

.topbar-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  max-width: 420px;
  height: 36px;
  padding: 0 var(--space-3);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.topbar-search:focus-within {
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-glow);
}

.topbar-search svg {
  width: 16px;
  height: 16px;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
}

.topbar-search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: var(--text-body-sm);
  color: var(--color-text);
}

.topbar-search input::placeholder { color: var(--color-text-tertiary); }

.topbar-kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-text-tertiary);
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-3);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: var(--text-body-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
  position: relative;
}

.topbar-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

.topbar-btn svg { width: 16px; height: 16px; }

.topbar-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
  background: var(--color-primary);
  color: #07111F;
  border-radius: var(--radius-full);
}

.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-2) 0 var(--space-1);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: var(--text-body-sm);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: border-color 150ms ease;
}

.topbar-user:hover { border-color: var(--color-border-strong); }

.topbar-user svg { width: 14px; height: 14px; color: var(--color-text-tertiary); }

.topbar-avatar {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  background: var(--color-info-muted);
  color: var(--color-primary);
  border-radius: var(--radius-md);
}

.topbar-user-name { font-weight: 500; padding-right: var(--space-1); }

/* ─── Body Layout ─── */
.dashboard-body {
  display: grid;
  grid-template-columns: 1fr 272px;
  gap: var(--space-5);
  padding: var(--space-5) var(--space-5);
  align-items: start;
}

.dashboard-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  min-width: 0;
}

.dash-row { min-width: 0; }

.dash-row--split {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--space-5);
}

/* ─── Cards ─── */
.dash-card {
  background: linear-gradient(165deg, rgba(19, 40, 69, 0.5) 0%, rgba(14, 30, 54, 0.85) 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  min-width: 0;
  transition: border-color 150ms ease;
}

.dash-card--chart { padding-bottom: var(--space-4); }

.dash-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.dash-card-title {
  font-size: var(--text-h4);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.dash-card-sub {
  font-size: var(--text-caption);
  color: var(--color-text-tertiary);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.dash-card-link {
  font-size: var(--text-body-sm);
  color: var(--color-primary);
  font-weight: 500;
  white-space: nowrap;
}

.dash-card-link:hover { text-decoration: underline; }

/* ─── KPI Cards ─── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-5);
}

.kpi-card {
  background: linear-gradient(165deg, rgba(19, 40, 69, 0.45) 0%, rgba(14, 30, 54, 0.8) 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.kpi-card:hover {
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-glow);
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}

.kpi-label {
  font-size: var(--text-caption);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-tertiary);
  opacity: 0.85;
}

.kpi-icon {
  width: 15px;
  height: 15px;
  color: var(--color-text-tertiary);
  opacity: 0.45;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--color-text);
  margin-bottom: var(--space-4);
}

.kpi-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-3);
  padding-top: var(--space-1);
}

.kpi-trend {
  font-size: var(--text-caption);
  font-weight: 500;
  opacity: 0.9;
}

.kpi-trend--up { color: var(--color-success); }
.kpi-trend--down { color: var(--color-warning); }
.kpi-trend--neutral { color: var(--color-text-tertiary); }

.kpi-sparkline {
  width: 72px;
  height: 24px;
  flex-shrink: 0;
  opacity: 0.65;
}

/* ─── Chart ─── */
.chart-tabs {
  display: flex;
  gap: 2px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
  padding: 2px;
}

.chart-tab {
  padding: 4px 12px;
  font-size: var(--text-caption);
  font-weight: 600;
  font-family: var(--font-sans);
  color: var(--color-text-tertiary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.chart-tab:hover { color: var(--color-text-secondary); }

.chart-tab.active {
  background: var(--color-info-muted);
  color: var(--color-primary);
}

.market-chart {
  height: 200px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.03);
  overflow: hidden;
  margin-bottom: var(--space-2);
}

.market-chart svg { width: 100%; height: 100%; display: block; }

.chart-axis {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-text-tertiary);
  padding: 0 var(--space-1);
}

/* ─── Tables ─── */
.dash-table {
  width: 100%;
  border-collapse: collapse;
}

.dash-table th {
  text-align: left;
  font-size: var(--text-caption);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.dash-table td {
  font-size: var(--text-body-sm);
  padding: 11px var(--space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  white-space: nowrap;
  line-height: 1.4;
}

.dash-table tbody tr:last-child td { border-bottom: none; }

.token-cell {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.score-pass { color: var(--color-success); }
.score-warn { color: var(--color-warning); }

/* ─── Badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 var(--space-2);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: var(--radius-sm);
}

.badge-success { background: var(--color-success-muted); color: var(--color-success); }
.badge-primary { background: var(--color-info-muted); color: var(--color-primary); }
.badge-danger { background: var(--color-danger-muted); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-muted); color: var(--color-warning); }

.pulse-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
  animation: pulse 2s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ─── Risk Overview ─── */
.risk-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.risk-stat {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  text-align: center;
}

.risk-stat-label {
  display: block;
  font-size: var(--text-caption);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-tertiary);
  margin-bottom: 4px;
}

.risk-stat-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 600;
}

.risk-stat-value--pass { color: var(--color-success); }
.risk-stat-value--warn { color: var(--color-warning); }

.risk-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.risk-list-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
}

.risk-list-item--danger { border-color: rgba(239, 68, 68, 0.15); }
.risk-list-item--warn { border-color: rgba(245, 158, 11, 0.12); }

.risk-list-token {
  font-weight: 600;
  font-size: var(--text-body-sm);
}

.risk-list-reason {
  font-size: var(--text-caption);
  color: var(--color-text-secondary);
}

/* ─── Activity Tabs ─── */
.activity-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.activity-tab {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-body-sm);
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--color-text-secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.activity-tab:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.03);
}

.activity-tab.active {
  color: var(--color-primary);
  background: var(--color-info-muted);
  border-color: rgba(0, 194, 255, 0.2);
}

/* ─── Intelligence Panel ─── */
.intel-panel {
  position: sticky;
  top: calc(56px + var(--space-4));
  max-height: calc(100vh - 56px - var(--space-8));
  overflow-y: auto;
}

.intel-panel-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.intel-block {
  background: linear-gradient(165deg, rgba(19, 40, 69, 0.5) 0%, rgba(14, 30, 54, 0.85) 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  transition: border-color 150ms ease;
}

.intel-block--neutral {
  border-color: var(--color-border);
}

.intel-block--engine {
  border-color: rgba(0, 194, 255, 0.2);
  background: linear-gradient(165deg, rgba(0, 194, 255, 0.05) 0%, rgba(14, 30, 54, 0.85) 100%);
  box-shadow: 0 0 16px rgba(0, 194, 255, 0.06);
}

.intel-block--highlight {
  border-color: rgba(34, 197, 94, 0.3);
  background: linear-gradient(165deg, rgba(34, 197, 94, 0.07) 0%, rgba(14, 30, 54, 0.88) 100%);
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.1);
}

.intel-block--threat {
  border-color: rgba(239, 68, 68, 0.3);
  background: linear-gradient(165deg, rgba(239, 68, 68, 0.06) 0%, rgba(14, 30, 54, 0.88) 100%);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.08);
}

.intel-block--health {
  padding: var(--space-4) var(--space-5);
  border-color: rgba(255, 255, 255, 0.08);
  background: linear-gradient(165deg, rgba(19, 40, 69, 0.35) 0%, rgba(14, 30, 54, 0.75) 100%);
}

.intel-block--health .intel-title {
  margin-bottom: var(--space-2);
}

.intel-block--health .health-list {
  gap: 6px;
}

.intel-block--health .health-item {
  font-size: var(--text-caption);
}

.intel-title {
  font-size: var(--text-caption);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-3);
}

.intel-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-body-sm);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.intel-status svg { width: 16px; height: 16px; }

.intel-status--live { color: var(--color-success); }
.intel-status--pass { color: var(--color-primary); }

.intel-detail {
  font-size: var(--text-caption);
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.intel-opportunity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.intel-token {
  font-size: var(--text-h3);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.intel-dl {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.intel-dl div {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.intel-dl dt {
  font-size: var(--text-caption);
  color: var(--color-text-tertiary);
}

.intel-dl dd { font-weight: 600; }

.health-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.health-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-body-sm);
  color: var(--color-text-secondary);
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
}

.health-dot--ok { background: var(--color-success); box-shadow: 0 0 6px rgba(34, 197, 94, 0.4); }
.health-dot--warn { background: var(--color-warning); box-shadow: 0 0 6px rgba(245, 158, 11, 0.4); }

/* ─── Responsive ─── */
@media (max-width: 1280px) {
  .dashboard-body {
    grid-template-columns: 1fr;
  }

  .intel-panel {
    position: static;
    max-height: none;
  }

  .intel-panel-inner {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}

@media (max-width: 1024px) {
  body.dashboard-app {
    grid-template-columns: 1fr;
  }

  .sidebar-toggle { display: inline-flex; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 232px;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { transform: translateX(0); }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-row--split { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .topbar { padding: 0 var(--space-3); }
  .topbar-btn-label { display: none; }
  .topbar-user-name { display: none; }
  .topbar-kbd { display: none; }
  .dashboard-body { padding: var(--space-3); }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.5rem; }
  .chart-tabs { flex-wrap: wrap; }
  .intel-panel-inner { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .dash-card-header { flex-direction: column; align-items: flex-start; }
  .risk-stats { grid-template-columns: 1fr; }
}
