/* Merchant web pages: login + dashboard. No external dependencies (CSP-safe). */
:root {
    --brand: #2563eb;
    --brand-hover: #1d4ed8;
    --brand-soft: #eff6ff;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #64748b;
    --success: #047857;
    --success-soft: #ecfdf5;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --danger: #b91c1c;
    --danger-soft: #fef2f2;
    --focus: 0 0 0 3px rgba(37, 99, 235, 0.3);
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.06);
    --radius: 12px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light;
}

/* Dark palette: follows the device (FRONTEND_THEME=auto) unless the page forces
   data-theme="light" or "dark" on <html>. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --brand: #3b82f6;
        --brand-hover: #60a5fa;
        --brand-soft: #172554;
        --bg: #0b1120;
        --surface: #111827;
        --surface-2: #0f172a;
        --border: #1f2937;
        --text: #f1f5f9;
        --text-2: #cbd5e1;
        --text-3: #94a3b8;
        --success: #34d399;
        --success-soft: #052e22;
        --warning: #fbbf24;
        --warning-soft: #2d1d05;
        --danger: #f87171;
        --danger-soft: #2c0b0b;
        --focus: 0 0 0 3px rgba(59, 130, 246, 0.4);
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --brand: #3b82f6;
    --brand-hover: #60a5fa;
    --brand-soft: #172554;
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #0f172a;
    --border: #1f2937;
    --text: #f1f5f9;
    --text-2: #cbd5e1;
    --text-3: #94a3b8;
    --success: #34d399;
    --success-soft: #052e22;
    --warning: #fbbf24;
    --warning-soft: #2d1d05;
    --danger: #f87171;
    --danger-soft: #2c0b0b;
    --focus: 0 0 0 3px rgba(59, 130, 246, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
}

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

html, body { margin: 0; }

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

[hidden] { display: none !important; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Brand mark ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand-mark {
    width: 34px; height: 34px; border-radius: 9px; background: var(--brand);
    display: grid; place-items: center; color: #fff; flex-shrink: 0;
}
.brand-mark svg { width: 18px; height: 18px; }

/* ---------- Login ---------- */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 32px 16px;
}
.auth-card {
    width: 100%; max-width: 400px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
    padding: 32px 28px;
}
.auth-card .brand { margin-bottom: 28px; }
.auth-card h1 { font-size: 22px; line-height: 1.3; margin: 0 0 6px; letter-spacing: -0.01em; }
.auth-card .lead { color: var(--text-2); margin: 0 0 24px; }
.auth-card.wide { max-width: 560px; }
.auth-switch { margin: 18px 0 0; text-align: center; font-size: 14px; color: var(--text-2); }
.form-section { border: 0; padding: 0; margin: 0 0 8px; min-width: 0; }
.form-section legend {
    padding: 0; margin: 8px 0 12px; font-size: 12px; font-weight: 700; letter-spacing: .05em;
    text-transform: uppercase; color: var(--text-3);
}
.form-section + .form-section { border-top: 1px solid var(--border); padding-top: 8px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }
.field-hint { color: var(--text-3); font-size: 12px; margin-top: 6px; }
.input.upper { text-transform: uppercase; }
.input.upper::placeholder { text-transform: none; }
.strength { display: flex; gap: 4px; margin-top: 8px; }
.strength span { flex: 1; height: 4px; border-radius: 999px; background: var(--border); }
.strength[data-level="1"] span:nth-child(-n+1) { background: var(--danger); }
.strength[data-level="2"] span:nth-child(-n+2) { background: var(--warning); }
.strength[data-level="3"] span:nth-child(-n+3) { background: var(--success); }
.strength[data-level="4"] span:nth-child(-n+4) { background: var(--success); }
.segmented {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 18px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.segmented button {
    height: 34px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2);
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08); }
.segmented button:focus-visible { outline: none; box-shadow: var(--focus); }
.otp-input { font-size: 22px; letter-spacing: 0.4em; text-align: center; }
.link-btn { border: 0; background: none; padding: 0; margin-left: 6px; font: inherit; color: var(--brand); cursor: pointer; }
.link-btn:disabled { color: var(--text-3); cursor: default; }
.link-btn:not(:disabled):hover { text-decoration: underline; }
.auth-foot { margin-top: 20px; text-align: center; color: var(--text-3); font-size: 13px; }
.secure-note { display: flex; align-items: center; justify-content: center; gap: 6px; }
.secure-note svg { width: 14px; height: 14px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.input-group { position: relative; display: flex; align-items: center; }
.input-prefix {
    position: absolute; left: 12px; color: var(--text-3); font-size: 15px; pointer-events: none;
}
.input {
    width: 100%; height: 44px; padding: 0 12px; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    transition: border-color .15s, box-shadow .15s;
}
.input.has-prefix { padding-left: 48px; }
.input.has-suffix { padding-right: 64px; }
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-suffix {
    position: absolute; right: 6px; height: 32px; padding: 0 10px; border: 0; border-radius: 7px;
    background: transparent; color: var(--text-2); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.input-suffix:hover { background: var(--surface-2); color: var(--text); }
.input-suffix:focus-visible { outline: none; box-shadow: var(--focus); }
.field-error { color: var(--danger); font-size: 13px; margin-top: 6px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 44px; padding: 0 18px; font: inherit; font-weight: 600; border-radius: 10px;
    border: 1px solid transparent; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { width: 100%; background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:disabled { opacity: .7; cursor: progress; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); height: 38px; padding: 0 14px; font-size: 14px; }
.btn-ghost:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }

.spinner {
    width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
    border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
    display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px;
    font-size: 14px; margin-bottom: 16px; border: 1px solid transparent;
}
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-info { background: var(--brand-soft); color: var(--brand); border-color: color-mix(in srgb, var(--brand) 25%, transparent); }

/* ---------- Dashboard ---------- */
.topbar {
    position: sticky; top: 0; z-index: 10; background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: 1120px; margin: 0 auto; padding: 12px 16px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.user-chip { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-meta { text-align: right; min-width: 0; }
.user-meta .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.user-meta .sub { color: var(--text-3); font-size: 12px; }

.page { max-width: 1120px; margin: 0 auto; padding: 24px 16px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; margin: 0; letter-spacing: -0.01em; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

.badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; line-height: 20px; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px;
}
.stat .label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat .hint { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.stat.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.stat.primary .label, .stat.primary .hint { color: rgba(255,255,255,.85); }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-head h2 { font-size: 15px; margin: 0; }
.card-body { padding: 16px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-3); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
td.mono { font-family: var(--mono); font-size: 13px; }
.empty { padding: 32px 16px; text-align: center; color: var(--text-3); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; text-align: right; word-break: break-all; }
.token-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.token-box {
    flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; color: transparent !important; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 560px) {
    .auth-card { padding: 24px 20px; }
    .user-meta { display: none; }
    .page-head h1 { font-size: 20px; }
    .stat .value { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
