:root {
  color-scheme: dark;
  --bg: #070b11;
  --panel: #101722;
  --panel-2: #0c121b;
  --panel-3: #151e2b;
  --text: #f1f5f9;
  --muted: #9aa8b8;
  --line: rgba(148, 163, 184, 0.18);
  --accent: #2dd4bf;
  --blue: #60a5fa;
  --violet: #a78bfa;
  --green: #34d399;
  --amber: #fbbf24;
  --rose: #fb7185;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  background:
    linear-gradient(rgba(148, 163, 184, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.04) 1px, transparent 1px),
    var(--bg);
  background-size: 52px 52px;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
p {
  margin: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: rgba(7, 11, 17, 0.94);
  border-right: 1px solid var(--line);
}

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

.brand span {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(45, 212, 191, 0.55);
  border-radius: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  background: rgba(45, 212, 191, 0.08);
}

.brand strong {
  font-size: 15px;
}

nav {
  display: grid;
  gap: 8px;
}

nav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 720;
}

nav a:hover,
nav a.active {
  color: var(--text);
  background: rgba(45, 212, 191, 0.1);
}

.shell {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  font-size: 30px;
  line-height: 1.12;
}

h2 {
  font-size: 15px;
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 140px auto auto;
  align-items: end;
  gap: 10px;
  min-width: min(100%, 620px);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

input,
select,
button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

input,
select {
  width: 100%;
  padding: 8px 10px;
  background: #080d15;
  color: var(--text);
}

button {
  padding: 8px 14px;
  border-color: rgba(45, 212, 191, 0.5);
  background: var(--accent);
  color: #031014;
  cursor: pointer;
  font-weight: 850;
}

button:hover {
  background: #5eead4;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(12, 18, 27, 0.9);
}

.status-pill.ok {
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--green);
}

.status-pill.error {
  border-color: rgba(251, 113, 133, 0.45);
  color: var(--rose);
}

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

.kpi,
.panel,
.provider-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 23, 34, 0.94);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

.kpi {
  min-height: 116px;
  padding: 16px;
}

.kpi span,
.kpi small,
.panel-title span {
  color: var(--muted);
  font-size: 12px;
}

.kpi strong {
  display: block;
  margin: 9px 0 6px;
  font-size: 28px;
  line-height: 1.08;
}

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

.provider-card {
  padding: 16px;
  background: var(--panel-2);
}

.provider-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.provider-name {
  font-weight: 850;
}

.provider-tag {
  color: var(--muted);
  font-size: 12px;
}

.provider-value {
  color: var(--blue);
  font-size: 24px;
  font-weight: 900;
}

.provider-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #070b11;
}

.provider-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.6fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.token-panel,
.table-panel {
  grid-column: span 1;
}

.user-panel {
  grid-column: span 2;
}

.panel-title {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.legend-input {
  background: var(--blue);
}

.legend-output {
  background: var(--accent);
}

.legend-revenue {
  background: var(--amber);
}

canvas {
  width: 100%;
  max-width: 100%;
  display: block;
}

.model-legend {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.user-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  margin-top: 12px;
}

.model-item,
.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.model-item span,
.user-item span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-item strong {
  color: var(--text);
  font-weight: 760;
  white-space: nowrap;
}

.model-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 999px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
}

.compact table {
  min-width: 460px;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

th {
  background: #0a1018;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.status-text {
  color: var(--green);
  font-weight: 800;
}

.status-text.error {
  color: var(--rose);
}

.alert-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.alert {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a1018;
  color: var(--muted);
  font-size: 13px;
}

.alert strong {
  color: var(--text);
}

.empty {
  color: var(--muted);
}

@media (max-width: 1160px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
  }

  nav {
    display: flex;
    flex-wrap: wrap;
  }

  .brand {
    margin-bottom: 0;
  }

  .topbar,
  .controls {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .topbar {
    display: grid;
  }
}

@media (max-width: 860px) {
  .shell {
    padding: 16px;
  }

  .kpi-grid,
  .monitor-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .user-panel {
    grid-column: span 1;
  }

  .user-legend {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 26px;
  }
}
