:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --text: #171b22;
  --muted: #667085;
  --line: #d7dde6;
  --line-soft: #e8edf3;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #e6f7f4;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warning: #b54708;
  --warning-soft: #fff7ed;
  --success: #047857;
  --success-soft: #ecfdf3;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 30px rgba(15, 23, 42, .045);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: radial-gradient(circle at top left, rgba(15, 118, 110, .07), transparent 310px), var(--bg); }
a { color: inherit; text-decoration: none; }
.topbar { height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 32px; border-bottom: 1px solid rgba(215, 221, 230, .88); background: rgba(255,255,255,.9); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 780; font-size: 17px; letter-spacing: 0; }
.nav { display: flex; align-items: center; gap: 8px; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 24px 56px; }
.hero { min-height: 360px; display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.hero-copy { max-width: 760px; }
.eyebrow { color: var(--primary); font-weight: 700; }
h1 { font-size: 44px; line-height: 1.12; margin: 10px 0 16px; }
h2 { font-size: 21px; margin: 0 0 14px; letter-spacing: 0; }
h3 { margin: 0 0 10px; }
p { color: var(--muted); line-height: 1.65; }
.actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.actions form { margin: 0; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 8px 13px; font-weight: 680; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; min-height: 36px; box-shadow: 0 1px 0 rgba(15, 23, 42, .03); transition: background .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease; }
.btn:hover { border-color: #b8c2d0; background: #f8fafc; box-shadow: 0 4px 14px rgba(15, 23, 42, .06); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: white; box-shadow: 0 8px 18px rgba(15, 118, 110, .18); }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { color: var(--text); background: transparent; box-shadow: none; }
.btn.ghost:hover { background: #eef2f6; }
.btn.small { min-height: 28px; padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.btn.danger { color: var(--danger); border-color: #f1b6b0; background: var(--danger-soft); }
.btn.danger:hover { border-color: #f97066; background: #ffe5e2; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(15, 118, 110, .18); outline-offset: 2px; }
.section, .panel { margin-top: 24px; }
.grid { display: grid; gap: 16px; }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card, .price-card, .metric, .panel, .form-card { background: rgba(255, 255, 255, .98); border: 1px solid var(--line); border-radius: 8px; padding: 16px; box-shadow: var(--shadow); }
.panel { padding: 18px; }
.card.wide { max-width: 560px; }
.price-card .price { color: var(--text); font-size: 24px; font-weight: 800; margin: 0; }
.price-card ul { padding-left: 18px; color: var(--muted); line-height: 1.8; }
.addon, .notice, .error { margin-top: 16px; border-radius: 6px; padding: 12px 14px; }
.addon, .notice { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.error { background: #fef3f2; color: var(--danger); border: 1px solid #fecdca; }
.auth-panel, .status-page { min-height: 560px; display: grid; place-items: center; }
.form-card { width: min(100%, 420px); }
label { display: grid; gap: 7px; margin: 12px 0; color: #344054; font-weight: 650; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 9px 10px; font: inherit; background: white; transition: border-color .16s ease, box-shadow .16s ease; }
input:hover, textarea:hover, select:hover { border-color: #b8c2d0; }
.muted { color: var(--muted); }
.dashboard-head { margin-bottom: 16px; display: flex; justify-content: space-between; gap: 18px; align-items: end; }
.dashboard-head h1 { font-size: 30px; margin-bottom: 4px; }
.dashboard-head p { margin: 0; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { padding: 14px 15px; }
.metric span { color: var(--muted); display: block; margin-bottom: 7px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; }
.metric strong { font-size: 21px; line-height: 1.2; }
.tag { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px; margin: 0 5px 5px 0; background: white; color: #344054; font-size: 12px; font-weight: 650; }
.admin-nav { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 16px; padding: 4px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255, 255, 255, .72); width: fit-content; }
.admin-nav .btn { min-height: 32px; }
.feature-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.feature { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 5px; background: white; }
.feature span { color: var(--muted); font-size: 13px; }
.feature.enabled { border-color: #99f6e4; background: var(--primary-soft); }
.feature.enabled span { color: #0f766e; }
.feature.disabled { opacity: .62; background: #f9fafb; }
.upload-form { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(260px, 380px); gap: 16px; align-items: stretch; }
.drop-zone { margin: 0; min-height: 176px; border: 1.5px dashed #8ca4b8; border-radius: 8px; background: linear-gradient(180deg, #fbfdfd, #f5f8fb); display: grid; place-items: center; align-content: center; gap: 8px; padding: 22px; text-align: center; cursor: pointer; position: relative; overflow: hidden; }
.drop-zone::before { content: ""; width: 42px; height: 42px; border-radius: 12px; background: var(--primary-soft); border: 1px solid #b7ebe4; box-shadow: inset 0 -8px 18px rgba(15, 118, 110, .08); }
.drop-zone strong { font-size: 16px; }
.drop-zone span { color: var(--muted); font-weight: 500; }
.drop-zone input { width: auto; max-width: 100%; }
.drop-zone.dragging { border-color: var(--primary); background: #f0fdfa; box-shadow: inset 0 0 0 1px rgba(15, 118, 110, .18); }
.upload-side { display: grid; gap: 12px; align-content: space-between; }
.file-list { --upload-file-row-height: 52px; list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: calc(var(--upload-file-row-height) * 5 + 8px * 4); overflow-y: auto; scrollbar-gutter: stable; }
.file-list li { min-height: var(--upload-file-row-height); border: 1px solid var(--line-soft); border-radius: 7px; background: white; padding: 9px 10px; display: grid; grid-template-columns: minmax(120px, 1fr) auto auto; gap: 9px; align-items: center; }
.file-list strong { overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.file-list span { color: var(--muted); font-size: 13px; }
.file-list em { font-style: normal; font-size: 13px; font-weight: 700; color: var(--muted); }
.file-list li.valid { border-color: #a7f3d0; background: var(--success-soft); }
.file-list li.valid em { color: #047857; }
.file-list li.invalid { border-color: #fecdca; background: #fff6f5; }
.file-list li.invalid em { color: var(--danger); }
.filter-form { display: grid; grid-template-columns: minmax(180px, 1fr) 150px 150px 150px 150px auto auto; gap: 12px; align-items: end; }
.filter-form label { margin: 0; }
.filter-form .wide { grid-column: 1 / -1; }
.form-section-title { font-weight: 700; color: var(--ink); margin-top: 8px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: white; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 920px; }
th, td { text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--line-soft); vertical-align: top; overflow-wrap: anywhere; }
th { background: #f8fafc; color: #475467; font-size: 12px; font-weight: 760; white-space: nowrap; }
td { font-size: 14px; }
tbody tr:hover td { background: #fbfcfe; }
tr:last-child td { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); }
.actions-cell { width: 190px; min-width: 190px; max-width: 230px; }
.action-grid { display: grid; grid-template-columns: repeat(2, minmax(78px, 1fr)); gap: 6px; align-items: stretch; }
.action-grid form { display: contents; }
.action-grid .btn { width: 100%; min-width: 0; text-align: center; white-space: normal; line-height: 1.25; }
.actions-cell input { width: 86px; padding: 6px 8px; }
.actions-cell select { width: 108px; padding: 6px 8px; }
.actions-cell .inline-admin-form { display: flex; grid-column: 1 / -1; align-items: center; flex-wrap: wrap; padding: 5px; border: 1px solid var(--line); border-radius: 7px; background: #f9fafb; }
.actions-cell .inline-admin-form input[name="admin_note"] { width: 138px; }
.inline-check { display: inline-flex; grid-auto-flow: column; align-items: center; gap: 4px; margin: 0; color: #344054; font-size: 12px; white-space: nowrap; }
.inline-check input { width: auto; }
.mini-help { color: var(--muted); font-size: 12px; display: inline-block; max-width: min(520px, 70vw); white-space: normal; overflow-wrap: anywhere; vertical-align: middle; }
.admin-dialog { width: min(92vw, 520px); border: 1px solid var(--line); border-radius: 8px; padding: 0; }
.admin-dialog::backdrop { background: rgba(15, 23, 42, .32); }
.dialog-form { padding: 20px; display: grid; gap: 12px; }
.dialog-form h3 { margin-bottom: 4px; }
.dialog-form label { margin: 0; }
.code-block { white-space: pre-wrap; word-break: break-word; margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 6px; background: #f9fafb; color: #344054; max-height: 420px; overflow: auto; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; }
.detail-grid p { margin: 0; display: grid; gap: 4px; }
.detail-grid strong { color: var(--text); }
.status-badge { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); background: #f8fafc; color: #475467; font-size: 12px; font-weight: 760; white-space: nowrap; }
.status-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .85; }
.status-completed, .status-succeeded, .status-valid, .status-enabled, .status-available { border-color: #b7e4c7; background: var(--success-soft); color: var(--success); }
.status-running, .status-in-use, .status-probation { border-color: #99f6e4; background: var(--primary-soft); color: var(--primary); }
.status-queued, .status-waiting-for-key, .status-retrying, .status-unknown { border-color: #fed7aa; background: var(--warning-soft); color: var(--warning); }
.status-paused, .status-disabled, .status-unavailable { border-color: #d0d5dd; background: #f2f4f7; color: #667085; }
.status-failed, .status-invalid, .status-exhausted, .status-cooldown { border-color: #fecdca; background: var(--danger-soft); color: var(--danger); }

.api-token-page { display: grid; gap: 16px; }
.api-token-page .notice, .api-token-page .error { margin-top: 0; }
.api-token-head { margin-bottom: 0; }
.api-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.api-summary-item { min-height: 94px; display: grid; align-content: space-between; gap: 8px; padding: 14px 15px; border: 1px solid var(--line); border-radius: 8px; background: linear-gradient(180deg, #ffffff, #fbfcfd); box-shadow: var(--shadow); }
.api-summary-item span { color: var(--muted); font-size: 12px; font-weight: 760; text-transform: uppercase; letter-spacing: .02em; }
.api-summary-item strong { color: var(--text); font-size: 22px; line-height: 1.15; }
.api-summary-item strong.status-badge { width: fit-content; font-size: 12px; }
.api-summary-item em { color: var(--muted); font-style: normal; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-title-row h2 { margin-bottom: 0; }
.panel-title-row .muted { font-size: 13px; }
.api-settings-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; align-items: end; }
.api-settings-form label, .api-add-token-form label { margin: 0; }
.api-settings-form .wide, .api-add-token-form .wide, .api-form-actions { grid-column: 1 / -1; }
.api-settings-form textarea { min-height: 132px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.55; }
.api-settings-form input[type="checkbox"] { width: auto; }
.api-clear-check { align-self: center; padding: 10px 12px; border: 1px solid var(--line-soft); border-radius: 7px; background: #f9fafb; }
.api-form-actions { display: flex; justify-content: flex-end; padding-top: 2px; }
.api-tools-grid { display: grid; grid-template-columns: minmax(280px, .82fr) minmax(360px, 1.18fr); gap: 16px; align-items: start; }
.api-test-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.api-test-actions form { margin: 0; }
.api-test-actions .btn { width: 100%; min-height: 42px; }
.api-add-token-form { display: grid; grid-template-columns: minmax(140px, .7fr) minmax(180px, 1fr); gap: 12px; align-items: end; }
.api-add-token-form .btn { justify-self: end; min-width: 112px; }
.token-table-panel table { min-width: 1040px; }
.model-state-panel table { min-width: 1080px; }
.token-table-panel th:nth-child(1), .token-table-panel td:nth-child(1) { width: 110px; }
.token-table-panel th:nth-child(3), .token-table-panel td:nth-child(3) { width: 150px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.token-table-panel th:nth-child(4), .token-table-panel td:nth-child(4), .token-table-panel th:nth-child(5), .token-table-panel td:nth-child(5), .token-table-panel th:nth-child(6), .token-table-panel td:nth-child(6) { width: 118px; }
.token-table-panel th:nth-child(7), .token-table-panel td:nth-child(7) { width: 156px; }
.token-table-panel .actions-cell { width: 220px; min-width: 220px; }

@media (max-width: 900px) {
  .grid.four, .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .api-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .api-settings-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .api-tools-grid { grid-template-columns: 1fr; }
  h1 { font-size: 34px; }
  .topbar { padding: 0 18px; }
}

@media (max-width: 620px) {
  main { padding: 22px 14px 48px; }
  .grid.four, .metrics { grid-template-columns: 1fr; }
  .feature-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .upload-form { grid-template-columns: 1fr; }
  .file-list li { grid-template-columns: 1fr; }
  .filter-form { grid-template-columns: 1fr; }
  .api-summary, .api-settings-form, .api-test-actions, .api-add-token-form { grid-template-columns: 1fr; }
  .panel-title-row { display: grid; gap: 4px; }
  .api-form-actions, .api-add-token-form .btn { justify-content: stretch; justify-self: stretch; }
  h1 { font-size: 28px; }
  .nav { gap: 6px; }
  .btn { padding: 8px 10px; }
}
