* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --admin-primary: #4f46e5;
    --admin-primary-hover: #4338ca;
    --admin-secondary: #6b7280;
    --admin-success: #10b981;
    --admin-danger: #ef4444;
    --admin-warning: #f59e0b;
    --admin-info: #3b82f6;
    --admin-dark: #1f2937;
    --admin-sidebar-bg: #1e293b;
    --admin-sidebar-hover: #334155;
    --admin-sidebar-active: #4f46e5;
    --admin-text: #374151;
    --admin-text-light: #9ca3af;
    --admin-text-sidebar: #cbd5e1;
    --admin-bg: #f1f5f9;
    --admin-bg-white: #ffffff;
    --admin-border: #e5e7eb;
    --admin-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --admin-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --admin-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --admin-radius-sm: 4px;
    --admin-radius: 8px;
    --admin-radius-lg: 12px;
    --admin-sidebar-width: 250px;
    --admin-header-height: 60px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--admin-text);
    background: var(--admin-bg);
}

a {
    color: var(--admin-primary);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--admin-primary-hover);
}

body.login-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 400px;
    background: var(--admin-bg-white);
    border-radius: var(--admin-radius-lg);
    padding: 40px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

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

.login-header h1 {
    font-size: 28px;
    color: var(--admin-dark);
    margin-bottom: 8px;
}

.login-header p {
    color: var(--admin-secondary);
}

.admin-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--admin-sidebar-width);
    background: var(--admin-sidebar-bg);
    color: var(--admin-text-sidebar);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-brand {
    height: var(--admin-header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    font-size: 20px;
    font-weight: 700;
    color: white;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-nav {
    padding: 16px 0;
    list-style: none;
}

.sidebar-nav .nav-item {
    margin-bottom: 2px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--admin-text-sidebar);
    transition: all 0.2s;
    cursor: pointer;
}

.sidebar-nav .nav-link:hover {
    background: var(--admin-sidebar-hover);
    color: white;
}

.sidebar-nav .nav-link.active {
    background: var(--admin-sidebar-active);
    color: white;
}

.sidebar-nav .nav-icon {
    width: 20px;
    margin-right: 12px;
    text-align: center;
}

.sidebar-nav .submenu {
    list-style: none;
    background: rgba(0, 0, 0, 0.2);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s;
}

.sidebar-nav .submenu.open {
    max-height: 500px;
}

.sidebar-nav .submenu .nav-link {
    padding-left: 52px;
    font-size: 13px;
}

.sidebar-nav .nav-arrow {
    margin-left: auto;
    transition: transform 0.2s;
}

.sidebar-nav .nav-item.open .nav-arrow {
    transform: rotate(90deg);
}

.main-wrapper {
    flex: 1;
    margin-left: var(--admin-sidebar-width);
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--admin-header-height);
    background: var(--admin-bg-white);
    border-bottom: 1px solid var(--admin-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--admin-shadow-sm);
}

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

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--admin-text);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
    font-size: 14px;
}

.breadcrumb li {
    color: var(--admin-text-light);
}

.breadcrumb li a {
    color: var(--admin-text);
}

.breadcrumb li + li::before {
    content: '/';
    margin-right: 8px;
    color: var(--admin-text-light);
}

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

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--admin-radius);
    transition: background 0.2s;
}

.topbar-user:hover {
    background: var(--admin-bg);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--admin-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}

.user-name {
    font-weight: 500;
}

.page-content {
    padding: 24px;
    flex: 1;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--admin-dark);
}

.page-actions {
    display: flex;
    gap: 8px;
}

.card {
    background: var(--admin-bg-white);
    border-radius: var(--admin-radius);
    box-shadow: var(--admin-shadow-sm);
    margin-bottom: 24px;
}

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

.card-title {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--admin-bg-white);
    border-radius: var(--admin-radius);
    padding: 20px;
    box-shadow: var(--admin-shadow-sm);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--admin-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-icon.primary { background: #eef2ff; color: var(--admin-primary); }
.stat-icon.success { background: #ecfdf5; color: var(--admin-success); }
.stat-icon.warning { background: #fffbeb; color: var(--admin-warning); }
.stat-icon.danger { background: #fef2f2; color: var(--admin-danger); }
.stat-icon.info { background: #eff6ff; color: var(--admin-info); }

.stat-info h3 {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-info p {
    color: var(--admin-text-light);
    font-size: 13px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--admin-radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.5;
}

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

.btn-primary:hover {
    background: var(--admin-primary-hover);
    color: white;
}

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

.btn-success:hover {
    background: #059669;
    color: white;
}

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

.btn-danger:hover {
    background: #dc2626;
    color: white;
}

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

.btn-warning:hover {
    background: #d97706;
    color: white;
}

.btn-secondary {
    background: var(--admin-bg);
    color: var(--admin-text);
    border: 1px solid var(--admin-border);
}

.btn-secondary:hover {
    background: var(--admin-border);
    color: var(--admin-text);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 16px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
}

.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--admin-border);
}

.data-table th {
    background: var(--admin-bg);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--admin-text-light);
}

.data-table tbody tr:hover {
    background: var(--admin-bg);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.table-actions {
    display: flex;
    gap: 6px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #e5e7eb; color: #374151; }

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius-sm);
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--admin-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-control-sm {
    padding: 4px 8px;
    font-size: 13px;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 8px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 32px;
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 16px;
    height: 16px;
}

.form-help {
    font-size: 12px;
    color: var(--admin-text-light);
    margin-top: 4px;
}

.form-error {
    color: var(--admin-danger);
    font-size: 12px;
    margin-top: 4px;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--admin-radius-sm);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

.alert-danger {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.alert-warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.alert-info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.pagination {
    display: flex;
    justify-content: center;
    margin-top: 24px;
}

.pagination-list {
    display: flex;
    gap: 4px;
    list-style: none;
}

.pagination-list li a,
.pagination-list li span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border-radius: var(--admin-radius-sm);
    font-size: 13px;
    color: var(--admin-text);
    border: 1px solid var(--admin-border);
    transition: all 0.2s;
}

.pagination-list li a:hover {
    background: var(--admin-primary);
    color: white;
    border-color: var(--admin-primary);
}

.pagination-list li.active span {
    background: var(--admin-primary);
    color: white;
    border-color: var(--admin-primary);
}

.pagination-list li.disabled span {
    color: var(--admin-text-light);
    cursor: not-allowed;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 16px;
    flex-wrap: wrap;
}

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

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

.search-input {
    position: relative;
}

.search-input input {
    padding-left: 36px;
    width: 240px;
}

.search-input::before {
    content: '🔍';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--admin-bg-white);
    border-radius: var(--admin-radius);
    padding: 20px;
    box-shadow: var(--admin-shadow-sm);
}

.chart-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.chart-placeholder {
    height: 280px;
    background: var(--admin-bg);
    border-radius: var(--admin-radius-sm);
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    color: var(--admin-text-light);
    padding: 12px;
    position: relative;
}
.chart-placeholder > canvas {
    width: 100% !important;
    height: 100% !important;
    position: relative;
    z-index: 1;
}

.tabs {
    display: flex;
    border-bottom: 1px solid var(--admin-border);
    margin-bottom: 20px;
}

.tab-item {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    color: var(--admin-text-light);
    transition: all 0.2s;
    font-weight: 500;
}

.tab-item:hover {
    color: var(--admin-text);
}

.tab-item.active {
    color: var(--admin-primary);
    border-bottom-color: var(--admin-primary);
}

.config-section {
    margin-bottom: 32px;
}

.config-section h3 {
    font-size: 18px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--admin-border);
}

.log-list {
    list-style: none;
}

.log-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--admin-border);
    display: flex;
    gap: 12px;
}

.log-item:last-child {
    border-bottom: none;
}

.log-time {
    color: var(--admin-text-light);
    font-size: 12px;
    white-space: nowrap;
}

.log-level {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.log-level.info { background: #dbeafe; color: #1e40af; }
.log-level.warning { background: #fef3c7; color: #92400e; }
.log-level.error { background: #fee2e2; color: #991b1b; }

.log-message {
    flex: 1;
}

.system-info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.info-item {
    padding: 16px;
    background: var(--admin-bg);
    border-radius: var(--admin-radius-sm);
}

.info-label {
    font-size: 12px;
    color: var(--admin-text-light);
    margin-bottom: 4px;
}

.info-value {
    font-size: 16px;
    font-weight: 600;
}

@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .chart-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .system-info-grid {
        grid-template-columns: 1fr;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-left,
    .toolbar-right {
        flex-wrap: wrap;
    }

    .page-content {
        padding: 16px;
    }
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

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

/* ========== 管理端响应式增强 ========== */

/* 表格横滚容器 + 小屏卡式化 */
.data-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--admin-radius);
}

.data-table {
    min-width: 100%;
    width: max-content;
}

/* 侧栏默认横排宽度 */
.sidebar {
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
    z-index: 101;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--admin-sidebar-width);
}

.sidebar-toggle {
    display: none;
    background: transparent;
    border: 0;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    padding: 0;
    flex-shrink: 0;
}
.sidebar-toggle:hover {
    background: rgba(255,255,255,0.1);
}
.sidebar-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
}

/* 登录页移动端适配 */
@media (max-width: 640px) {
    body.login-page {
        padding: 20px 16px;
    }
    .login-wrap {
        padding: 0 !important;
        width: 100% !important;
    }
    .login-card {
        padding: 28px 20px !important;
    }
    .login-card h2 {
        font-size: 22px;
    }
}

/* 中等屏幕及以下：表格式+工具栏细节 */
@media (max-width: 768px) {
    .admin-header {
        padding: 0 16px;
    }
    .header-right {
        gap: 10px;
    }
    .user-name {
        display: none;
    }
    .btn {
        padding: 8px 12px;
        font-size: 13px;
    }
    .btn .icon {
        margin-right: 4px;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .toolbar-left,
    .toolbar-right {
        width: 100%;
        justify-content: flex-start;
    }
    .search-input {
        flex: 1;
        min-width: 0;
    }
    .toolbar select,
    .toolbar .input {
        max-width: 100%;
    }

    /* 表格：卡式化，每一行变卡片 */
    .data-table thead {
        display: none;
    }
    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100% !important;
    }
    .data-table tr {
        background: var(--admin-bg-white);
        border: 1px solid var(--admin-border);
        border-radius: var(--admin-radius);
        padding: 14px 16px 4px;
        margin-bottom: 12px;
        box-shadow: var(--admin-shadow-sm);
    }
    .data-table td {
        padding: 6px 0 !important;
        border: 0 !important;
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
        text-align: right;
    }
    .data-table td::before {
        content: attr(data-label);
        flex-shrink: 0;
        color: var(--admin-text-light);
        font-size: 12px;
        font-weight: 500;
        text-align: left;
        padding-right: 12px;
        min-width: 30%;
    }
    .data-table td:first-child::before { content: 'ID'; }
    .data-table .row-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    .pagination {
        flex-wrap: wrap;
        gap: 6px;
    }
    .pagination .page-info {
        order: 99;
        width: 100%;
        text-align: center;
        padding-top: 6px;
    }
    .user-info .user-greeting {
        display: none;
    }
}

/* 内容自适应 */
.admin-wrapper .page-content {
    word-break: break-word;
    overflow-wrap: anywhere;
}
.editor-toolbar {
    flex-wrap: wrap;
}
.comment-body {
    word-break: break-word;
}
.log-item {
    flex-wrap: wrap;
}
.log-time {
    width: 100%;
    margin-top: 4px;
}

/* 图表/统计卡自适应内边距 */
@media (max-width: 480px) {
    .stat-card {
        padding: 16px;
    }
    .stat-card .stat-value {
        font-size: 22px;
    }
    .card {
        padding: 16px;
    }
    .card-header {
        padding: 14px 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
}

.progress-bar {
    height: 8px;
    background: var(--admin-bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar .progress-fill {
    height: 100%;
    background: var(--admin-primary);
    border-radius: 4px;
    transition: width 0.3s;
}

.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--admin-bg-white);
    border-radius: var(--admin-radius);
    box-shadow: var(--admin-shadow-md);
    min-width: 160px;
    padding: 8px 0;
    list-style: none;
    display: none;
    z-index: 1000;
}

.dropdown.open .dropdown-menu {
    display: block;
}

.dropdown-menu li a {
    display: block;
    padding: 8px 16px;
    color: var(--admin-text);
    font-size: 14px;
}

.dropdown-menu li a:hover {
    background: var(--admin-bg);
}
