:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --text: #18202f;
  --muted: #667085;
  --line: #d9e0ea;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --accent: #3b82f6;
  --danger: #dc2626;
  --warning: #b45309;
  --success: #15803d;
  --shadow: 0 10px 28px rgba(31, 42, 68, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #17202f;
  color: #edf3fb;
  padding: 24px;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #14b8a6;
  color: #062321;
  font-weight: 800;
}

.brand h1,
.brand p,
.page-title h2,
.page-title p,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p {
  color: #aab6c7;
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  display: flex;
  align-items: center;
  min-height: 42px;
  border-radius: 8px;
  color: #c9d4e5;
  padding: 10px 12px;
}

.nav-tab:hover,
.nav-tab.active {
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 22px;
}

.connection-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.connection-form {
  display: grid;
  grid-template-columns: minmax(180px, 300px) minmax(180px, 300px) auto;
  gap: 12px;
  align-items: end;
}

.field {
  display: grid;
  gap: 7px;
}

.field label,
.field-group legend {
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field textarea,
.search-input,
.small-input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.search-input:focus,
.small-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.field small {
  color: var(--muted);
  font-size: 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  padding: 9px 13px;
}

.button:hover {
  border-color: #b9c3d1;
  background: #f8fafc;
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.button.primary:hover {
  border-color: var(--primary-strong);
  background: var(--primary-strong);
}

.button.danger {
  border-color: #fecaca;
  color: var(--danger);
}

.button.full-width {
  width: 100%;
}

.page-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin: 10px 0 18px;
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page-title h2 {
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.08;
}

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

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  display: grid;
  gap: 6px;
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  font-size: 34px;
}

.split-layout,
.agents-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.86fr) minmax(0, 1.14fr);
  gap: 14px;
}

.agents-layout {
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  align-items: start;
}

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

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

.panel-heading h3 {
  font-size: 17px;
}

.provider-list,
.agent-mini-list {
  display: grid;
  gap: 10px;
}

.provider-item,
.agent-mini-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.status-badge,
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge {
  background: var(--surface-2);
  color: #475467;
}

.status-badge.good,
.chip.good {
  background: #dcfce7;
  color: var(--success);
}

.status-badge.bad,
.chip.bad {
  background: #fee2e2;
  color: var(--danger);
}

.chip,
.chip.warn {
  background: var(--surface-2);
  color: #475467;
}

.form-panel {
  display: grid;
  gap: 14px;
}

.field-group {
  display: grid;
  gap: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.field-group label {
  display: flex;
  gap: 8px;
  color: #344054;
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.table-panel {
  overflow: hidden;
}

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

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
  text-transform: uppercase;
}

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

td {
  color: #344054;
  font-size: 13px;
}

.agent-name {
  display: grid;
  gap: 3px;
}

.agent-name strong {
  color: var(--text);
  font-size: 14px;
}

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

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row-actions form {
  margin: 0;
}

.inline-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.small-input {
  max-width: 90px;
}

.usage-metrics {
  margin-bottom: 14px;
}

.cost-card strong {
  color: var(--primary-strong);
}

.rate-note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.token-alert,
.notice {
  margin-bottom: 18px;
  border-radius: 8px;
  padding: 14px;
}

.token-alert {
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  color: #14532d;
}

.token-alert code {
  display: block;
  max-width: min(900px, 70vw);
  margin-top: 7px;
  overflow: auto;
  color: #052e16;
  white-space: nowrap;
}

.notice.success {
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  color: #14532d;
}

.notice.error {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px;
}

.login-panel {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-brand {
  margin-bottom: 22px;
}

.login-brand h1 {
  color: var(--text);
}

.login-brand p {
  color: var(--muted);
}

@media (max-width: 1080px) {
  .app-shell,
  .agents-layout,
  .split-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 16px;
  }

  .nav-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .connection-bar,
  .connection-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 14px;
  }

  .nav-tabs,
  .metric-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .page-title,
  .panel-heading,
  .inline-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .token-alert code {
    max-width: 100%;
  }
}
