/* ==================== CSS Variables ==================== */
:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --success-color: #48bb78;
    --warning-color: #ed8936;
    --danger-color: #f56565;
    --info-color: #4299e1;
    --bg-light: #f7fafc;
    --bg-dark: #2d3748;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --border-color: #e2e8f0;
    --border: #e2e8f0;
    --card-bg: #ffffff;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 0px;
    --topbar-height: 64px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== Reset & Base ==================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    /* 移动端触摸优化 */
    -webkit-text-size-adjust: 100%;
    -ms-touch-action: manipulation;
    touch-action: manipulation;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
    background: var(--bg-light);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    /* 移动端滚动优化 */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* 移动端触摸优化 */
@media (max-width: 768px) {
    body {
        /* 禁止双击缩放 */
        touch-action: manipulation;
    }
    /* 禁止长按选中 */
    * {
        -webkit-touch-callout: default;
    }
    /* 按钮和链接点击无高亮 */
    button, a, input, select, textarea {
        -webkit-tap-highlight-color: transparent;
    }
    /* 防止 iOS Safari 自动放大 */
    input, select, textarea {
        font-size: 16px !important;
    }
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

/* ==================== Login Page ==================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
    top: -200px;
    right: -200px;
    animation: float 8s ease-in-out infinite;
}

.login-page::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: rgba(255,255,255,0.03);
    bottom: -100px;
    left: -100px;
    animation: float 6s ease-in-out infinite reverse;
}

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-30px) rotate(5deg); }
}

.login-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.2);
    position: relative;
    z-index: 1;
    animation: slideUp 0.5s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-card .logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-card .logo-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4);
}

.login-card .logo-icon svg {
    width: 36px;
    height: 36px;
    fill: white;
}

.login-card .logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.login-card .logo p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

.form-group {
    margin-bottom: 20px;
    position: relative;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    transition: var(--transition);
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: var(--transition);
    background: white;
    color: var(--text-primary);
    outline: none;
}

.form-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.form-group input::placeholder {
    color: #a0aec0;
}

.form-group .input-icon {
    position: absolute;
    right: 14px;
    top: 38px;
    color: var(--text-secondary);
    cursor: pointer;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.35);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.45);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #38a169;
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #e53e3e;
    transform: translateY(-1px);
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: #dd6b20;
}

.btn-info {
    background: var(--info-color);
    color: white;
}

.btn-info:hover:not(:disabled) {
    background: #3182ce;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1rem;
}

.btn-full {
    width: 100%;
}

.btn .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.login-error {
    background: #fff5f5;
    color: var(--danger-color);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
    display: none;
    border: 1px solid #fed7d7;
}

.login-error.show {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==================== App Layout ==================== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1a202c 0%, #2d3748 100%);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}
.main-content.expanded .topbar {
    width: 100vw;
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sidebar-header .logo-icon-sm {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-header .logo-icon-sm svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    white-space: nowrap;
}

.sidebar-nav {
    padding: 16px 12px;
    flex: 1;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.35);
    padding: 0 12px;
    margin-bottom: 8px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
    font-size: 0.9rem;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: white;
}

.nav-item.active {
    background: linear-gradient(135deg, rgba(102,126,234,0.3), rgba(118,75,162,0.2));
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.8;
}

.nav-item.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-footer .version {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.35);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding-top: var(--topbar-height);
    transition: var(--transition);
    min-height: 100vh;
    /* 移动端触摸优化 */
    -webkit-overflow-scrolling: touch;
    /* 防止横向滚动溢出 */
    overflow-x: hidden;
}

.main-content.expanded {
    margin-left: 0;
}

/* Top Bar */
.topbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: fixed;
    top: 0;
    right: 0;
    z-index: 500;
    box-shadow: var(--shadow-sm);
    /* 移动端触摸优化 */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* 防止 topbar 被内容覆盖 */
    width: calc(100vw - 260px);
    max-width: 100vw;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

.menu-toggle:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.breadcrumb span {
    color: var(--text-secondary);
}

.breadcrumb .current {
    color: var(--text-primary);
    font-weight: 600;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-right .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.topbar-right .user-info:hover {
    background: var(--bg-light);
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.user-role {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

/* Page Content */
.page-content {
    padding: 28px;
    /* 移动端触摸优化 */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* 防止 page-content 横向滚动影响 topbar */
    overflow-x: hidden;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
}

.page-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ==================== Cards ==================== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    transition: var(--transition);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-header {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.card-body {
    padding: 22px;
}

.card-body.no-pad {
    padding: 0;
}

/* Stats Cards Grid */
.stats-grid {
    display: flex;
    gap: 16px;
    margin-bottom: 28px;
    overflow-x: auto;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 20px 22px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 18px;
    flex: 1;
    min-width: 170px;
    border: 1px solid rgba(0,0,0,0.04);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-card.primary .stat-icon { background: rgba(102,126,234,0.1); color: var(--primary-color); }
.stat-card.success .stat-icon { background: rgba(72,187,120,0.1); color: var(--success-color); }
.stat-card.warning .stat-icon { background: rgba(237,137,54,0.1); color: var(--warning-color); }
.stat-card.danger .stat-icon { background: rgba(245,101,101,0.1); color: var(--danger-color); }
.stat-card.info .stat-icon { background: rgba(66,153,225,0.1); color: var(--info-color); }
.stat-card.secondary .stat-icon { background: rgba(118,75,162,0.1); color: var(--secondary-color); }

.stat-card .stat-icon svg {
    width: 60px;
    height: 60px;
    padding-top: 8px;
}

.stat-card .stat-value {
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.15;
    margin-bottom: 2px;
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}


/* Stat info: icon left, value+label stacked right */
.stat-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-width: 0;
}

.stat-card .stat-change {
    font-size: 0.75rem;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-card .stat-change.up { color: var(--success-color); }
.stat-card .stat-change.down { color: var(--danger-color); }

/* Stat card background icon */
.stat-card .stat-card-bg {
    position: absolute;
    right: -6px;
    bottom: -10px;
    opacity: 0.05;
    pointer-events: none;
    z-index: 0;
}
.stat-card .stat-card-bg svg {
    width: 70px;
    height: 70px;
}
.stat-card .stat-icon,
.stat-card .stat-info,
.stat-card .stat-value,
.stat-card .stat-label {
    position: relative;
    z-index: 1;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.chart-card .card-header {
    border-left: 3px solid var(--primary-color);
    padding-left: 19px;
}
.chart-card .card-header h3 {
    display: flex;
    align-items: center;
}

.chart-card .card-body {
    padding: 16px;
    height: 300px;
    position: relative;
}

/* ==================== Tables ==================== */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

thead {
    background: var(--bg-light);
}

th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
    white-space:nowrap
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background: rgba(102, 126, 234, 0.03);
}

tbody tr:nth-child(even) {
    background: rgba(247, 250, 252, 0.5);
}

tbody tr:nth-child(even):hover {
    background: rgba(102, 126, 234, 0.05);
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    gap: 4px;
}

.badge-success { background: #f0fff4; color: #276749; }
.badge-warning { background: #fffaf0; color: #9c4221; }
.badge-danger { background: #fff5f5; color: #9b2c2c; }
.badge-info { background: #ebf8ff; color: #2b6cb0; }
.badge-secondary { background: #f7fafc; color: #4a5568; }
.badge-primary { background: #ebf4ff; color: #4c51bf; }

.badge .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.badge-success .dot { background: var(--success-color); }
.badge-warning .dot { background: var(--warning-color); }
.badge-danger .dot { background: var(--danger-color); }
.badge-info .dot { background: var(--info-color); }

/* ==================== Modal ==================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    padding: 20px;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9) translateY(20px);
    transition: var(--transition);
}

.modal-overlay.show .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--bg-light);
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--danger-color);
    color: white;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Form Styles */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: var(--transition);
    background: white;
    color: var(--text-primary);
    outline: none;
    font-family: inherit;
}

.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.form-group .help-text {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.form-group .error-text {
    font-size: 0.78rem;
    color: var(--danger-color);
    margin-top: 4px;
    display: none;
}

.form-group.has-error input,
.form-group.has-error select,
.form-group.has-error textarea {
    border-color: var(--danger-color);
}

.form-group.has-error .error-text {
    display: block;
}

/* ==================== Toast ==================== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 420px;
    animation: toastIn 0.3s ease;
    border-left: 4px solid;
    font-size: 0.88rem;
}

.toast.success { border-left-color: var(--success-color); }
.toast.error { border-left-color: var(--danger-color); }
.toast.warning { border-left-color: var(--warning-color); }
.toast.info { border-left-color: var(--info-color); }

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(100px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100px); }
}

.toast-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.toast.success .toast-icon { color: var(--success-color); }
.toast.error .toast-icon { color: var(--danger-color); }
.toast.warning .toast-icon { color: var(--warning-color); }
.toast.info .toast-icon { color: var(--info-color); }

/* ==================== Filters / Toolbar ==================== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-box {
    position: relative;
}

.search-box input {
    padding: 8px 14px 8px 36px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    width: 220px;
    transition: var(--transition);
    outline: none;
    background: white;
}

.search-box input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
    width: 280px;
}

.search-box svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

.filter-select {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    outline: none;
    background: white;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.filter-select:focus {
    border-color: var(--primary-color);
}

/* ==================== Empty State ==================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 80px;
    height: 80px;
    color: #e2e8f0;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 0.9rem;
}

/* ==================== Loading ==================== */
.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    margin-left: 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==================== Confirm Dialog ==================== */
.confirm-dialog .modal {
    max-width: 400px;
}

.confirm-dialog .modal-body {
    text-align: center;
    padding: 30px 24px;
}

.confirm-dialog .confirm-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.confirm-dialog .confirm-icon.danger {
    background: #fff5f5;
    color: var(--danger-color);
}

.confirm-dialog .confirm-icon.warning {
    background: #fffaf0;
    color: var(--warning-color);
}

.confirm-dialog .confirm-icon svg {
    width: 28px;
    height: 28px;
}

.confirm-dialog h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.confirm-dialog p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ==================== Detail View ==================== */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.detail-item {
    padding: 12px;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
}

.detail-item .label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.detail-item .value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
}

/* ==================== Push Form ==================== */
.push-form .form-group {
    margin-bottom: 16px;
}

/* ==================== Settings ==================== */
.settings-section {
    margin-bottom: 28px;
}

.settings-section h3 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-label {
    font-weight: 600;
    font-size: 0.9rem;
}

.setting-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.setting-value {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
    color: var(--primary-color);
    background: rgba(102,126,234,0.08);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
}

.setting-input {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
    background: white;
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s;
}
.setting-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102,126,234,0.15);
}

/* Connection dot */
.online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin: 0px 6px 0 6px;
    animation: pulse 2s infinite;
}

.online-dot.active { background: var(--success-color); }
.online-dot.inactive { background: var(--text-secondary); animation: none; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ==================== Actions Column ==================== */
.actions {
    display: flex;
    gap: 6px;
}

.action-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    background: transparent;
    color: var(--text-secondary);
}

.action-btn:hover {
    background: var(--bg-light);
}

.action-btn.view:hover { color: var(--info-color); }
.action-btn.edit:hover { color: var(--warning-color); }
.action-btn.delete:hover { color: var(--danger-color); background: #fff5f5; }
.action-btn.revoke:hover { color: var(--warning-color); background: #fffaf0; }

.action-btn svg {
    width: 16px;
    height: 16px;
}

/* ==================== Sidebar Overlay (Mobile) ==================== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.sidebar-overlay.show {
    display: block;
}

/* ==================== Pagination ==================== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 22px;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* 分页信息 */
.pagination-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 22px;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.pagination-info-detail {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* 分页按钮组 */
.pagination-btns {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* 分页按钮 */
.page-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    transition: all 0.2s ease;
    color: var(--text-primary);
    white-space: nowrap;
}
.page-btn:hover:not(.disabled):not(.active) {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(102, 102, 241, 0.05);
    transform: translateY(-1px);
}
.page-btn.active {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(102, 102, 241, 0.35);
}
.page-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.page-ellipsis {
    padding: 0 4px;
    color: var(--text-muted);
    font-size: 1rem;
    user-select: none;
}

/* ==================== Responsive ==================== */
@media (max-width: 1200px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1024px) {
    .stats-grid {
        flex-wrap: wrap;
    }
    .stats-grid .stat-card {
        min-width: calc(33.333% - 14px);
    }
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(calc(-1 * var(--sidebar-width)));
        /* 移动端硬件加速 */
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        /* 移动端侧边栏层级高于 topbar */
        z-index: 1001;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        z-index: 1001;
    }
    .main-content {
        margin-left: 0 !important;
        /* topbar fixed 后，留出 topbar 高度 */
        padding-top: var(--topbar-height);
    }
    /* 登录页不需要 padding-top，因为 topbar 在登录后才显示 */
    #loginPage .login-page {
        padding-top: 0 !important;
    }
    .page-content {
        padding: 10px;
    }
    .topbar {
        padding: 0 16px;
        width: calc(100%);
        /* 全局已是 position: fixed，此处只覆盖 padding */
    }
    /* 防止 select 下拉时改变视口高度导致 fixed 失效 */
    select, .filter-select {
        -webkit-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23718096' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 10px center;
        padding-right: 30px !important;
    }
    /* 移动端隐藏次要表格列 */
    .hide-mobile { display: none !important; }
    .hide-tablet { display: none !important; }
    .stats-grid {
        gap: 12px;
    }
    .stats-grid .stat-card {
        min-width: calc(50% - 8px);
    }
    .stat-card {
        padding: 16px 18px;
        gap: 14px;
    }
    .stat-card .stat-icon {
        width: 44px;
        height: 44px;
    }
    .stat-card .stat-icon svg {
        width: 22px;
        height: 22px;
    }
    .stat-card .stat-value {
        font-size: 1.6rem;
    }
    .toolbar-left, .toolbar-right {
        flex-wrap: wrap;
    }
    .search-box input {
        width: 100%;
    }
    .search-box input:focus {
        width: 100%;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .pagination {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    .user-name, .user-role {
        display: none;
    }
    .modal {
        max-width: 100%;
        margin: 10px;
    }
    .toast {
        min-width: auto;
        max-width: calc(100vw - 40px);
    }
    .pagination-info {
        flex-wrap: wrap;
        padding: 12px 16px;
        gap: 10px;
    }
    /* 分页按钮单独一行，居中显示 */
    .pagination-btns {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        flex-direction: column;
    }
    .login-card {
        padding: 32px 24px;
    }
}

/* ==================== Code / Monospace ==================== */
.code {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.82rem;
    background: var(--bg-light);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--primary-color);
}

/* ==================== Scrollbar ==================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* ==================== Print ==================== */
@media print {
    .sidebar, .topbar, .toast-container, .modal-overlay {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
    }
}

/* ==================== Connection list specific ==================== */
.connection-card {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.connection-card:hover {
    background: rgba(102, 126, 234, 0.03);
}

.connection-card:last-child {
    border-bottom: none;
}

.connection-info {
    flex: 1;
}

.connection-info .conn-id {
    font-weight: 600;
    font-size: 0.9rem;
}

.connection-info .conn-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ==================== Hidden utility ==================== */
.hidden {
    display: none !important;
}

.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .3s;
    border-radius: 26px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--primary-color);
}
input:checked + .slider:before {
    transform: translateX(22px);
}

.action-btn.push:hover { color: var(--info-color); background: #f0f7ff; }
.action-btn.push svg { width: 15px; height: 15px; }

/* ==================== Dark Mode ==================== */
body.dark-mode {
    --bg-light: #0f172a;
    --bg-dark: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --border: #334155;
    --card-bg: #1e293b;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
}
body.dark-mode .login-page {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}
body.dark-mode .login-card {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid #334155;
}
body.dark-mode .login-card .logo h1,
body.dark-mode .login-card .logo p { color: #f1f5f9; }
body.dark-mode .login-card .logo p { color: #94a3b8; }
body.dark-mode .form-group input,
body.dark-mode .form-group select,
body.dark-mode .form-group textarea {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}
body.dark-mode .form-group input:focus,
body.dark-mode .form-group select:focus,
body.dark-mode .form-group textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}
body.dark-mode .form-group label { color: #94a3b8; }

body.dark-mode .sidebar {
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
}
body.dark-mode .topbar {
    background: #1e293b;
    border-color: #334155;
}
body.dark-mode .stat-card {
    background: #1e293b;
    border-color: #334155;
}
body.dark-mode .stat-card .stat-value { color: #f1f5f9; }
body.dark-mode .stat-card .stat-label { color: #94a3b8; }
body.dark-mode .card {
    background: #1e293b;
    border-color: #334155;
}
body.dark-mode .card-header {
    border-color: #334155;
}
body.dark-mode table thead {
    background: #0f172a;
}
body.dark-mode th {
    color: #94a3b8;
    border-color: #334155;
}
body.dark-mode td {
    color: #f1f5f9;
    border-color: #334155;
}
body.dark-mode tbody tr:nth-child(even) {
    background: rgba(15, 23, 42, 0.4);
}
body.dark-mode tbody tr:hover {
    background: rgba(99, 102, 241, 0.08);
}
body.dark-mode .search-box input {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}
body.dark-mode .filter-select {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}
body.dark-mode .modal {
    background: #1e293b;
}
body.dark-mode .modal-header,
body.dark-mode .modal-footer {
    border-color: #334155;
}
body.dark-mode .modal-close {
    background: #334155;
    color: #94a3b8;
}
body.dark-mode .detail-item {
    background: #0f172a;
}
body.dark-mode .detail-item .label { color: #94a3b8; }
body.dark-mode .detail-item .value { color: #f1f5f9; }
body.dark-mode .setting-row { border-color: #334155; }
body.dark-mode .setting-value {
    background: rgba(99,102,241,0.15);
    color: var(--primary-light);
}
body.dark-mode .setting-input {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}
body.dark-mode .pagination {
    border-color: #334155;
    color: #94a3b8;
}
body.dark-mode .pagination-btns button {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}
body.dark-mode .pagination-btns button:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}
body.dark-mode .empty-state { color: #94a3b8; }
body.dark-mode .empty-state h3 { color: #f1f5f9; }
body.dark-mode .page-header h1 { color: #f1f5f9; }
body.dark-mode .page-header p { color: #94a3b8; }
body.dark-mode .chart-card .card-header h3 { color: #f1f5f9; }
body.dark-mode .setting-label { color: #f1f5f9; }
body.dark-mode .setting-desc { color: #94a3b8; }
body.dark-mode .connection-card { border-color: #334155; }
body.dark-mode .connection-card:hover { background: rgba(99,102,241,0.06); }
body.dark-mode .connection-info .conn-meta { color: #94a3b8; }
body.dark-mode ::-webkit-scrollbar-thumb {
    background: #475569;
}
body.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}
body.dark-mode .btn-outline {
    border-color: #334155;
    color: #94a3b8;
}
body.dark-mode .btn-outline:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}
body.dark-mode .skeleton {
    background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
}
body.dark-mode .loading-spinner {
    border-color: #334155;
    border-top-color: var(--primary-color);
}
body.dark-mode .loading-text { color: #94a3b8; }
body.dark-mode .toast { background: #1e293b; }
body.dark-mode .badge-secondary { background: #334155; color: #cbd5e1; }
body.dark-mode .badge-success { background: rgba(72,187,120,0.15); color: #68d68d; }
body.dark-mode .badge-warning { background: rgba(237,137,54,0.15); color: #f6ad55; }
body.dark-mode .badge-danger { background: rgba(245,101,101,0.15); color: #fc8181; }
body.dark-mode .badge-info { background: rgba(66,153,225,0.15); color: #63b3ed; }
body.dark-mode .badge-primary { background: rgba(99,102,241,0.15); color: #a5b4fc; }
body.dark-mode .confirm-dialog .confirm-icon.danger { background: rgba(245,101,101,0.15); }
body.dark-mode .confirm-dialog .confirm-icon.warning { background: rgba(237,137,54,0.15); }
body.dark-mode .confirm-dialog h3 { color: #f1f5f9; }
body.dark-mode .confirm-dialog p { color: #94a3b8; }
body.dark-mode .modal-header h3 { color: #f1f5f9; }
body.dark-mode .form-group .help-text { color: #64748b; }
body.dark-mode .topbar-right .user-info:hover { background: #334155; }
body.dark-mode .nav-item { color: rgba(241,245,249,0.6); }
body.dark-mode .nav-item:hover { background: rgba(255,255,255,0.05); color: #f1f5f9; }
body.dark-mode .nav-item.active {
    background: linear-gradient(135deg, rgba(99,102,241,0.25), rgba(139,92,246,0.15));
}
body.dark-mode .sidebar-overlay { background: rgba(0,0,0,0.6); }
body.dark-mode .action-btn:hover { background: #334155; }
body.dark-mode .action-btn.delete:hover { background: rgba(245,101,101,0.15); }
body.dark-mode .action-btn.push:hover { background: rgba(66,153,225,0.15); }
body.dark-mode .action-btn.revoke:hover { background: rgba(237,137,54,0.15); }
body.dark-mode .code { background: #0f172a; }

/* Dark mode toggle button */
.dark-mode-toggle {
    width: 36px; height: 36px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.dark-mode-toggle:hover {
    background: var(--bg-light);
    color: var(--primary-color);
}
.dark-mode-toggle svg { width: 20px; height: 20px; }

/* Moon icon (shown in light mode) */
.icon-moon { display: block; }
.icon-sun { display: none; }
body.dark-mode .icon-moon { display: none; }
body.dark-mode .icon-sun { display: block; }

/* Smooth transition for dark mode switch */
body, body *, body *::before, body *::after {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ==================== Tablet (769-1024px) ==================== */
@media (min-width: 769px) and (max-width: 1024px) {
    .hide-tablet { display: table-cell !important; }
}

/* ==================== Desktop (>1024px) ==================== */
@media (min-width: 1025px) {
    .hide-mobile { display: table-cell !important; }
    .hide-tablet { display: table-cell !important; }
}

/* ==================== Action buttons touch-friendly ==================== */
.action-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
}
