:root {
    --sidebar: #0f1a2b;
    --sidebar-2: #13223a;
    --primary: #2f7df6;
    --primary-2: #1b64e5;
    --bg: #f3f6fb;
    --card: #ffffff;
    --line: #e6edf6;
    --ink: #152238;
    --ink-2: #475569;
    --muted: #8a9bb2;
    --green: #0f9f6e;
    --red: #e5484d;
    --amber: #d97706;
    --radius: 14px;
    --shadow: 0 12px 30px -24px rgba(15, 23, 42, .45);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-2); }
code { font-family: Consolas, Monaco, Menlo, monospace; font-size: 12.5px; }

.app-shell { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
    width: 232px;
    flex: none;
    height: 100vh;
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #101c30 0%, #0d1728 100%);
    color: #c8d4e5;
    z-index: 50;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 20px 18px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b8cff, #1b64e5);
    color: #fff;
    font-size: 17px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 18px -8px rgba(47, 125, 246, .9);
    flex: none;
}

.brand-mark.big { width: 52px; height: 52px; border-radius: 14px; font-size: 24px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.brand-text b { color: #fff; font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text em { font-style: normal; font-size: 9px; letter-spacing: 1.2px; color: #64748b; margin-top: 2px; }

.side-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 12px;
    border-radius: 10px;
    color: #9fb0c7;
    font-size: 13.5px;
    font-weight: 600;
    border: 1px solid transparent;
    transition: background .15s, color .15s;
}

.nav-item:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.nav-item.on {
    background: linear-gradient(90deg, rgba(47, 125, 246, .24), rgba(47, 125, 246, .06));
    border-color: rgba(90, 155, 255, .25);
    color: #fff;
}
.nav-ic { width: 19px; height: 19px; display: flex; align-items: center; justify-content: center; }
.nav-ic svg { width: 18px; height: 18px; }

.side-foot {
    margin-top: auto;
    padding: 14px 18px;
    border-top: 1px solid rgba(255, 255, 255, .06);
    display: flex;
    justify-content: space-between;
    font-size: 10.5px;
    color: #53657f;
}

/* ===== Main / topbar ===== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: 64px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    padding: 0 26px;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 40;
}

.menu-toggle {
    display: none;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    width: 34px;
    height: 34px;
    font-size: 16px;
    cursor: pointer;
    color: var(--ink-2);
}

.welcome { font-size: 14px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.welcome b { color: var(--ink); font-weight: 700; }

.role-badge {
    font-size: 10.5px;
    padding: 2px 8px;
    border-radius: 20px;
    background: #eef4ff;
    color: var(--primary-2);
    font-weight: 700;
    letter-spacing: .3px;
}

.logout-form { margin-left: auto; }

.btn-logout {
    border: 1px solid #f3c1c4;
    color: var(--red);
    background: #fff7f7;
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: .15s;
}
.btn-logout:hover { background: #feecec; border-color: #f0a8ad; }

.content { padding: 24px 26px 40px; max-width: 1600px; width: 100%; margin: 0 auto; }

/* ===== Page heading ===== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.2px; }
.page-head p { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ===== Cards ===== */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; font-size: 14px; }
.card-head b { font-size: 14.5px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat-card { margin-bottom: 0; min-height: 156px; }
.stat-head { font-size: 13.5px; font-weight: 700; margin-bottom: 14px; }

.kv-list { display: flex; flex-direction: column; gap: 10px; }
.kv-list > div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 13px; }
.kv-list span { color: var(--muted); }
.kv-list b { font-weight: 700; color: var(--ink); text-align: right; }
.kv-list.compact { margin-top: 10px; }

.balance-big { font-size: 27px; font-weight: 800; letter-spacing: -.5px; margin: 2px 0 6px; }
.text-green { color: var(--green) !important; }
.text-red { color: var(--red) !important; }

.api-numbers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.api-numbers > div { display: flex; flex-direction: column; gap: 4px; }
.api-numbers span { font-size: 11.5px; color: var(--muted); }
.api-numbers b { font-size: 22px; letter-spacing: -.5px; }
.stat-note { margin-top: 14px; color: var(--muted); font-size: 11.5px; }

/* ===== Chart ===== */
.chart-card { padding-bottom: 10px; }
.chart-head { align-items: flex-start; margin-bottom: 8px; }
.chart-head .muted { display: block; margin-top: 3px; font-size: 11.5px; }
.chart-tools { display: flex; align-items: center; gap: 10px; }

.seg { display: inline-flex; background: #f1f5fb; border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg-btn {
    border: 0;
    background: transparent;
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 11px;
    border-radius: 6px;
    cursor: pointer;
}
.seg-btn.on { background: #fff; color: var(--primary-2); box-shadow: 0 2px 6px rgba(15, 23, 42, .08); }

.chart-legend { display: flex; gap: 18px; align-items: center; font-size: 12px; color: var(--ink-2); margin: 6px 0 4px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-blue { background: var(--primary); }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }

.chart-box { position: relative; height: 340px; width: 100%; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.chart-tooltip {
    position: absolute;
    display: none;
    pointer-events: none;
    background: rgba(15, 23, 42, .92);
    color: #fff;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 11.5px;
    line-height: 1.7;
    z-index: 10;
    white-space: nowrap;
}

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid #eef3f9; font-size: 12.8px; vertical-align: middle; }
th { color: var(--muted); font-size: 11.5px; font-weight: 700; background: #fbfcfe; white-space: nowrap; }
tbody tr:hover { background: #f8fbff; }
tbody tr:last-child td { border-bottom: 0; }
.wide-table { min-width: 1080px; }
.empty { text-align: center; color: var(--muted); padding: 28px 0 !important; }
.mono { font-family: Consolas, Monaco, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.nowrap { white-space: nowrap; }
.ellipsis { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-ok { background: #e9f8f1; color: var(--green); }
.badge-bad { background: #fdecec; color: var(--red); }
.badge-warn { background: #fff6e5; color: var(--amber); }
.badge-info { background: #eaf2ff; color: var(--primary-2); }
.badge-gray { background: #f1f4f9; color: #7b8ca3; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: #f1f5fb; color: var(--ink-2); font-size: 11px; font-weight: 700; }
.tag-blue { background: #eaf2ff; color: var(--primary-2); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 8px;
    padding: 9px 15px;
    font-size: 13px;
    font-weight: 650;
    border: 1px solid transparent;
    cursor: pointer;
    transition: .15s;
    text-decoration: none;
    line-height: 1.2;
}
.btn-primary { background: linear-gradient(180deg, #3b8aff, #2f7df6); color: #fff; box-shadow: 0 8px 16px -10px rgba(47, 125, 246, .9); }
.btn-primary:hover { background: linear-gradient(180deg, #2f7df6, #1b64e5); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: #c9d7e8; color: var(--ink); }
.btn-danger { background: #fff5f5; border-color: #f3c1c4; color: var(--red); }
.btn-danger:hover { background: #feecec; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; padding: 11px 15px; }
.link { color: var(--primary); font-size: 12.5px; font-weight: 600; }

/* ===== Forms ===== */
.form-group { margin-bottom: 13px; }
.form-group label { display: block; font-size: 12px; color: var(--ink-2); font-weight: 650; margin-bottom: 6px; }
.form-control {
    width: 100%;
    height: 38px;
    border: 1px solid #dbe5f1;
    border-radius: 8px;
    padding: 0 11px;
    font-size: 13px;
    color: var(--ink);
    background: #fff;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
textarea.form-control { height: auto; padding: 10px 11px; resize: vertical; }
.form-control:focus { border-color: #8cb8ff; box-shadow: 0 0 0 3px rgba(47, 125, 246, .12); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-db { grid-template-columns: minmax(0, 1fr) 116px; }
.form-section-title { margin: 20px 0 10px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; font-weight: 800; letter-spacing: .04em; color: var(--ink); }
.form-section-title.first { margin-top: 0; padding-top: 0; border-top: 0; }
.form-hint { margin: -2px 0 4px; font-size: 11.5px; color: var(--muted); line-height: 1.7; }
.form-hint code { background: #f4f7fb; padding: 1px 5px; border-radius: 4px; }
.form-tip { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.6; }
.grid-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; }
.form-actions { display: flex; align-items: flex-end; }
.form-actions .btn { width: 100%; }
.inline-form { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.inline-form .form-control { max-width: 280px; }
.row-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.input-xs { height: 30px; width: 92px; padding: 0 8px; font-size: 12px; }
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 0; }
.filter-bar .form-control { width: auto; min-width: 130px; height: 34px; font-size: 12.5px; }

/* ===== Flash ===== */
.flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 12.5px;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.flash-success { background: #ecfdf5; border-color: #b9f0d8; color: #057a55; }
.flash-error { background: #fef2f2; border-color: #f6cdcd; color: #b42318; }
.flash-warn { background: #fffbeb; border-color: #f7e2b5; color: #92400e; }
.flash-info { background: #eff6ff; border-color: #cddffb; color: #1b64e5; }
.flash-x { border: 0; background: transparent; font-size: 18px; color: currentColor; cursor: pointer; opacity: .6; }

/* ===== Misc ===== */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; }
.balance-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.balance-meta { display: flex; gap: 26px; }
.balance-meta > div { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.balance-meta span { color: var(--muted); }
.balance-mini { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.balance-mini b { font-size: 18px; color: var(--ink); margin-left: 4px; }
.gateway-box { display: flex; align-items: center; gap: 10px; background: #f8fbff; border: 1px dashed #cddffb; border-radius: 10px; padding: 10px 12px; flex-wrap: wrap; }
.gateway-box code { color: var(--primary-2); font-weight: 700; word-break: break-all; }
.endpoint-list { display: flex; flex-direction: column; gap: 7px; margin: 12px 0; font-size: 12px; color: var(--ink-2); }
.endpoint-list code { color: var(--ink); }
.new-key-card { border-color: #b9f0d8; background: #f7fefb; }
.new-key-head { font-weight: 700; color: #057a55; margin-bottom: 10px; }
.key-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.key-row code { background: #fff; border: 1px solid #b9f0d8; padding: 9px 12px; border-radius: 8px; font-weight: 700; word-break: break-all; }
.help-list { display: flex; flex-direction: column; gap: 12px; }
.help-list > div { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 10px; font-size: 12.5px; }
.help-list b { color: var(--ink); }
.help-list span { color: var(--muted); line-height: 1.65; }
.empty-box { color: var(--muted); font-size: 12.5px; line-height: 1.7; }
.code-block { background: #0f1a2b; color: #d6e2f3; border-radius: 10px; padding: 14px; overflow: auto; font-size: 11.5px; line-height: 1.7; }
.pager { display: flex; gap: 6px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.chart-tooltip strong { color: #fff; }

/* ===== Auth pages ===== */
.auth-body { background: #eef3fa; min-height: 100vh; }
.auth-wrap { display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh; }
.auth-brand {
    position: relative;
    background: radial-gradient(900px 500px at 0% 0%, rgba(47, 125, 246, .35), transparent 60%),
                radial-gradient(700px 500px at 100% 100%, rgba(16, 185, 129, .18), transparent 55%),
                #0f1a2b;
    color: #fff;
    padding: 54px 56px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
}
.auth-brand::after {
    content: "";
    position: absolute;
    width: 440px; height: 440px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .06);
    right: -140px; bottom: -160px;
    box-shadow: 0 0 0 60px rgba(255, 255, 255, .025), 0 0 0 120px rgba(255, 255, 255, .018);
}
.auth-brand-inner { position: relative; z-index: 1; max-width: 430px; }
.auth-brand h1 { font-size: 30px; margin: 22px 0 10px; letter-spacing: -.5px; }
.auth-brand p { color: #9fb0c7; line-height: 1.8; font-size: 14px; }
.auth-brand ul { margin: 26px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; color: #c8d4e5; font-size: 13px; }
.auth-brand li::before { content: "•"; color: #5a9bff; margin-right: 8px; }
.auth-brand-foot { position: relative; z-index: 1; font-size: 10.5px; letter-spacing: 1.4px; color: #53657f; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 34px; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 24px 60px -34px rgba(15, 23, 42, .55); padding: 32px 32px 26px; width: 100%; max-width: 430px; }
.install-card { max-width: 650px; }
.auth-head { margin-bottom: 20px; }
.eyebrow { font-size: 10px; letter-spacing: 1.6px; color: #8aa4c8; font-weight: 800; }
.auth-head h2 { margin: 8px 0 6px; font-size: 22px; }
.auth-head p { margin: 0; color: var(--muted); font-size: 12.5px; }
.auth-tip { margin-top: 16px; color: var(--muted); font-size: 11.5px; line-height: 1.8; }
.auth-tip code { background: #f4f7fb; padding: 1px 5px; border-radius: 4px; }
.install-card .form-group { margin-bottom: 11px; }

/* ===== Error ===== */
.error-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.error-card { text-align: center; max-width: 430px; width: 100%; padding: 34px; }
.error-code { font-size: 44px; font-weight: 800; color: #dbe6f5; letter-spacing: -2px; }
.error-card h2 { margin: 6px 0; }
.error-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .stat-card:last-child { grid-column: span 2; }
    .grid-2 { grid-template-columns: 1fr; }
    .grid-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; }
    body.nav-open .sidebar { transform: translateX(0); box-shadow: 20px 0 60px rgba(15, 23, 42, .35); }
    .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .content { padding: 18px 16px 34px; }
    .topbar { padding: 0 16px; }
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
    .auth-panel { padding: 22px; }
    .stat-grid { grid-template-columns: 1fr; }
    .stat-card:last-child { grid-column: auto; }
    .form-row { grid-template-columns: 1fr; }
    .grid-form { grid-template-columns: 1fr; }
    .balance-card { flex-direction: column; align-items: flex-start; }
    .balance-meta { width: 100%; justify-content: space-between; }
    .chart-box { height: 280px; }
    .welcome { font-size: 13px; }
    .btn-logout { padding: 7px 10px; font-size: 12px; }
}
