:root {
  --bg: #fafafa;
  --fg: #222;
  --muted: #777;
  --card: #fff;
  --border: #e5e5e5;
  --primary: #2d6cdf;
  --primary-dark: #1f55bd;
  --error-bg: #ffeaea;
  --error-fg: #b40000;
  --success-bg: #eaffea;
  --success-fg: #1a7a1a;
}

* { box-sizing: border-box; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700;
  font-size: 1.2em;
  text-decoration: none;
  color: var(--fg);
}
.topbar nav { display: flex; gap: 18px; align-items: center; }
.topbar nav a, .topbar nav button {
  text-decoration: none;
  color: var(--fg);
  font-weight: 500;
}
.linklike {
  background: none; border: none; cursor: pointer; padding: 0;
  color: var(--fg); text-decoration: underline; font: inherit;
}
.inline { display: inline; margin: 0; }

main { max-width: 880px; margin: 0 auto; padding: 28px; }
footer { max-width: 880px; margin: 0 auto; padding: 14px 28px 28px; }
footer .beian { margin-top: 6px; font-size: 0.9em; }

h1 { margin: 0 0 0.4em; }
h2 { margin-top: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.9em; }

.hero { text-align: center; padding: 40px 0; }
.hero h1 { font-size: 2em; }
.hero .lead { font-size: 1.1em; color: var(--muted); }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 28px;
}
.features article {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
}

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-top: 18px;
}
.tier {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
}
.tier h2 { margin-top: 0; }
.price { font-size: 2em; font-weight: 700; margin: 4px 0; }
.provider-select { margin: 8px 0; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  text-decoration: none;
  cursor: pointer;
  font: inherit;
}
.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.form { display: grid; gap: 12px; max-width: 360px; }
.form label { display: grid; gap: 4px; font-weight: 500; }
.form input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 22px;
  margin-bottom: 18px;
}

.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  background: #eef;
  color: #114;
}
.flash.error { background: var(--error-bg); color: var(--error-fg); }
.flash.success { background: var(--success-bg); color: var(--success-fg); overflow-wrap: anywhere; }

code {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  background: #f0f0f0;
  padding: 1px 4px;
  border-radius: 3px;
}
pre.codeblock {
  background: #111827;
  color: #e5e7eb;
  padding: 12px 14px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.85em;
  line-height: 1.5;
  margin: 8px 0;
}
pre.codeblock code {
  background: transparent;       /* override the gray inline-code look */
  color: inherit;
  padding: 0;
  white-space: pre;
}

/* ---- Tab switcher for code samples -------------------------- */
.code-tabs { margin-top: 8px; }
.tab-headers { display: flex; gap: 4px; border-bottom: 1px solid #e5e7eb; margin-bottom: 0; }
.tab-head {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  padding: 6px 12px;
  font-size: 0.9em;
  color: var(--muted, #6b7280);
  cursor: pointer;
  border-radius: 4px 4px 0 0;
}
.tab-head:hover { color: var(--fg, #111); }
.tab-head.active {
  background: #111827;
  color: #f9fafb;
  border-color: #111827;
}
.tab-body { display: none; }
.tab-body.active { display: block; }
.tab-body pre.codeblock { margin-top: 0; border-top-left-radius: 0; }

.keys-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.keys-table th, .keys-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

/* ---------- admin ---------- */
.admin-nav {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  padding: 10px 28px;
  background: #1f2937; color: #fff;
  border-bottom: 1px solid #111827;
}
.admin-nav a { color: #fff; text-decoration: none; padding: 4px 10px; border-radius: 4px; }
.admin-nav a:hover { background: #374151; }
.admin-nav .brand { font-weight: 700; margin-right: 12px; padding-right: 16px; border-right: 1px solid #374151; }
.admin-nav .right { margin-left: auto; color: #d1d5db; font-size: 0.9em; }
.admin-nav .right a { padding: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
}
.stat .label { color: var(--muted); font-size: 0.9em; }
.stat .value { font-size: 1.6em; font-weight: 700; }

table.data { width: 100%; border-collapse: collapse; margin-top: 12px; background: var(--card); }
table.data th, table.data td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.95em;
}
table.data th { background: #f3f4f6; font-weight: 600; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.8em; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.bad { background: #fee2e2; color: #991b1b; }

.btn.danger { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.btn.danger:hover { background: #fecaca; }
.btn.small { padding: 4px 10px; font-size: 0.85em; }

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

/* Progress bar (quota usage) */
.progress {
  width: 100%;
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}
.progress-bar {
  height: 100%;
  background: var(--primary, #2563eb);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-bar.ok { background: #10b981; }
.progress-bar.warn { background: #f59e0b; }
.progress-bar.danger { background: #ef4444; }

/* Outer progress bar = a fixed-height track; .progress-fill inside fills
 * it to the percent width and takes the same color class. Used for quota
 * panel where we already have a label above so track can be thin. */
.progress-bar { background: #e5e7eb; padding: 0; }
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; background: var(--primary, #2563eb); }
.progress-fill.ok { background: #10b981; }
.progress-fill.warn { background: #f59e0b; }
.progress-fill.danger { background: #ef4444; }

.quota-panel { display: flex; flex-direction: column; gap: 10px; }
.quota-summary { display: flex; align-items: center; justify-content: space-between; }
.quota-numbers strong { font-size: 1.4em; }
.quota-meta { font-size: 0.85em; }
.quota-spark { display: flex; align-items: flex-end; gap: 3px; height: 28px; padding-top: 4px; }
.spark-bar { width: 10px; background: #93c5fd; border-radius: 2px 2px 0 0; min-height: 2px; }
.spark-bar.today { background: #2563eb; }

.audit-log pre { white-space: pre-wrap; word-break: break-all; background: #111827; color: #e5e7eb; padding: 10px; border-radius: 6px; font-size: 0.85em; max-height: 240px; overflow: auto; }

.pagination { display: flex; gap: 6px; margin-top: 12px; align-items: center; }
.pagination .info { color: var(--muted); }

.field-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; margin-bottom: 8px; }
.field-row label { color: var(--muted); font-size: 0.9em; }
.field-row input, .field-row textarea {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
}

/* ---- Compact admin tables (user_detail subscriptions + api_keys) ---- */
table.data.compact th,
table.data.compact td {
  padding: 6px 8px;
  font-size: 0.9em;
}
table.data.compact code { font-size: 0.85em; }

/* Sub-row under a main table row — used to show the full proxy key without
 * breaking the main row's height. Visually de-emphasized so the eye treats
 * it as metadata, not a peer of the main columns. */
table.data .sub-row td {
  padding-top: 4px;
  padding-bottom: 10px;
  border-top: none;
  background: #f9fafb;
}
table.data .sub-row code {
  display: inline-block;
  max-width: 100%;
  word-break: break-all;
  font-size: 0.8em;
  color: #4b5563;
}
table.data .sub-row .copy-btn { margin-left: 8px; }
