:root {
  --bg: #070b12;
  --bg2: #0b1120;
  --card: rgba(255, 255, 255, 0.035);
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #e7ecf3;
  --muted: #8b95a7;
  --accent: #4ade80;
  --accent-dim: rgba(74, 222, 128, 0.14);
  --blue: #60a5fa;
  --red: #f87171;
  --amber: #fbbf24;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(96, 165, 250, 0.10), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(74, 222, 128, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  min-height: 100%;
}
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.accent { color: var(--accent); }

/* ------------------------------------------------ topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px; border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky; top: 0; backdrop-filter: blur(8px);
  background: rgba(7, 11, 18, 0.75); z-index: 5;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: 0.3px; display: flex; align-items: center; gap: 10px; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 10px var(--accent); }
.brand-sub { color: var(--muted); font-weight: 400; font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.whoami { color: var(--muted); font-size: 13px; margin-right: 6px; }

/* ------------------------------------------------ layout */
main { max-width: 1180px; margin: 0 auto; padding: 36px 22px 60px; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ------------------------------------------------ welcome */
.hero { text-align: center; margin: 26px 0 30px; }
.hero h1 { font-size: 34px; font-weight: 700; letter-spacing: 0.5px; }
.lead { color: var(--muted); margin-top: 12px; font-size: 15px; }
.download-card {
  max-width: 680px; margin: 0 auto 20px; padding: 18px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 16px;
}
.download-card h2 { font-size: 16px; margin-bottom: 5px; }
.download-card p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.download-card .btn { text-decoration: none; flex: 0 0 auto; }
.login-card {
  max-width: 380px; margin: 0 auto; background: var(--card);
  border: 1px solid var(--card-border); border-radius: 16px; padding: 26px 28px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.35);
}
.login-card h2 { font-size: 18px; margin-bottom: 18px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
input {
  width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 9px;
  border: 1px solid rgba(255,255,255,0.14); background: rgba(0,0,0,0.30);
  color: var(--text); font-size: 14px; outline: none; transition: border .15s;
}
input:focus { border-color: var(--blue); }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.login-hint { margin-top: 16px; color: var(--muted); font-size: 12px; text-align: center; line-height: 1.6; }
.service-strip { display: flex; justify-content: center; gap: 10px; margin-top: 30px; flex-wrap: wrap; }
.chip {
  font-size: 12px; padding: 6px 13px; border-radius: 999px; color: var(--accent);
  background: var(--accent-dim); border: 1px solid rgba(74,222,128,0.25);
}
.chip.muted { color: var(--muted); background: rgba(255,255,255,0.04); border-color: rgba(255,255,255,0.10); }
.chip-name { font-weight: 600; }

/* ------------------------------------------------ console */
.page-title { font-size: 22px; margin: 6px 0 18px; }
.card {
  background: var(--card); border: 1px solid var(--card-border); border-radius: 16px;
  padding: 20px 22px; margin-bottom: 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.card-title { font-size: 16px; font-weight: 650; }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* service card */
.svc-title { display: flex; gap: 12px; align-items: center; }
.svc-icon { font-size: 22px; color: var(--accent); }
.svc-name { font-size: 18px; font-weight: 700; }
.status-pill {
  display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600;
  padding: 6px 13px; border-radius: 999px;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.status-pill.up { color: var(--accent); background: var(--accent-dim); }
.status-pill.up .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-pill.down { color: var(--red); background: rgba(248,113,113,0.12); }
.status-pill.down .dot { background: var(--red); }
.svc-grid { display: grid; grid-template-columns: 1fr 1.4fr; gap: 14px 22px; }
.svc-cell.wide { grid-column: span 1; }
.svc-cell:first-child { grid-column: span 1; }
.cell-label { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.cell-value { font-size: 14px; word-break: break-all; }
.copyable { cursor: pointer; user-select: all; }
.copyable:hover { color: var(--blue); }
.svc-note { margin-top: 14px; font-size: 12px; color: var(--muted); border-top: 1px dashed rgba(255,255,255,0.08); padding-top: 10px; }
.quota-badges { display: flex; gap: 10px; margin: 4px 0 14px; flex-wrap: wrap; }
.quota-badge { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600;
  padding: 5px 13px; border-radius: 999px; background: rgba(255,255,255,0.06); }
.quota-badge.good { color: var(--accent); background: var(--accent-dim); }
.quota-badge.warn { color: var(--amber); background: rgba(251,191,36,0.12); }
.quota-badge.bad { color: var(--red); background: rgba(248,113,113,0.12); }
.quota-window { margin-bottom: 16px; }
.quota-window-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 7px; }
.quota-window-name { font-size: 13px; font-weight: 600; }
.quota-window-reset { font-size: 12px; color: var(--muted); }
.quota-bar { height: 10px; border-radius: 6px; background: rgba(255,255,255,0.08); overflow: hidden; }
.quota-bar-fill { height: 100%; border-radius: 6px; background: var(--accent); transition: width .4s ease; }
.quota-bar-fill.warn { background: var(--amber); }
.quota-bar-fill.danger { background: var(--red); }
.quota-window-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: 12.5px; }
.quota-window-note { color: var(--muted); }
.quota-details { border-top: 1px dashed rgba(255,255,255,0.08); padding-top: 12px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 22px; }
.quota-detail-item { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.quota-detail-label { color: var(--muted); flex: 0 0 auto; }
.quota-detail-item .mono { text-align: right; word-break: break-all; }
.quota-note { margin-top: 14px; font-size: 12px; color: var(--muted); }
#quota-card .card-head { align-items: center; }

/* keys */
.key-create { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.key-create label { margin-bottom: 0; flex: 1 1 130px; }
.key-create label:first-child { flex: 2 1 200px; }
.key-create input { margin-top: 5px; }
table.keys-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.keys-table th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,0.10); white-space: nowrap;
}
.keys-table td { padding: 10px; border-bottom: 1px solid rgba(255,255,255,0.05); vertical-align: middle; }
.keys-table tr:last-child td { border-bottom: none; }
.audit-pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 16px; color: var(--muted); font-size: 12px; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; }
.tag.active { color: var(--accent); background: var(--accent-dim); }
.tag.revoked { color: var(--muted); background: rgba(255,255,255,0.06); text-decoration: line-through; }
.k-masked { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 0 12px; }
.error-banner { color: var(--red); background: rgba(248,113,113,0.10); border: 1px solid rgba(248,113,113,0.25);
  padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-top: 8px; }

/* buttons */
.btn {
  border: 1px solid rgba(255,255,255,0.14); background: rgba(255,255,255,0.05);
  color: var(--text); padding: 9px 16px; border-radius: 9px; font-size: 14px;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,0.10); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06250f; font-weight: 650; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: rgba(248,113,113,0.35); }
.btn.danger:hover { background: rgba(248,113,113,0.14); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* modal */
.overlay {
  position: fixed; inset: 0; background: rgba(3, 6, 12, 0.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  background: #0e1524; border: 1px solid rgba(255,255,255,0.14); border-radius: 16px;
  width: 100%; max-width: 560px; padding: 24px; box-shadow: 0 24px 70px rgba(0,0,0,0.55);
  animation: fade .18s ease;
}
.modal h3 { font-size: 17px; margin-bottom: 8px; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; line-height: 1.6; }
.keybox {
  font-family: var(--mono); background: rgba(0,0,0,0.45); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px; padding: 13px 14px; font-size: 13px; word-break: break-all;
  user-select: all; margin: 6px 0 16px; color: var(--accent); line-height: 1.6;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.download-details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; margin: 16px 0; font-size: 13px; }
.download-details dt { color: var(--muted); }
.download-details dd { margin: 0; }
.break-all { overflow-wrap: anywhere; }
.archive-preview { max-height: 220px; overflow: auto; margin: 8px 0 0; padding: 10px 12px 10px 28px; background: var(--bg); border: 1px solid var(--card-border); border-radius: 8px; font-size: 12px; line-height: 1.65; }
.modal-actions.left { justify-content: flex-start; }
.warn { color: var(--amber); font-size: 12.5px; }

.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 26px 0 34px; }

/* Logged-in management portal */
.portal-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 28px; align-items: start; }
.portal-nav { position: sticky; top: 76px; padding: 12px 0; border-right: 1px solid rgba(255,255,255,0.09); }
.nav-group + .nav-group { margin-top: 26px; }
.nav-group-title { padding: 0 14px 8px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.nav-item { display: block; width: 100%; border: 0; border-left: 3px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font: inherit; padding: 10px 14px; text-align: left; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.nav-item.active { border-left-color: var(--accent); background: var(--accent-dim); color: var(--accent); font-weight: 700; }
.portal-content { min-width: 0; }
.portal-page > .page-title { margin-top: 0; }
.model-config { display: flex; align-items: end; gap: 14px; margin-top: 18px; }
.model-config label { min-width: 250px; }
.model-config select { width: 100%; }

/* Cost page: one query strip, one result table, secondary pricing disclosure. */
.cost-intro { margin: -8px 0 24px; color: var(--muted); font-size: 13px; line-height: 1.7; }
#usage-card { padding: 0; overflow: hidden; border-radius: 12px; }
.usage-range { display: flex; align-items: center; gap: 20px; padding: 20px; flex-wrap: wrap; }
.usage-field, .usage-date-parts { display: flex; align-items: center; gap: 8px; }
.usage-field { color: var(--muted); font-size: 13px; white-space: nowrap; }
.usage-field label { margin: 0; }
.usage-range select { color-scheme: dark; height: 44px; padding: 0 10px; border: 1px solid #354052; border-radius: 7px; background: #101826; color: var(--text); font: inherit; cursor: pointer; }
.usage-range .btn { height: 44px; min-width: 80px; }
#page-cost :focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.usage-results { border-top: 1px solid var(--card-border); min-height: 180px; }
#usage-status { padding: 14px 20px; font-size: 12px; color: var(--muted); }
.cost-table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.usage-table { min-width: 840px; font-variant-numeric: tabular-nums; }
#page-cost .keys-table th { background: #111a28; padding: 12px; }
#page-cost .keys-table td { padding: 16px 12px; white-space: nowrap; }
.usage-table th:nth-child(n+3), .usage-table td.mono { text-align: right; }
.usage-table td:nth-child(2) { text-align: left; }
.usage-table tbody tr:not(.total-row):hover { background: rgba(255,255,255,.025); }
.total-row td { border-top: 1px solid #435065; font-weight: 700; background: #152130; }
.cost-note { border-top: 1px solid var(--card-border); padding: 16px 20px; color: var(--muted); font-size: 12px; line-height: 1.8; }
#usage-empty { padding: 28px 20px 40px; }
#usage-empty strong { color: var(--text); font-weight: 500; }
#usage-empty p { margin-top: 8px; }
#usage-error { padding: 16px 20px 28px; }
.cost-pricing { border-radius: 12px; padding: 18px 20px; }
.cost-pricing summary { cursor: pointer; font-size: 14px; }
.cost-pricing summary span { color: var(--muted); font-size: 12px; margin-left: 12px; }
.cost-pricing[open] summary { margin-bottom: 20px; }
.cost-pricing .keys-table { min-width: 760px; }
.pill-mini { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 11px; background: rgba(255,255,255,0.09); color: var(--muted); }
.pill-mini.warn { background: rgba(255,193,7,0.15); color: var(--amber); }
@media (max-width: 1050px) and (min-width: 761px) {
  .usage-range { gap: 12px; padding: 16px 12px; }
  .usage-range select { padding: 0 6px; }
}
@media (max-width: 560px) {
  .usage-range { gap: 12px; padding: 16px; }
  .usage-range .usage-field:nth-child(2) { order: 3; width: 100%; }
  .usage-range .btn { margin-left: auto; }
  .usage-date-parts { flex: 1; }
  .usage-date-parts select { flex: 1; min-width: 0; }
  .cost-pricing summary span { display: block; margin: 8px 0 0; }
}

@media (max-width: 760px) {
  .download-card { align-items: flex-start; flex-direction: column; }
  .svc-grid { grid-template-columns: 1fr; }
  .quota-details { grid-template-columns: 1fr; }
  .portal-layout { display: block; }
  .portal-nav { position: static; display: flex; gap: 16px; border-right: 0; border-bottom: 1px solid rgba(255,255,255,0.09); margin-bottom: 24px; padding-bottom: 12px; }
  .nav-group { flex: 1; }
  .nav-group + .nav-group { margin-top: 0; }
  .model-config { align-items: stretch; flex-direction: column; }
  .model-config label { min-width: 0; }
}
