:root {
    --bg: #f5f6f8; --surface: #ffffff; --text: #1d2129;
    --text-secondary: #86909c; --border: #e5e6eb;
    --primary: #3370ff; --primary-hover: #2860e1; --primary-light: #e8f0ff;
    --danger: #f53f3f; --danger-bg: #fff0f0;
    --success: #00b42a; --success-bg: #e8ffea;
    --warning: #ff7d00;
    --radius: 8px; --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 4px 12px rgba(0,0,0,.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.08);
    --font: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
    --sidebar-w: 240px;
}
:root.dark {
    --bg: #17171a; --surface: #1f1f23; --text: #e5e6eb;
    --text-secondary: #8b8fa3; --border: #3a3a42;
    --primary-light: #1a2332;
    --danger-bg: #2a1215; --success-bg: #16291a;
    --shadow: 0 4px 12px rgba(0,0,0,.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px; border-radius: var(--radius-sm);
    font-size: 0.88rem; font-weight: 500; font-family: var(--font);
    cursor: pointer; border: 1px solid transparent; transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 5px 12px; font-size: 0.82rem; }
.btn-icon {
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-secondary);
    cursor: pointer; font-size: 0.95rem; transition: all .15s;
}
.btn-icon:hover { border-color: var(--primary); color: var(--primary); }

/* ===== Auth Page ===== */
.auth-container { display: flex; min-height: 100vh; }

.auth-brand-side {
    flex: 1;
    background: linear-gradient(135deg, #1d2129 0%, #2a3a5c 50%, #1d2129 100%);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    padding: 48px 40px; position: relative; overflow: hidden;
}
:root.dark .auth-brand-side {
    background: linear-gradient(135deg, #0d0d0f 0%, #1a2040 50%, #0d0d0f 100%);
}
.auth-brand-side::before {
    content: ''; position: absolute; width: 400px; height: 400px;
    border-radius: 50%; background: rgba(51,112,255,0.08);
    top: -100px; right: -80px;
}
.auth-brand-side::after {
    content: ''; position: absolute; width: 300px; height: 300px;
    border-radius: 50%; background: rgba(51,112,255,0.05);
    bottom: -60px; left: -60px;
}
.auth-brand-logo { font-size: 2rem; font-weight: 700; color: #fff; margin-bottom: 12px; position: relative; z-index: 1; }
.auth-brand-logo span { color: var(--primary); }
.auth-brand-desc {
    color: rgba(255,255,255,0.5); font-size: 0.92rem; text-align: center;
    max-width: 320px; line-height: 1.7; position: relative; z-index: 1;
}
.auth-brand-features {
    margin-top: 36px; display: flex; flex-direction: column; gap: 14px;
    position: relative; z-index: 1;
}
.auth-brand-features .feat { display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,0.65); font-size: 0.88rem; }
.auth-brand-features .feat-icon {
    width: 32px; height: 32px; border-radius: 6px;
    background: rgba(51,112,255,0.15);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem; flex-shrink: 0;
}

.auth-form-side {
    width: 480px; min-height: 100vh; display: flex; flex-direction: column;
    justify-content: center; padding: 48px 40px; background: var(--surface);
}
.auth-form-header { margin-bottom: 32px; }
.auth-form-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.auth-form-subtitle { color: var(--text-secondary); font-size: 0.9rem; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.auth-tab {
    padding: 10px 20px; font-size: 0.9rem; font-weight: 500;
    color: var(--text-secondary); cursor: pointer; border: none;
    background: none; font-family: var(--font); position: relative; transition: color .15s;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active { color: var(--primary); }
.auth-tab.active::after {
    content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
    height: 2px; background: var(--primary);
}
.auth-error {
    background: var(--danger-bg); border: 1px solid rgba(245,63,63,0.15);
    border-radius: var(--radius-sm); padding: 10px 14px;
    font-size: 0.85rem; color: var(--danger); margin-bottom: 16px; display: none;
}
.field { margin-bottom: 16px; }
.field-label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 6px; }
.field-label .req { color: var(--danger); margin-left: 2px; }
.field-input {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 0.9rem; font-family: var(--font);
    outline: none; background: var(--surface); color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.field-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(51,112,255,0.1); }
.field-input::placeholder { color: #c0c4cc; }
.auth-footer { margin-top: 20px; text-align: center; font-size: 0.85rem; color: var(--text-secondary); }
.auth-footer a { color: var(--primary); }

/* ===== Success Page ===== */
.success-container {
    min-height: 100vh; display: flex; align-items: center;
    justify-content: center; padding: 24px;
}
.success-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 36px; max-width: 480px; width: 100%; text-align: center;
}
.success-card h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 6px; }
.success-card > p { color: var(--text-secondary); font-size: 0.88rem; margin-bottom: 20px; }
.key-box {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 12px 14px;
    font-family: var(--font-mono); font-size: 0.84rem;
    word-break: break-all; text-align: left; margin-bottom: 20px; position: relative;
}
.key-box .copy-trigger {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    padding: 3px 10px; background: var(--primary); color: #fff;
    border: none; border-radius: 4px; font-size: 0.75rem; cursor: pointer; font-family: var(--font);
}
.key-box .copy-trigger:hover { background: var(--primary-hover); }
.success-actions { display: flex; gap: 10px; justify-content: center; }

/* ===== Dashboard Layout ===== */
.dash-layout { display: flex; min-height: 100vh; }
.dash-sidebar {
    width: var(--sidebar-w); background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; position: fixed;
    top: 0; left: 0; bottom: 0; z-index: 40;
}
.sidebar-logo {
    height: 56px; display: flex; align-items: center; padding: 0 20px;
    font-weight: 700; font-size: 1.1rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
    justify-content: space-between;
}
.sidebar-logo span { color: var(--primary); }
.sidebar-nav { flex: 1; padding: 12px; overflow-y: auto; }
.sidebar-section {
    font-size: 0.75rem; font-weight: 600; color: var(--text-secondary);
    text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; padding: 0 8px;
}
.sidebar-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    border-radius: var(--radius-sm); cursor: pointer; font-size: 0.94rem;
    color: var(--text); transition: background .15s, color .15s; margin-bottom: 2px;
}
.sidebar-item:hover { background: var(--bg); }
.sidebar-item.active { background: var(--primary-light); color: var(--primary); font-weight: 500; }
.sidebar-item .icon { font-size: 1.1rem; width: 22px; text-align: center; flex-shrink: 0; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sidebar-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--primary-light); display: flex; align-items: center; justify-content: center;
    font-size: 0.82rem; font-weight: 600; color: var(--primary); flex-shrink: 0;
}
.sidebar-user-name { font-size: 0.94rem; font-weight: 500; }
.sidebar-user-key { font-size: 0.75rem; color: var(--text-secondary); font-family: var(--font-mono); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-actions { display: flex; gap: 8px; }

.dash-main { flex: 1; margin-left: var(--sidebar-w); min-height: 100vh; }
.dash-content { padding: 28px 36px; }
.dash-page-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 24px; padding-bottom: 12px; border-bottom: 2px solid var(--primary); display: inline-block; }

/* ===== Dashboard Sub Pages ===== */
.dash-page { display: none; }
.dash-page.active { display: block; }

/* ===== Cards ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.card-header { padding: 16px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 1rem; font-weight: 600; }
.card-body { padding: 20px; }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-cell { padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stat-cell .label { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 4px; }
.stat-cell .value { font-size: 1.5rem; font-weight: 700; }
.stat-cell .value.success { color: var(--success); }

/* ===== Charts ===== */
.chart-row { display: flex; gap: 16px; }
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 180px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar-fill { width: 100%; max-width: 42px; background: linear-gradient(180deg, var(--primary) 0%, #6aa1ff 100%); border-radius: 4px 4px 0 0; transition: height .4s ease; min-height: 2px; }
.bar-fill:hover { opacity: .8; }
.bar-date { font-size: 0.78rem; color: var(--text-secondary); }
.bar-val { font-size: 0.78rem; color: var(--primary); font-weight: 500; }

.pie-chart-wrap { display: flex; flex-direction: column; gap: 8px; }
.pie-ring { position: relative; width: 140px; height: 140px; margin: 0 auto 8px; }
.pie-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.pie-ring .center-label { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 1.4rem; font-weight: 700; }
.pie-ring .center-sub { font-size: 0.7rem; color: var(--text-secondary); font-weight: 400; }
.pie-legend { display: flex; flex-direction: column; gap: 4px; }
.pie-legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; }
.pie-legend-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.pie-legend-name { flex: 1; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); }
.pie-legend-val { font-weight: 500; }

.chart-empty { text-align: center; padding: 40px 0; color: var(--text-secondary); font-size: 0.85rem; }

/* ===== API Key Display ===== */
.apikey-display {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 14px;
}
.apikey-display .apikey-row { flex: 1; font-family: var(--font-mono); font-size: 0.9rem; word-break: break-all; }
.key-hint { font-size: 0.85rem; color: var(--text-secondary); margin-top: 8px; }
.key-hint code { background: var(--bg); padding: 2px 6px; border-radius: 3px; font-family: var(--font-mono); font-size: 0.82rem; }

/* ===== Top APIs ===== */
.top-apis-list > div { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.top-apis-list > div:last-child { border-bottom: none; }
.top-apis-list .path { font-family: var(--font-mono); font-size: 0.88rem; }
.top-apis-list .count { color: var(--text-secondary); font-size: 0.88rem; }

/* ===== Password Form ===== */
.pwd-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 12px; align-items: end; }
.pwd-form .field { margin-bottom: 0; }

/* ===== Redeem ===== */
.redeem-form { display: flex; gap: 10px; align-items: center; }
.redeem-result {
    margin-top: 12px; padding: 10px 14px; border-radius: var(--radius-sm);
    font-size: 0.88rem; display: none;
}
.redeem-result.success { display: block; background: var(--success-bg); color: var(--success); border: 1px solid rgba(0,180,42,0.15); }
.redeem-result.error { display: block; background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(245,63,63,0.15); }

/* ===== Responsive ===== */
@media (max-width: 860px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .pwd-form { grid-template-columns: 1fr 1fr; }
    .chart-row { flex-direction: column; }
}
@media (max-width: 700px) {
    .auth-brand-side { display: none; }
    .auth-form-side { width: 100%; padding: 24px; }
    .dash-sidebar { display: none; }
    .dash-main { margin-left: 0; }
    .dash-content { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .pwd-form { grid-template-columns: 1fr; }
}
