:root {
  --bg: #0f1115;
  --surface: #171921;
  --surface-2: #1f2330;
  --text: #e8eaf0;
  --text-muted: #9aa0ae;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #2a2f3d;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

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

.app {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 20px;
}

header {
  text-align: center;
  margin-bottom: 28px;
}

header h1 {
  margin: 0 0 4px;
  font-size: 1.75rem;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
}

.controls {
  margin-bottom: 24px;
}

details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

summary {
  cursor: pointer;
  font-weight: 600;
  user-select: none;
}

.token-form {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.token-form label span {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.token-form input[type="password"],
.token-form input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
}

.token-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.refresh-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

button {
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  transition: opacity 0.15s ease;
}

button:hover {
  opacity: 0.9;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: white;
}

button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary.danger {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.4);
}

#last-refreshed {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.cards {
  display: grid;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card.loading {
  opacity: 0.7;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.15rem;
}

.provider-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: white;
}

.icon-claude { background: #cc785c; }
.icon-kimi { background: #3b82f6; }
.icon-zai { background: #10b981; }

.status {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.status.ok { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status.warn { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.status.error { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

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

.metric {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 12px;
}

.metric-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.metric-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
}

.bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 6px;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease, background 0.4s ease;
}

.bar-fill.low { background: var(--success); }
.bar-fill.medium { background: var(--warning); }
.bar-fill.high { background: var(--danger); }

.error-message {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 8px;
}

.error-message .hint {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 6px;
}

.error-message code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.error-details {
  display: block;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.error-details summary {
  cursor: pointer;
  font-weight: 600;
}

.error-details code {
  display: block;
  margin-top: 6px;
  padding: 8px;
  word-break: break-all;
  white-space: pre-wrap;
}

.last-updated {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 12px;
}

footer {
  margin-top: 40px;
  text-align: center;
}

.support {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.support p {
  margin: 0 0 8px;
  color: var(--text-muted);
}

.support a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.tip-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0;
  font-size: 0.9rem;
}

.tip-address {
  background: var(--surface-2);
  padding: 4px 8px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text);
}

button.small,
a.button.small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

a.button {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
}

.placeholder {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.fineprint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.fineprint a {
  color: var(--text-muted);
  text-decoration: underline;
}
