:root {
  --surface:#ffffff; --surface-2:#f7f8fa; --border:#e5e7eb;
  --text:#111111; --text-2:#6b7280;
  --accent:#2264e2; --accent-bg:#eff4fe;
  --cta:#111111; --danger:#dc2626; --success:#16a34a;
  --radius:12px; --radius-lg:16px;
  --font-display:'ZonaPro',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  --font-body:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;
  --font-mono:ui-monospace,SFMono-Regular,Menlo,monospace;
}

@font-face {
    font-family: 'ZonaPro';
    src: url('/ui/fonts/ZonaPro-SemiBold.otf') format('opentype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'ZonaPro';
    src: url('/ui/fonts/ZonaPro-Bold.otf') format('opentype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* ─── Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface-2);
}

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--text);
    margin: 0 0 8px;
}
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; font-weight: 600; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.noscript-note {
    max-width: 1152px;
    margin: 32px auto;
    padding: 16px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

/* ─── Header ─────────────────────────────────────── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 1152px;
    margin: 0 auto;
    padding: 0 16px;
    min-height: 60px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 16px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    color: var(--text);
    text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-pin { flex: 0 0 auto; display: block; }
.wordmark {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-nav {
    order: 3;
    width: 100%;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    scrollbar-width: none;
}
.header-nav:empty { display: none; }
.header-nav::-webkit-scrollbar { display: none; }

.nav-tab {
    flex: 0 0 auto;
    padding: 6px 14px;
    border-radius: 999px;
    border: none;
    background: transparent;
    color: var(--text-2);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.nav-tab:hover { color: var(--text); text-decoration: none; }
.nav-tab.active { background: var(--accent-bg); color: var(--accent); }

.account-chip {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 12px;
}

.lang-pill {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    overflow: hidden;
}
.lang-pill button {
    border: none;
    background: transparent;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    padding: 4px 10px;
    cursor: pointer;
}
.lang-pill button.active { background: var(--accent-bg); color: var(--accent); }

/* ─── Layout ─────────────────────────────────────── */
.container {
    max-width: 1152px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

.view-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}
.view-head h1 { margin: 0; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}
.card + .card { margin-top: 16px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }

.muted { color: var(--text-2); }
.small { font-size: 13px; }
.mono { font-family: var(--font-mono); font-size: 13px; }

/* ─── Buttons ────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 999px;
    border: 1px solid transparent;
    padding: 9px 20px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: opacity 0.15s ease, background 0.15s ease;
}
.btn:hover { text-decoration: none; }

.btn-primary { background: var(--cta); color: #ffffff; }
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost {
    background: transparent;
    color: var(--text-2);
    padding: 6px 10px;
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-danger-ghost {
    background: transparent;
    color: var(--danger);
    border-color: transparent;
    padding: 6px 10px;
}
.btn-danger-ghost:hover { background: rgba(220, 38, 38, 0.06); }

.btn-danger {
    background: var(--danger);
    color: #ffffff;
}
.btn-danger:hover { opacity: 0.85; }

.btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-block { width: 100%; }
.btn-sm { padding: 5px 14px; font-size: 13px; }

/* ─── Forms ──────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text);
}
.field .hint { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.field-error { font-size: 12px; color: var(--danger); margin-top: 4px; }

.input, select.input, textarea.input {
    width: 100%;
    padding: 9px 12px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}
.input.invalid { border-color: var(--danger); }

.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 64px; }
.pw-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 999px;
}
.pw-toggle:hover { color: var(--text); }

.code-input {
    font-family: var(--font-mono);
    font-size: 26px;
    letter-spacing: 0.5em;
    text-align: center;
    text-indent: 0.5em;
    padding: 12px;
}

/* ─── Auth views ─────────────────────────────────── */
.auth-wrap {
    max-width: 420px;
    margin: 32px auto 0;
}
.auth-card { padding: 28px 24px; }
.auth-card h1 { font-size: 22px; margin-bottom: 20px; }
.auth-foot {
    margin-top: 16px;
    text-align: center;
    font-size: 14px;
    color: var(--text-2);
}
.auth-foot + .auth-foot { margin-top: 8px; }

/* ─── Banners / chips ────────────────────────────── */
.banner {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
}
.banner-error {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.25);
    color: var(--danger);
}
.banner-info {
    background: var(--accent-bg);
    border-color: rgba(34, 100, 226, 0.25);
    color: var(--accent);
}
.banner-warn {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.3);
    color: var(--danger);
    font-weight: 600;
}

.chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.chip-blue { background: var(--accent-bg); color: var(--accent); }
.chip-gray { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.chip-green { background: rgba(22, 163, 74, 0.1); color: var(--success); }
.chip-red { background: rgba(220, 38, 38, 0.08); color: var(--danger); }

/* ─── Plan banner (dashboard) ────────────────────── */
.plan-banner {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 16px;
}
.plan-banner-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.plan-banner-right { flex: 1; min-width: 220px; }

.quota-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 6px;
    gap: 8px;
}
.quota-track {
    height: 8px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    overflow: hidden;
}
.quota-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
    transition: width 0.3s ease;
}

/* ─── Tables ─────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
table.data th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-2);
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; }
tr.row-inactive td { opacity: 0.5; }

/* ─── Empty states ───────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-2);
}
.empty-state svg { display: block; margin: 0 auto 12px; }
.empty-state h3 { color: var(--text); }
.empty-state .btn { margin-top: 12px; }

/* ─── Skeletons ──────────────────────────────────── */
@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.skeleton {
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--surface-2) 25%, #eef0f3 50%, var(--surface-2) 75%);
    background-size: 800px 100%;
    animation: shimmer 1.4s infinite linear;
}
.skeleton-line { height: 16px; margin-bottom: 12px; }
.skeleton-block { height: 120px; margin-bottom: 16px; }

/* ─── Spinner ────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: -3px;
}

/* ─── Modals ─────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(17, 17, 17, 0.45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px;
    overflow-y: auto;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 460px;
    margin: auto 0;
}
.modal-wide { max-width: 540px; }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.key-block {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin: 12px 0;
}
.key-block code {
    font-family: var(--font-mono);
    font-size: 13px;
    word-break: break-all;
    flex: 1;
}

pre.code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    overflow-x: auto;
    margin: 8px 0 0;
    white-space: pre;
}

/* ─── Toasts ─────────────────────────────────────── */
.toast-root {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.toast {
    background: var(--cta);
    color: #ffffff;
    font-size: 13px;
    padding: 9px 16px;
    border-radius: 999px;
    animation: toast-in 0.2s ease;
    max-width: 90vw;
}
.toast.error { background: var(--danger); }

/* ─── Usage view ─────────────────────────────────── */
.usage-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.usage-controls select.input { width: auto; min-width: 200px; }

.range-pills { display: inline-flex; gap: 4px; }
.range-pill {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    border-radius: 999px;
    padding: 5px 14px;
    cursor: pointer;
}
.range-pill.active {
    background: var(--accent-bg);
    color: var(--accent);
    border-color: rgba(34, 100, 226, 0.35);
}

.chart-box { position: relative; height: 300px; }

/* ─── Billing ────────────────────────────────────── */
.months-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.months-row .label { font-size: 14px; font-weight: 600; }

.plans-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 24px;
}
.plan-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.plan-card.current { box-shadow: 0 0 0 2px var(--accent); border-color: var(--accent); }
.plan-card .current-badge {
    position: absolute;
    top: -10px;
    right: 14px;
}
.plan-name { font-family: var(--font-display); font-weight: 700; font-size: 17px; }
.plan-price { font-size: 22px; font-weight: 700; margin: 4px 0; }
.plan-price .per { font-size: 13px; font-weight: 400; color: var(--text-2); }
.plan-feats {
    list-style: none;
    margin: 4px 0 12px;
    padding: 0;
    font-size: 13px;
    color: var(--text-2);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.plan-card .btn { margin-top: auto; }

/* ─── QPay modal ─────────────────────────────────── */
.qpay-amount {
    font-size: 26px;
    font-weight: 700;
    text-align: center;
    margin: 4px 0 12px;
}
.qpay-body { display: flex; flex-direction: column; gap: 16px; }
.qpay-qr { order: 1; text-align: center; }
.qpay-qr img {
    width: 200px;
    height: 200px;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #ffffff;
}
.qpay-banks { order: 2; }
.qpay-banks h3 { margin-bottom: 8px; }
.bank-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.bank-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 8px 10px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
}
.bank-btn:hover { background: var(--surface-2); text-decoration: none; }
.bank-btn img {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: contain;
    flex: 0 0 auto;
}
.bank-btn span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qpay-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-2);
    margin-top: 16px;
    min-height: 24px;
    text-align: center;
}
.qpay-status.ok { color: var(--success); font-weight: 600; }
.qpay-status.bad { color: var(--danger); font-weight: 600; }

@media (max-width: 640px) {
    .qpay-banks { order: 0; }
    .qpay-qr { order: 1; }
}

/* ─── Settings ───────────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.profile-row { display: flex; gap: 8px; font-size: 14px; padding: 6px 0; }
.profile-row .k { color: var(--text-2); min-width: 130px; flex: 0 0 auto; }
.profile-row .v { word-break: break-word; }

/* ─── Responsive tables → cards (mobile) ─────────── */
@media (max-width: 640px) {
    table.data.resp thead { display: none; }
    table.data.resp, table.data.resp tbody, table.data.resp tr, table.data.resp td { display: block; width: 100%; }
    table.data.resp tr {
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 10px;
        padding: 6px 0;
    }
    table.data.resp tr:hover { background: transparent; }
    table.data.resp td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        border-bottom: none;
        padding: 6px 12px;
        text-align: right;
    }
    table.data.resp td.num { text-align: right; }
    table.data.resp td::before {
        content: attr(data-label);
        font-size: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: var(--text-2);
        text-align: left;
    }
    table.data.resp td.no-label { justify-content: flex-end; }
    table.data.resp td.no-label::before { content: none; }
}

/* ─── Breakpoints up ─────────────────────────────── */
@media (min-width: 640px) {
    .container { padding: 32px 24px 72px; }
    .header-inner { padding: 0 24px; }
    .plan-banner { flex-direction: row; align-items: center; justify-content: space-between; }
    .plans-grid { grid-template-columns: repeat(2, 1fr); }
    .settings-grid { grid-template-columns: repeat(2, 1fr); align-items: start; }
    .account-chip { max-width: 220px; }
}

@media (min-width: 1024px) {
    .header-inner { flex-wrap: nowrap; }
    .header-nav {
        order: 0;
        width: auto;
        padding-bottom: 0;
        margin-left: 24px;
    }
    .header-right { order: 1; }
    .plans-grid { grid-template-columns: repeat(4, 1fr); }
    .chart-box { height: 340px; }
}
