@font-face { font-family: "Playfair Display"; src: url("/static/pf-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Playfair Display"; src: url("/static/pf-800.woff2") format("woff2"); font-weight: 800; font-display: swap; }

:root {
  --bg: #fafaf9; --card: #ffffff; --text: #111111; --muted: #6b6b6b; --line: #e7e7e4; --soft: #f3f3f1;
  --bad: #b42318; --bad-bg: #fdecea;
  --green: #1f7a5a; --green-bg: #e7f4ee;
  --amber: #a15c07; --amber-bg: #fdf2dc;
  --blue: #2457b3; --blue-bg: #e9effb;
  --gray: #6b6b6b; --gray-bg: #efefed;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* buttons */
button { font: inherit; cursor: pointer; }
.primary, .ghost, .danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 18px; border-radius: 999px; font-weight: 600; white-space: nowrap;
  transition: opacity .15s, background .15s, border-color .15s;
}
.primary { background: var(--text); color: #fff; border: 0; }
.primary:hover { opacity: .85; }
.danger { background: var(--bad); color: #fff; border: 0; }
.danger:hover { opacity: .9; }
.ghost { background: var(--card); color: var(--text); border: 1.5px solid var(--line); }
.ghost:hover { border-color: #c9c9c5; }
.sm { min-height: 34px; padding: 0 14px; font-size: 14px; }
.wide { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--text); text-decoration: underline; font-size: 14px; }
button[disabled] { opacity: .45; cursor: default; }
.icon { width: 34px; height: 34px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); display: inline-grid; place-items: center; }
.icon:hover { background: var(--soft); color: var(--text); }
.icon.del:hover { background: var(--bad-bg); color: var(--bad); }
.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* header */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.bar { height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font: 700 15px/1 var(--serif); letter-spacing: .2em; text-transform: uppercase; color: var(--text); text-decoration: none; }
.brand span { font-family: var(--sans); font-size: 11px; letter-spacing: .08em; font-weight: 600; color: var(--muted); margin-left: 6px; padding: 3px 8px; border-radius: 999px; background: var(--soft); vertical-align: 2px; }
.who { display: flex; align-items: center; gap: 12px; font-size: 14px; }

.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 36px 0 22px; flex-wrap: wrap; }
h1 { font: 800 clamp(34px, 5vw, 44px)/1.05 var(--serif); letter-spacing: -.01em; margin: 0; }
.head p { margin: 6px 0 0; }

/* status cards */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.stat {
  text-align: left; background: var(--card); border: 1.5px solid var(--line); border-radius: 16px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; font-weight: 500;
}
.stat b { color: var(--text); font: 800 26px/1.1 var(--serif); }
.stat:hover { border-color: #c9c9c5; }
.stat[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 3px rgba(17,17,17,.06); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.active { background: var(--green); } .dot.expiring { background: #d98a1b; }
.dot.upcoming { background: var(--blue); } .dot.expired { background: #a3a3a3; }

/* toolbar */
.toolbar { display: flex; gap: 10px; margin: 18px 0 10px; }
.search { flex: 1; position: relative; display: block; }
.search svg { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input { width: 100%; min-height: 44px; border: 1.5px solid var(--line); border-radius: 999px; background: var(--card); padding: 0 16px 0 42px; font: inherit; color: var(--text); }
.search input:focus { outline: 0; border-color: var(--text); }
#fcount { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 999px; background: var(--text); color: #fff; font-size: 12px; padding: 0 6px; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 24px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; }
.filters fieldset { border: 0; margin: 0; padding: 0; display: flex; gap: 8px; align-items: flex-end; }
.filters legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; padding: 0; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; }
input[type=date], input[type=email], input[type=password], input:not([type]) {
  min-height: 40px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 10px; font: inherit; color: var(--text); background: #fff;
}
input:focus { outline: 0; border-color: var(--text); }
input[aria-invalid="true"] { border-color: var(--bad); }

/* table */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; }
.table { overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fcfcfb; }
th.r, td.r { text-align: right; }
.sort { background: none; border: 0; padding: 0; font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit; display: inline-flex; gap: 4px; align-items: center; }
.sort:hover, .sort[data-dir] { color: var(--text); }
.sort[data-dir="asc"]::after { content: "↑"; }
.sort[data-dir="desc"]::after { content: "↓"; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfb; }
td.email { font-weight: 600; word-break: break-all; }
td.date { white-space: nowrap; }
td.left { white-space: nowrap; color: var(--muted); font-size: 14px; }
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.active { color: var(--green); background: var(--green-bg); }
.badge.expiring { color: var(--amber); background: var(--amber-bg); }
.badge.upcoming { color: var(--blue); background: var(--blue-bg); }
.badge.expired { color: var(--gray); background: var(--gray-bg); }
.rowact { display: inline-flex; gap: 2px; }
.empty { text-align: center; padding: 48px 16px; }
.empty-title { font: 700 20px/1.3 var(--serif); margin: 0 0 4px; }
.empty p { margin: 0; }
.loading tbody { opacity: .5; }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 14px 0 48px; font-size: 14px; }
.pager div { display: flex; gap: 8px; }

/* dialogs */
dialog { border: 0; border-radius: 20px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 30px 80px -20px rgba(0,0,0,.35); color: var(--text); }
dialog::backdrop { background: rgba(17,17,17,.35); }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { font: 800 26px/1.15 var(--serif); margin: 0 0 4px; }
dialog p { margin: 0; }
dialog label, .login label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
dialog input { width: 100%; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; }
.chip:hover { border-color: var(--text); }
.hint { font-size: 13px; min-height: 1em; }
.err { color: var(--bad); font-size: 14px; min-height: 0; }
.err:empty { display: none; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--text); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; background: #fff; }
.login { width: min(380px, calc(100vw - 32px)); text-align: center; padding: 32px 0; }
.login .brand { display: block; color: var(--muted); margin: 0 0 14px; }
.login h1 { font-size: 48px; margin-bottom: 28px; }
.login form { padding: 24px; display: flex; flex-direction: column; gap: 14px; text-align: left; box-shadow: 0 24px 60px -36px rgba(0,0,0,.25); }
.login input { width: 100%; }

/* mobile */
@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats .stat:first-child { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  .who .muted { display: none; }
  thead { display: none; }
  table, tbody, tr, td { display: block; }
  tbody tr { padding: 12px 14px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; }
  td { padding: 0; border: 0; }
  td.email { grid-column: 1 / 2; }
  td.status { grid-column: 2; grid-row: 1; text-align: right; }
  td.date, td.left { font-size: 13px; color: var(--muted); grid-column: 1 / -1; }
  td.date::before { content: attr(data-label) " "; font-weight: 600; }
  td.r { grid-column: 1 / -1; text-align: left; }
  .filters fieldset { flex-wrap: wrap; }
}

/* nav tabs */
.bar { gap: 20px; }
.tabs { display: flex; gap: 4px; margin-right: auto; }
.tabs a { padding: 7px 14px; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; }
.tabs a:hover { color: var(--text); background: var(--soft); }
.tabs a[aria-current="page"] { color: var(--text); background: var(--soft); }

/* settings */
.narrow { max-width: 880px; }
.panel { padding: 22px; margin-bottom: 18px; }
.panel h2 { font: 800 24px/1.2 var(--serif); margin: 0 0 6px; }
.panel h3 { font-size: 15px; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.panel .table { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-top: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.stack label, .confirm { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.stack button { align-self: flex-start; }
.small { font-size: 13px; margin: 0; }
.row2fa { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.row2fa p { margin: 0; }
.list { list-style: none; margin: 12px 0 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .meta { font-size: 13px; color: var(--muted); }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--text); color: #fff; margin-left: 6px; vertical-align: 1px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; font-family: ui-monospace, monospace; }
.checkrow { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 500 !important; font-size: 14px !important; cursor: pointer; }
.checkrow input { width: auto !important; min-height: 0; accent-color: var(--text); }
.confirm { padding-top: 12px; border-top: 1px solid var(--line); }

/* login steps */
.lead { margin: 0; font-size: 15px; }
.steps { margin: 0; padding-left: 20px; font-size: 14px; color: var(--muted); }
.steps li { margin: 2px 0; }
.qr { display: block; margin: 4px auto; width: 200px; height: 200px; border: 1px solid var(--line); border-radius: 12px; }
.secret { text-align: center; font-size: 13px; margin: 0; }
.secret code { font: 600 13px ui-monospace, monospace; background: var(--soft); padding: 3px 8px; border-radius: 6px; word-break: break-all; }
input.code { font: 700 24px/1 ui-monospace, monospace !important; letter-spacing: .4em; text-align: center; min-height: 54px !important; }
.login .link.back { align-self: center; color: var(--muted); }

@media (max-width: 760px) {
  .bar { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; }
  .tabs { order: 3; width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  .row2fa { flex-direction: column; align-items: flex-start; }
}

/* platform: models + gateway */
input[type=number], select {
  min-height: 40px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 10px; font: inherit; color: var(--text); background: #fff; width: 100%;
}
select:focus, input[type=number]:focus { outline: 0; border-color: var(--text); }
dialog.wide-dlg { width: min(640px, calc(100vw - 32px)); }
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.gw-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; margin-top: 12px; }
.gw-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.status-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 0; padding: 0; list-style: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge.byok { color: var(--blue); background: var(--blue-bg); }
.badge.unified { color: var(--amber); background: var(--amber-bg); }
.badge.off { color: var(--gray); background: var(--gray-bg); }
.table-scroll { overflow-x: auto; }
@media (max-width: 640px) { .three, .two { grid-template-columns: 1fr; } }
.actions.left { justify-content: flex-start; margin-top: 12px; }
.checkrow.endcell { align-self: end; min-height: 40px; }
.after-table { margin-top: 10px; }

/* ---------------------------------------------------------------- dashboard */
.balance-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--soft); font-weight: 700; font-size: 14px; white-space: nowrap; }
.balance-pill span { color: var(--muted); font-weight: 600; }
.view[hidden] { display: none !important; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric { padding: 18px; }
.metric span { display: block; color: var(--muted); font-size: 13px; font-weight: 600; }
.metric b { display: block; font: 800 28px/1.2 var(--serif); margin-top: 6px; font-variant-numeric: tabular-nums; }
.metric small { color: var(--muted); font-size: 12.5px; }
pre.code { background: #111; color: #f3f3f1; border-radius: 12px; padding: 14px 16px; overflow-x: auto; font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 0; white-space: pre; }
.codehead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 14px 0 6px; }
.codehead b { font-size: 13px; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.presets .chip[aria-pressed="true"] { border-color: var(--text); background: var(--text); color: #fff; }
.topup-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.topup-row label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; flex: 1; min-width: 180px; }
.newkey { display: flex; gap: 8px; align-items: center; background: var(--soft); border-radius: 12px; padding: 10px 12px; }
.newkey code { flex: 1; font: 13px/1.4 ui-monospace, monospace; word-break: break-all; }
.warnbox { background: var(--amber-bg); color: var(--amber); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; font-weight: 600; }
.okbox { background: var(--green-bg); color: var(--green); border-radius: 12px; padding: 10px 12px; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.filters-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 12px; }
.filters-row label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; min-width: 140px; }
.totals { display: flex; flex-wrap: wrap; gap: 18px; margin: 0 0 12px; font-size: 14px; }
.totals b { font-variant-numeric: tabular-nums; }
.models-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px; max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.badge.pending { color: var(--blue); background: var(--blue-bg); }
.badge.paid { color: var(--green); background: var(--green-bg); }
.badge.failed, .badge.cancelled, .badge.refunded, .badge.err { color: var(--bad); background: var(--bad-bg); }
.badge.expired, .badge.review { color: var(--gray); background: var(--gray-bg); }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); padding: 28px; }
.auth-card h1 { font: 800 30px/1.15 var(--serif); margin: 6px 0 6px; }
.auth-card .brand { display: inline-block; margin-bottom: 8px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.auth-card input { width: 100%; }
.auth-card .primary { width: 100%; justify-content: center; }
.auth-links { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; margin-top: 14px; }
.auth-links a, a.link-plain { color: var(--text); }
.copybtn { flex-shrink: 0; }
.tabs { overflow-x: auto; }
@media (max-width: 720px) {
  .bar { flex-wrap: wrap; row-gap: 8px; height: auto; padding: 10px 0; }
  .tabs { order: 3; width: 100%; }
  .metric b { font-size: 24px; }
}
a.primary, a.ghost { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
