:root {
  --background: 240 20% 98.8%;
  --foreground: 224 47% 11%;
  --card: 0 0% 100%;
  --card-foreground: 224 47% 11%;
  --popover: 0 0% 100%;
  --popover-foreground: 224 47% 11%;
  --primary: 239 84% 67%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 20% 96%;
  --secondary-foreground: 224 47% 18%;
  --muted: 240 18% 95.5%;
  --muted-foreground: 225 12% 45%;
  --accent: 240 18% 95.5%;
  --accent-foreground: 224 47% 18%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --border: 220 14% 91%;
  --input: 220 14% 91%;
  --ring: 239 84% 67%;
  --radius: 0.625rem;

  --blue: 217 91% 60%;
  --violet: 262 83% 58%;
  --emerald: 160 84% 39%;
  --amber: 38 92% 50%;
  --orange: 25 95% 53%;
  --red: 0 84% 60%;
  --zinc: 240 5% 46%;

  --sans: "Geist Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: hsl(var(--background)); }
@font-face { font-family: "Geist Sans"; font-style: normal; font-weight: 100 900; font-display: swap; src: url(/static/fonts/GeistSans-Variable.woff2) format("woff2"); }
body {
  min-height: 100vh;
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--sans);
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

button, input, textarea, select { font: inherit; }
button { appearance: none; }
a { color: inherit; text-decoration: none; }
svg { display: block; width: 1em; height: 1em; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

input, textarea, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 0.125rem);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0.625rem 0.75rem;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
textarea { min-height: 84px; resize: vertical; }
select { appearance: none; }
input::placeholder, textarea::placeholder { color: hsl(var(--muted-foreground) / 0.62); }
input:focus, textarea:focus, select:focus {
  border-color: hsl(var(--ring) / 0.42);
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.08);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.25rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 0.125rem);
  padding: 0 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}
.btn svg { width: 1rem; height: 1rem; }
.btn:disabled { cursor: not-allowed; opacity: 0.55; }
.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  box-shadow: 0 8px 20px hsl(var(--primary) / 0.18), 0 1px 2px 0 hsl(var(--foreground) / 0.05);
}
.btn-primary:hover:not(:disabled) { background: hsl(var(--primary) / 0.92); }
.btn-outline {
  border-color: hsl(var(--border));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
}
.btn-outline:hover:not(:disabled) { background: hsl(var(--accent)); }
.btn-danger {
  border-color: hsl(var(--red) / 0.22);
  background: hsl(var(--red) / 0.08);
  color: hsl(var(--red));
}
.btn-danger:hover:not(:disabled) { background: hsl(var(--red) / 0.13); }
.btn-full { width: 100%; }
.btn-small { min-height: 1.875rem; padding: 0 0.625rem; font-size: 0.75rem; }

.api-list-card .btn {
  min-height: 2rem;
  padding-inline: 0.75rem;
  font-size: 0.75rem;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 18% 12%, hsl(var(--primary) / 0.12), transparent 30rem),
    radial-gradient(circle at 84% 18%, hsl(var(--blue) / 0.10), transparent 26rem),
    hsl(var(--background));
}
.login-stack {
  display: grid;
  justify-items: center;
  width: min(100%, 24rem);
  gap: 1rem;
}
.login-brand {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 1rem;
  background: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--primary) / 0.76));
  color: hsl(var(--primary-foreground));
  box-shadow: 0 18px 45px hsl(var(--primary) / 0.22);
}
.login-brand svg { width: 1.35rem; height: 1.35rem; }
.login-title { text-align: center; }
.login-title h1 {
  margin: 0;
  color: hsl(var(--foreground));
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}
.login-title p {
  margin: 0.25rem 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}
.login-card {
  width: 100%;
  border: 1px solid hsl(var(--border));
  border-radius: 1rem;
  background: hsl(var(--card));
  padding: 1.5rem;
  box-shadow: 0 24px 70px hsl(var(--foreground) / 0.11), 0 2px 8px hsl(var(--foreground) / 0.04);
}
.login-copy { margin-bottom: 1.25rem; }
.login-copy h2 {
  margin: 0;
  color: hsl(var(--card-foreground));
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: -0.025em;
}
.login-copy p {
  margin: 0.25rem 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  line-height: 1.5;
}
.field-label {
  display: block;
  margin-bottom: 0.375rem;
  color: hsl(var(--foreground));
  font-size: 0.8125rem;
  font-weight: 500;
}
.input-with-icon { position: relative; margin-bottom: 1rem; }
.input-with-icon svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  width: 1rem;
  height: 1rem;
  transform: translateY(-50%);
  color: hsl(var(--muted-foreground));
  pointer-events: none;
}
.input-with-icon input { padding-left: 2.375rem; }
.input-with-icon.compact { margin-bottom: 0; min-width: 0; flex: 1; }
.input-with-icon.compact input { min-height: 2rem; padding-top: 0.375rem; padding-bottom: 0.375rem; font-size: 0.75rem; }

.app-shell { min-height: 100vh; padding-bottom: 3.25rem; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid hsl(var(--border) / 0.72);
  background: hsl(var(--background) / 0.52);
  backdrop-filter: blur(18px) saturate(1.8);
  box-shadow: 0 1px 12px hsl(var(--foreground) / 0.06);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1500px;
  min-height: 3.3rem;
  margin: 0 auto;
  padding: 0 1rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  flex: 1 1 0;
  min-width: 0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}
.brand-icon {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.625rem;
  background: linear-gradient(135deg, hsl(var(--primary) / 0.16), hsl(var(--primary) / 0.05));
  color: hsl(var(--primary));
}
.brand-icon svg { width: 1.125rem; height: 1.125rem; }

.nav-pills {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  flex: 0 0 auto;
  border: 1px solid hsl(var(--border) / 0.5);
  border-radius: 0.5rem;
  background: hsl(var(--muted) / 0.4);
  padding: 0.125rem;
}
.nav-pill {
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: hsl(var(--muted-foreground));
  padding: 0.45rem 0.875rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}
.nav-pill:hover { color: hsl(var(--foreground)); }
.nav-pill.active {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: 0 1px 2px 0 hsl(var(--foreground) / 0.06);
}
.topbar-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex: 1 1 0;
  gap: 0.5rem;
}
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}
.icon-button:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.icon-button svg { width: 1rem; height: 1rem; }
.eye-off, .privacy-on .eye-on { display: none; }
.privacy-on .eye-off { display: block; }

.page-frame {
  max-width: 1500px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}
.page-heading h1 {
  margin: 0;
  color: hsl(var(--foreground));
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.035em;
}
.page-heading p {
  margin: 0.25rem 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  line-height: 1.5;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card,
.table-card,
.form-card,
.upstream-card,
.placeholder-card,
.doc-card {
  border: 1px solid hsl(var(--border));
  border-radius: 0.75rem;
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  box-shadow: 0 1px 2px 0 hsl(var(--foreground) / 0.04);
}
.stat-card { padding: 1rem; }
.stat-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}
.stat-icon {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: calc(var(--radius) + 0.125rem);
  flex: 0 0 auto;
}
.stat-icon svg { width: 1rem; height: 1rem; }
.stat-blue { background: hsl(var(--blue) / 0.12); color: hsl(var(--blue)); }
.stat-violet { background: hsl(var(--violet) / 0.12); color: hsl(var(--violet)); }
.stat-emerald { background: hsl(var(--emerald) / 0.12); color: hsl(var(--emerald)); }
.stat-amber { background: hsl(var(--amber) / 0.14); color: hsl(var(--amber)); }
.stat-value {
  margin-top: 0.875rem;
  font-size: 1.625rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.03em;
}
.stat-meta {
  margin-top: 0.375rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  line-height: 1.45;
}

.table-card { overflow: hidden; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.875rem;
}
.section-header.compact { padding-bottom: 0.25rem; }
.section-kicker {
  margin: 0 0 0.25rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}
.section-header h2,
.placeholder-card h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.025em;
}
.section-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.625rem;
  flex-wrap: wrap;
}
.quiet-count {
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
}
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.fixed-table { min-width: 1240px; table-layout: fixed; }
.keys-table { min-width: 980px; }
th {
  border-top: 1px solid hsl(var(--border));
  border-bottom: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground) / 0.8);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1;
  padding: 0.75rem 1rem;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
td {
  border-bottom: 1px solid hsl(var(--border) / 0.72);
  color: hsl(var(--foreground));
  font-size: 0.8125rem;
  line-height: 1.45;
  padding: 0.875rem 1rem;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: hsl(var(--muted) / 0.38); }
.align-right { text-align: right; }
.mono,
.key-prefix,
.model-cell,
.tokens-cell,
.cost-cell,
#logsPage,
.status-inner strong,
.generated-key pre {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.model-cell,
.detail-cell,
.key-prefix {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tokens-cell,
.cost-cell { text-align: right; }
.account-cell strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subtext {
  margin-top: 0.25rem;
  color: hsl(var(--muted-foreground));
  font-family: var(--mono);
  font-size: 0.6875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.empty-row {
  padding: 2.5rem 1rem;
  color: hsl(var(--muted-foreground));
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.5rem;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  padding: 0.1875rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.badge-ok { border-color: hsl(var(--emerald) / 0.24); background: hsl(var(--emerald) / 0.11); color: hsl(var(--emerald)); }
.badge-rate_limit { border-color: hsl(var(--orange) / 0.25); background: hsl(var(--orange) / 0.12); color: hsl(var(--orange)); }
.badge-quota { border-color: hsl(var(--red) / 0.25); background: hsl(var(--red) / 0.11); color: hsl(var(--red)); }
.badge-error { border-color: hsl(var(--zinc) / 0.22); background: hsl(var(--zinc) / 0.11); color: hsl(var(--zinc)); }
.badge-active { border-color: hsl(var(--emerald) / 0.24); background: hsl(var(--emerald) / 0.1); color: hsl(var(--emerald)); }
.badge-inactive { border-color: hsl(var(--zinc) / 0.22); background: hsl(var(--zinc) / 0.1); color: hsl(var(--zinc)); }
.badge-revoked { border-color: hsl(var(--red) / 0.25); background: hsl(var(--red) / 0.11); color: hsl(var(--red)); }
.badge-warn { border-color: hsl(var(--amber) / 0.3); background: hsl(var(--amber) / 0.13); color: hsl(var(--amber)); }

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.625rem;
  border-top: 1px solid hsl(var(--border));
  padding: 0.875rem 1rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
}

.keys-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24rem;
  gap: 1rem;
  align-items: start;
}
.keys-workspace {
  display: grid;
  grid-template-columns: minmax(18rem, 0.86fr) minmax(0, 1.14fr);
  gap: 1rem;
  align-items: start;
}
.api-list-card, .key-detail-card { min-height: 34rem; }
.api-list-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem 0.75rem;
}
.api-list-controls select {
  width: 8.5rem;
  min-height: 2rem;
  padding: 0.375rem 0.625rem;
  color: hsl(var(--foreground));
  font-size: 0.8125rem;
}
.api-key-list {
  display: grid;
  gap: 0.25rem;
  max-height: calc(100vh - 17rem);
  overflow-y: auto;
  padding: 0 1rem 1rem;
}
.api-key-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  padding: 0.625rem 0.75rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.api-key-item:hover { background: hsl(var(--muted) / 0.5); }
.api-key-item.selected {
  background: hsl(var(--primary) / 0.08);
  box-shadow: inset 0 0 0 1px hsl(var(--primary) / 0.25);
}
.api-key-item-top {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}
.api-key-item-top strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
  font-weight: 500;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.25rem;
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
  color: white;
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 1;
}
.status-pill.active { background: hsl(var(--emerald)); }
.status-pill.revoked { background: hsl(var(--zinc)); }
.api-key-item-bar {
  margin-top: 0.375rem;
}
.mini-usage-bar {
  display: block;
  height: 4px;
  width: 100%;
  border-radius: 9999px;
  background: hsl(var(--muted));
  overflow: hidden;
}
.mini-usage-fill {
  display: block;
  height: 100%;
  border-radius: 9999px;
  transition: width 0.3s;
}
.mini-usage-fill.bar-green { background: hsl(160 84% 39%); }
.mini-usage-fill.bar-amber { background: hsl(38 92% 50%); }
.mini-usage-fill.bar-orange { background: hsl(25 95% 53%); }
.mini-usage-fill.bar-red { background: hsl(0 84% 60%); }
.mini-usage-fill.bar-empty { background: transparent; }
}
.key-detail-card { padding: 1rem; }
.empty-detail {
  display: grid;
  align-content: center;
  min-height: 28rem;
  color: hsl(var(--muted-foreground));
  text-align: center;
}
.empty-detail h2 { margin: 0.25rem 0 0; color: hsl(var(--foreground)); }
.empty-detail p:last-child { max-width: 28rem; margin: 0.5rem auto 0; line-height: 1.55; }
.key-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.25rem;
}
.key-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.key-detail-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.025em;
}
.detail-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.375rem; }
.detail-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.625rem;
  margin-top: 0.75rem;
}
.detail-stat {
  border: 1px solid hsl(var(--border));
  border-radius: 0.65rem;
  background: hsl(var(--muted) / 0.36);
  padding: 0.625rem 0.75rem;
}
.detail-stat span { display: block; color: hsl(var(--muted-foreground)); font-size: 0.625rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.detail-stat strong { display: block; margin-top: 0.25rem; font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-info-panel {
  margin-top: 0.75rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.75rem;
  background: hsl(var(--muted) / 0.30);
  padding: 0.875rem;
}
.key-info-panel h3 {
  margin: 0 0 0.875rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}
.key-info-panel dl {
  display: grid;
  gap: 0.625rem;
  margin: 0;
  font-size: 0.75rem;
}
.key-info-panel dl > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-width: 0;
}
.key-info-panel dt {
  color: hsl(var(--muted-foreground));
  flex: 0 0 auto;
}
.key-info-panel dd {
  min-width: 0;
  max-width: 75%;
  margin: 0;
  color: hsl(var(--foreground));
  font-weight: 500;
  line-height: 1.45;
  text-align: right;
  overflow-wrap: anywhere;
}
.key-info-panel .key-prefix {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.muted-value { color: hsl(var(--muted-foreground)); font-weight: 400; }
.text-danger { color: hsl(var(--destructive)) !important; }
.key-info-limits { margin-top: 0.875rem; padding-top: 0.875rem; border-top: 1px solid hsl(var(--border)); }
.detail-section { margin-top: 1.125rem; }
.detail-section h3 { margin: 0 0 0.5rem; font-size: 0.8125rem; font-weight: 700; }
.detail-section p { margin: 0; color: hsl(var(--muted-foreground)); font-size: 0.875rem; line-height: 1.55; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.875rem; }
.limit-chip-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.limit-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid hsl(var(--blue) / 0.22);
  border-radius: 999px;
  background: hsl(var(--blue) / 0.07);
  color: hsl(var(--blue));
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
}
.form-card { padding-bottom: 1rem; }
.form-stack {
  display: grid;
  gap: 0.875rem;
  padding: 0.75rem 1rem 0;
}
.form-stack label {
  display: grid;
  gap: 0.375rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  font-weight: 500;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.limit-input { width: 6.25rem; min-height: 2rem; padding: 0.375rem 0.5rem; font-family: var(--mono); font-size: 0.75rem; }
.table-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.generated-key {
  margin: 1rem 1rem 0;
  border: 1px dashed hsl(var(--blue) / 0.35);
  border-radius: 0.75rem;
  background: hsl(var(--blue) / 0.06);
  padding: 0.875rem;
}
.generated-key[hidden] { display: none; }
.generated-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.generated-head strong { font-size: 0.8125rem; font-weight: 600; }
.generated-key pre {
  margin: 0.75rem 0 0;
  white-space: pre-wrap;
  word-break: break-all;
  color: hsl(var(--blue));
  font-size: 0.75rem;
  line-height: 1.6;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: grid;
  place-items: center;
  background: hsl(var(--foreground) / 0.36);
  padding: 1rem;
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: min(62rem, 100%);
  max-height: min(90vh, 52rem);
  overflow: auto;
  border: 1px solid hsl(var(--border));
  border-radius: 1rem;
  background: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
  box-shadow: 0 24px 80px hsl(var(--foreground) / 0.22);
}
.modal-header, .modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
}
.modal-header { border-bottom: 1px solid hsl(var(--border)); }
.modal-header h2 { margin: 0; font-size: 1.125rem; }
.modal-header p { margin: 0.375rem 0 0; color: hsl(var(--muted-foreground)); font-size: 0.875rem; }
.modal-footer { border-top: 1px solid hsl(var(--border)); justify-content: flex-end; }
.modal-body { padding: 1rem; }
.two-column-form { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.form-panel { display: grid; gap: 0.875rem; }
.form-panel label {
  display: grid;
  gap: 0.375rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  font-weight: 500;
}
.form-panel h3 { margin: 0.25rem 0 0; font-size: 0.95rem; }
.limits-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.switch-label { display: inline-flex !important; grid-template-columns: auto auto; align-items: center; gap: 0.5rem; white-space: nowrap; }
.switch-label input { width: auto; min-height: auto; }
.limits-basic, .limits-advanced { display: grid; gap: 0.875rem; }
.limits-basic[hidden], .limits-advanced[hidden] { display: none; }
.limit-rules { display: grid; gap: 0.75rem; }
.limit-rule-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.625rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.75rem;
  padding: 0.75rem;
}
.limit-rule-row [data-remove-limit] { align-self: end; }

.upstream-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.upstream-card { padding: 1rem; }
.documentation-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
.doc-card { padding: 1.25rem; }
.doc-card h2 {
  margin: 0.25rem 0 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.025em;
}
.doc-card pre {
  margin: 1rem 0 0;
  overflow-x: auto;
  border: 1px solid hsl(var(--border));
  border-radius: 0.625rem;
  background: hsl(var(--muted) / 0.5);
  color: hsl(var(--foreground));
  padding: 0.875rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.6;
}
.upstream-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.upstream-title { margin: 0.25rem 0 0; font-size: 1rem; font-weight: 600; letter-spacing: -0.025em; }
.upstream-url {
  margin: 0.875rem 0 0;
  color: hsl(var(--muted-foreground));
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.55;
  word-break: break-all;
}
.upstream-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.875rem; }
.model-pills { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 1rem; }
.model-pill {
  display: inline-flex;
  align-items: center;
  min-height: 1.5rem;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  padding: 0.1875rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.6875rem;
  white-space: nowrap;
}
.error-text { margin: 0.875rem 0 0; color: hsl(var(--destructive)); font-size: 0.75rem; line-height: 1.5; }

.placeholder-card {
  display: grid;
  justify-items: center;
  max-width: 34rem;
  margin: 4rem auto 0;
  padding: 3rem 1.5rem;
  text-align: center;
}
.placeholder-icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: 1rem;
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}
.placeholder-icon svg { width: 1.25rem; height: 1.25rem; }
.placeholder-card p:last-child {
  max-width: 27rem;
  margin: 0.625rem 0 0;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
  line-height: 1.6;
}

.status-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  border-top: 1px solid hsl(var(--border) / 0.72);
  background: hsl(var(--background) / 0.52);
  backdrop-filter: blur(18px) saturate(1.8);
  box-shadow: 0 -1px 12px hsl(var(--foreground) / 0.06);
}
.status-inner {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1.25rem;
  min-height: 2.25rem;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 1rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  line-height: 1;
}
.status-inner span { display: inline-flex; align-items: center; gap: 0.25rem; white-space: nowrap; }
.status-inner strong { color: hsl(var(--foreground)); font-size: 0.6875rem; font-weight: 500; }
.live-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: hsl(var(--emerald));
  box-shadow: 0 0 0 3px hsl(var(--emerald) / 0.12);
}
.live-dot.off { background: hsl(var(--zinc)); box-shadow: 0 0 0 3px hsl(var(--zinc) / 0.12); }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 4rem;
  z-index: 60;
  display: none;
  max-width: min(26rem, calc(100vw - 2rem));
  border: 1px solid hsl(var(--border));
  border-radius: 0.75rem;
  background: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
  box-shadow: 0 20px 25px -5px hsl(var(--foreground) / 0.1), 0 8px 10px -6px hsl(var(--foreground) / 0.1);
  padding: 0.875rem 1rem;
  font-size: 0.8125rem;
  line-height: 1.45;
}
.toast.show { display: block; animation: toast-in 180ms ease-out; }
@keyframes toast-in { from { transform: translateY(0.5rem); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.privacy-on .private {
  filter: blur(0.25rem);
  user-select: none;
}
.privacy-on .private:hover { filter: blur(0.125rem); }

@media (max-width: 1080px) {
  .topbar-inner { flex-wrap: wrap; padding: 0.75rem 1rem; }
  .brand { flex: 1 1 auto; }
  .nav-pills { order: 3; width: 100%; overflow-x: auto; justify-content: flex-start; }
  .topbar-actions { flex: 0 0 auto; justify-content: flex-end; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .keys-layout, .keys-workspace, .upstream-grid, .documentation-grid, .two-column-form { grid-template-columns: 1fr; }
  .detail-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .page-frame { padding: 1rem 0.75rem; }
  .page-heading { align-items: flex-start; flex-direction: column; margin-bottom: 1.25rem; }
  .stats-grid { grid-template-columns: 1fr; gap: 0.75rem; }
  .section-header { align-items: flex-start; flex-direction: column; }
  .section-actions { width: 100%; justify-content: space-between; }
  .api-list-controls { align-items: stretch; flex-direction: column; }
  .api-list-controls select { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .api-key-item { flex-direction: column; }
  .api-key-item-meta, .key-detail-head { align-items: flex-start; flex-direction: column; }
  .detail-stats-grid, .detail-grid, .limit-rule-row { grid-template-columns: 1fr; }
  .status-inner { justify-content: flex-start; overflow-x: auto; }
  .topbar-actions .btn { padding: 0 0.625rem; }
}
