:root {
    --page-bg: #f8fafc;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --surface-elevated: #ffffff;
    --surface-muted: #f1f5f9;
    --text: #334155;
    --text-strong: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --success: #10b981;
    --danger: #ef4444;
    --info: #3b82f6;
    --shadow-soft: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-elevated: 0 10px 30px rgba(15, 23, 42, 0.12);
    --overlay: rgba(15, 23, 42, 0.72);
    --input-bg: #ffffff;
    --input-text: #334155;
    --input-placeholder: #94a3b8;
    --primary-contrast: #ffffff;
    --theme-toggle-bg: #e2e8f0;
    --theme-toggle-text: #1e293b;
}

html[data-theme='dark'] {
    color-scheme: dark;
    --page-bg: #0f172a;
    --surface: #111827;
    --surface-alt: #0b1220;
    --surface-elevated: #162033;
    --surface-muted: #1e293b;
    --text: #cbd5e1;
    --text-strong: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --border-strong: #475569;
    --success: #10b981;
    --danger: #ef4444;
    --info: #3b82f6;
    --shadow-soft: 0 1px 3px rgba(2, 6, 23, 0.45);
    --shadow-elevated: 0 18px 42px rgba(2, 6, 23, 0.6);
    --overlay: rgba(2, 6, 23, 0.8);
    --input-bg: #0f172a;
    --input-text: #e2e8f0;
    --input-placeholder: #64748b;
    --primary-contrast: #ffffff;
    --theme-toggle-bg: #1e293b;
    --theme-toggle-text: #e2e8f0;
}

body {
    background: var(--page-bg);
    color: var(--text);
}

.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
}

.logo,
.page-title,
.card-title,
.modal-title,
.welcome-title {
    color: var(--text-strong);
}

.page-subtitle,
.form-label,
.nav-link,
.welcome-description,
.modal-body,
.modal-cost-item span:first-child,
.card-header,
.table th,
.table td,
.search-container,
.pagination a,
.pagination span {
    color: var(--text);
}

.nav-link:hover {
    background: var(--surface-muted);
    color: var(--text-strong);
}

.nav-link.active {
    color: var(--text-strong);
    background: var(--surface-muted);
}

.lang-switcher {
    background: var(--surface-muted);
}

.lang-btn.active {
    background: var(--surface);
    color: var(--text-strong);
}

.card,
.table-container,
.search-container,
.modal,
.form-input,
.form-textarea {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.card,
.table-container,
.search-container {
    box-shadow: var(--shadow-soft);
}

.card-header {
    background: var(--surface-alt);
    border-bottom-color: var(--border);
}

.form-input,
.form-textarea {
    background: var(--input-bg);
    color: var(--input-text);
    border-color: var(--border-strong);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--input-placeholder);
}

.form-input:focus,
.form-textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}

.table th {
    background: var(--surface-alt);
    color: var(--text-strong);
    border-bottom-color: var(--border);
}

.table td,
.table tr:hover {
    border-bottom-color: var(--border);
}

.table tr:hover {
    background: var(--surface-alt);
}

.pagination a,
.pagination span {
    border-color: var(--border-strong);
    background: var(--surface);
}

.pagination a:hover {
    background: var(--surface-alt);
    border-color: var(--border-strong);
}

html[data-theme='dark'] .alert-success {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.28);
    color: #34d399;
}

html[data-theme='dark'] .alert-error {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.28);
    color: #fca5a5;
}

html[data-theme='dark'] .alert-info {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.28);
    color: #93c5fd;
}

html[data-theme='dark'] .modal-overlay {
    background: var(--overlay);
}

html[data-theme='dark'] .modal,
html[data-theme='dark'] .sub-users-modal {
    background: var(--surface);
    border-color: var(--border);
    box-shadow: var(--shadow-elevated);
}

html[data-theme='dark'] .modal-header,
html[data-theme='dark'] .sub-users-modal-header,
html[data-theme='dark'] .token-log-dialog-header {
    border-bottom-color: var(--border);
}

html[data-theme='dark'] .modal-header::after {
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
}

html[data-theme='dark'] .modal-icon {
    filter: drop-shadow(0 2px 4px rgba(59, 130, 246, 0.25));
}

html[data-theme='dark'] .modal-cost-info,
html[data-theme='dark'] #balance-info {
    background: var(--surface-alt);
    border-color: var(--border-strong);
}

html[data-theme='dark'] .modal-cost-item:last-child {
    color: var(--text-strong);
    border-top-color: var(--border-strong);
}

html[data-theme='dark'] .modal-cost-item span:last-child {
    color: var(--text-strong);
}

html[data-theme='dark'] .modal-btn-secondary,
html[data-theme='dark'] .btn-secondary,
html[data-theme='dark'] .btn-outline {
    background: var(--surface-alt);
    color: var(--text-strong);
    border-color: var(--border-strong);
}

html[data-theme='dark'] .btn-outline:hover,
html[data-theme='dark'] .modal-btn-secondary:hover {
    background: var(--surface-muted);
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--theme-toggle-bg);
    color: var(--theme-toggle-text);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
}

.theme-toggle .theme-toggle-icon {
    font-size: 1rem;
    line-height: 1;
}

.theme-toggle .theme-toggle-label {
    display: none;
}

html[data-theme='dark'] .nav-link.btn-danger,
html[data-theme='dark'] .btn-primary,
html[data-theme='dark'] .btn-danger,
html[data-theme='dark'] .btn-success {
    color: var(--primary-contrast);
}

html[data-theme='dark'] .sub-users-modal-overlay,
html[data-theme='dark'] .token-log-dialog-backdrop {
    background: rgba(2, 6, 23, 0.78);
}

html[data-theme='dark'] .v2ray-over-limit-row {
    background: rgba(71, 85, 105, 0.4);
    border-color: rgba(148, 163, 184, 0.2) !important;
}

html[data-theme='dark'] .v2ray-over-limit-row td {
    color: #cbd5e1;
    opacity: 0.85;
}