:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --sidebar-width: 240px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
}

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

.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
}

.sidebar-header { padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,.1); }
.logo { font-size: 18px; font-weight: 700; }
.subtitle { margin-top: 6px; font-size: 12px; opacity: .75; }

.nav { padding: 16px 12px; flex: 1; }
.nav-item {
  display: block;
  padding: 10px 14px;
  margin-bottom: 6px;
  border-radius: 8px;
  color: rgba(255,255,255,.85);
  text-decoration: none;
}
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.12); color: #fff; }

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.1); }

.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar h1 { font-size: 24px; margin-bottom: 4px; }
.muted { color: var(--gray-500); font-size: 13px; }

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
}

.toolbar label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--gray-500);
}

select {
  min-width: 120px;
  padding: 8px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background: #fff;
}

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  font-size: 14px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: rgba(255,255,255,.15); color: #fff; width: 100%; }

.section { display: none; }
.section.active { display: block; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card-label { font-size: 12px; color: var(--gray-500); margin-bottom: 8px; }
.card-value { font-size: 28px; font-weight: 700; line-height: 1.2; }
.card-sub { margin-top: 6px; font-size: 12px; color: var(--gray-500); }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.panel-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.chart { width: 100%; height: 320px; }
.chart-tall { height: 380px; }

.panel-desc {
  font-size: 13px;
  color: var(--gray-500);
  margin: -4px 0 14px;
}

.token-group {
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  margin-bottom: 16px;
  overflow: hidden;
}

.token-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(90deg, #eef2ff 0%, #f9fafb 100%);
  border-bottom: 1px solid var(--gray-200);
}

.token-group-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-dark);
}

.token-group-summary {
  font-size: 12px;
  color: var(--gray-500);
  text-align: right;
}

.token-group-summary strong {
  display: block;
  font-size: 18px;
  color: var(--gray-800);
  margin-bottom: 2px;
}

.token-group table { margin: 0; }
.token-group tbody tr:last-child td { border-bottom: none; }

.table-wrap.wide { overflow: auto; max-width: 100%; }

.collapsible summary {
  cursor: pointer;
  list-style: none;
  margin-bottom: 12px;
}

.collapsible summary::-webkit-details-marker { display: none; }

.pivot-table th.token-col,
.pivot-table td.token-col {
  text-align: right;
  min-width: 110px;
}

.pivot-table th.date-col,
.pivot-table td.date-col {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
}

.pivot-table thead th.date-col { background: var(--gray-50); }

.pivot-table tfoot td {
  font-weight: 700;
  background: #fafafa;
  border-top: 2px solid var(--gray-200);
}

.table-wrap { overflow: auto; }
.table-wrap.tall { max-height: 480px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); text-align: left; white-space: nowrap; }
th { color: var(--gray-500); font-weight: 600; background: var(--gray-50); position: sticky; top: 0; }
tbody tr:hover { background: #fafafa; }

.inline-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--gray-700);
}

.num { font-variant-numeric: tabular-nums; }

.table-link, .token-group-link, .btn-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.table-link:hover, .token-group-link:hover, .btn-link:hover {
  text-decoration: underline;
}

.token-group-link {
  display: inline-block;
  margin-left: 10px;
  font-size: 12px;
  font-weight: 600;
}

.prompt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
}

.prompt-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--gray-500);
}

.prompt-preview {
  max-width: 420px;
  white-space: normal;
  line-height: 1.5;
}

.modal.hidden { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-card {
  position: relative;
  width: min(920px, 100%);
  max-height: calc(100vh - 48px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-footer {
  border-bottom: none;
  border-top: 1px solid var(--gray-100);
}

.modal-header h2 {
  font-size: 18px;
  margin-bottom: 4px;
}

.modal-close {
  border: none;
  background: var(--gray-100);
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  padding: 16px 20px;
  overflow: auto;
}

.prompt-block + .prompt-block {
  margin-top: 14px;
}

.prompt-block-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-500);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.prompt-pre {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.6;
  max-height: 240px;
  overflow: auto;
}

.prompt-pre.empty {
  color: var(--gray-500);
  font-style: italic;
}

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .sidebar { position: static; width: 100%; }
  .main { margin-left: 0; }
  .app { flex-direction: column; }
}
