:root {
  --bg: #f4f7fb;
  --bg-soft: #e8edf5;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --surface-strong: #eef4f8;
  --border: #d8e0ec;
  --border-strong: #b9c6d8;
  --text: #182230;
  --text-muted: #667085;
  --text-soft: #98a2b3;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --primary-soft: #d9f3ef;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --green: #16803c;
  --green-soft: #dcfce7;
  --red: #b42318;
  --red-soft: #fee4e2;
  --orange: #b45309;
  --orange-soft: #ffedd5;
  --shadow: 0 18px 45px rgba(24, 34, 48, 0.10);
  --shadow-soft: 0 8px 24px rgba(24, 34, 48, 0.07);
}

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

body {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), rgba(244, 247, 251, 0) 320px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

code {
  display: inline-block;
  max-width: 360px;
  overflow: hidden;
  color: #344054;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

#app {
  width: min(1440px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
  padding: 18px 20px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(216, 224, 236, 0.86);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid rgba(15, 118, 110, 0.32);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.92), rgba(37, 99, 235, 0.78)),
    var(--primary);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.30);
}

.eyebrow,
.section-kicker {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.header h1 {
  margin-top: 2px;
  color: var(--text);
  font-size: 24px;
  font-weight: 750;
  line-height: 1.15;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.token-input,
.input {
  min-height: 38px;
  padding: 8px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.token-input {
  width: clamp(190px, 24vw, 300px);
}

.input {
  width: 100%;
  margin-top: 6px;
}

.token-input::placeholder,
.input::placeholder {
  color: var(--text-soft);
}

.token-input:focus,
.input:focus {
  border-color: rgba(15, 118, 110, 0.70);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 650;
}

.btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
}

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

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

.btn-secondary {
  color: #344054;
  background: var(--surface);
  border-color: var(--border);
}

.btn-secondary:hover {
  color: var(--primary-strong);
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.btn-danger,
.btn-sm {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  margin-right: 6px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.btn-sm {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: rgba(37, 99, 235, 0.18);
}

.btn-sm:hover {
  background: #c7dafe;
}

.btn-danger {
  color: var(--red);
  background: var(--red-soft);
  border-color: rgba(180, 35, 24, 0.16);
}

.btn-danger:hover {
  color: #ffffff;
  background: var(--red);
}

.btn-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.btn-close:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.banner {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--orange);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.banner strong {
  display: block;
  margin-bottom: 2px;
  color: var(--text);
  font-size: 15px;
}

.banner p {
  color: var(--text-muted);
}

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

.stat-card {
  position: relative;
  min-height: 116px;
  padding: 18px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.stat-card::before {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: var(--primary);
  content: "";
}

.stat-card.calls::before {
  background: var(--blue);
}

.stat-card.errors::before {
  background: var(--orange);
}

.stat-card.tokens::before {
  background: var(--green);
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.stat-card .value {
  margin-top: 10px;
  color: var(--text);
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
}

.stat-card .sub {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 14px;
  padding: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.tab {
  min-height: 34px;
  padding: 7px 14px;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary-strong);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(24, 34, 48, 0.10);
}

.tab-content {
  display: none;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tab-content.active {
  display: block;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.section-header h2 {
  margin-top: 2px;
  color: var(--text);
  font-size: 19px;
  font-weight: 800;
}

.table {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
  background: var(--surface);
}

.table th,
.table td {
  padding: 13px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

.table th {
  color: var(--text-muted);
  background: var(--surface-muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.table tbody tr {
  transition: background 140ms ease;
}

.table tbody tr:hover {
  background: #f2f7fb;
}

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

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.badge-active,
.badge-connected {
  color: var(--green);
  background: var(--green-soft);
}

.badge-revoked,
.badge-disconnected {
  color: var(--red);
  background: var(--red-soft);
}

.config-panel {
  margin: 20px;
  padding: 18px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.config-panel + .config-panel {
  margin-top: 0;
}

.config-panel h3 {
  margin-bottom: 14px;
  font-size: 16px;
  font-weight: 800;
}

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

.meta-item {
  min-width: 0;
  padding: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.meta-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 750;
}

#oauth-config-result {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(24, 34, 48, 0.56);
  backdrop-filter: blur(5px);
  z-index: 100;
}

.modal-content {
  width: min(900px, 100%);
  max-height: min(82vh, 760px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal-content > .form-group,
.modal-content > .btn,
.modal-content > .result-box {
  margin-right: 22px;
  margin-left: 22px;
}

.modal-content > .btn {
  margin-bottom: 22px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

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

.modal .table {
  min-width: 720px;
}

.result-box {
  margin-top: 16px;
  margin-bottom: 22px;
  padding: 14px;
  color: var(--text);
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 8px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  word-break: break-all;
}

.result-box .token {
  color: #86efac;
}

.result-box .warning {
  margin-top: 8px;
  color: #fed7aa;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.empty {
  padding: 42px 16px;
  color: var(--text-muted);
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(24, 34, 48, 0.72);
  z-index: 200;
}

.overlay-content {
  width: min(420px, 100%);
  padding: 28px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.overlay-content h2 {
  margin-bottom: 8px;
  color: var(--text);
}

.overlay-content p {
  margin-bottom: 16px;
  color: var(--text-muted);
}

.overlay-content input {
  width: 100%;
  margin-bottom: 12px;
}

@media (max-width: 980px) {
  #app {
    width: min(100% - 28px, 1440px);
    padding-top: 14px;
  }

  .header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions,
  .token-input {
    width: 100%;
  }

  .header-actions .btn,
  .header-actions a {
    flex: 1 1 160px;
  }

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

@media (max-width: 640px) {
  #app {
    width: min(100% - 20px, 1440px);
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .header h1 {
    font-size: 20px;
  }

  .banner,
  .section-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .banner .btn,
  .section-header .btn {
    width: 100%;
  }

  .stats-grid,
  .config-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tab {
    padding-right: 8px;
    padding-left: 8px;
  }

  .config-panel {
    margin: 14px;
    padding: 14px;
  }
}
