* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 隐藏滚动条但保持滚动功能 */
body {
    overflow-y: auto;
    scrollbar-width: auto;
    /* Firefox */
    -ms-overflow-style: auto;
    /* IE and Edge */
}

body::-webkit-scrollbar {
    width: 8px;
    /* Chrome, Safari, Opera */
}

body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-secondary: rgba(51, 65, 85, 0.5);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border: rgba(148, 163, 184, 0.1);
}

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-primary);
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
.header {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px 32px;
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.logo h1 {
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(135deg, #fff, #cbd5e1);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    gap: 12px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

/* Cards */
.cards-grid {
    display: grid;
    gap: 20px;
}

.card {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

/* Collapsed card - compact style */
.card.collapsed {
    padding: 16px 20px;
}

.card.collapsed .card-header {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

/* 卡片内容区域 - 平滑展开 */
.card-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

/* New horizontal layout */
.site-info-row {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1;
}

.site-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
    min-width: 120px;
}

.name-text {
    white-space: nowrap;
}

.site-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    flex: 1;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-compact {
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    white-space: nowrap;
    border: 1px solid var(--border);
}

.traffic-stat {
    position: relative;
    padding-bottom: 6px;
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
}

.mini-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 0 0 6px 6px;
    transition: width 0.3s ease;
}

.site-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.status-online {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.status-offline {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.status-loading {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Rules Table */
.rules-table {
    width: 100%;
    border-collapse: collapse;
}

.rules-table th {
    text-align: left;
    padding: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}

.rules-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.rules-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease;
    margin: auto;
}

.modal-large {
    max-width: 900px;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.form-input,
select.form-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.3s ease;
}

.form-input:focus,
select.form-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
}

/* 下拉选项样式 */
select.form-input option {
    background: #1e293b;
    color: var(--text-primary);
    padding: 8px;
}

/* 自定义多选下拉框样式 */
.custom-select-wrapper {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
    user-select: none;
    position: relative;
    padding-right: 40px;
}

.custom-select-trigger::after {
    content: '';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--text-secondary);
    pointer-events: none;
}

.custom-select-trigger:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
}

.dropdown-arrow {
    font-size: 12px;
    transition: transform 0.3s ease;
}

.custom-select-dropdown.active~.custom-select-trigger .dropdown-arrow {
    transform: rotate(180deg);
}

.custom-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #1e293b;
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.custom-select-dropdown.active {
    display: block;
    animation: dropdownSlideIn 0.2s ease;
}

@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.custom-select-option {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s ease;
    user-select: none;
}

.custom-select-option:hover:not(.disabled) {
    background: rgba(255, 255, 255, 0.05);
}

.custom-select-option.selected {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
}

.custom-select-option.disabled {
    color: #888;
    cursor: not-allowed;
    opacity: 0.5;
}

.custom-checkbox {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.custom-select-option.selected .custom-checkbox {
    background: var(--success);
    border-color: var(--success);
}

.custom-checkbox-check {
    display: none;
    color: white;
    font-size: 14px;
    font-weight: bold;
}

.custom-select-option.selected .custom-checkbox-check {
    display: block;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Loading Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Action Buttons */
.action-btns {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Domain List */
.domain-list,
.failover-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
}

.domain-item,
.failover-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.domain-info,
.failover-info {
    flex: 1;
}

.domain-name,
.failover-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.domain-ip,
.failover-status {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Logs */
.logs-container {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    margin-top: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.log-entry {
    margin-bottom: 4px;
    color: var(--text-secondary);
}

/* Collapse Icon */
.collapse-icon {
    display: inline-block;
    margin-right: 8px;
    transition: transform 0.3s ease;
    font-size: 12px;
}

/* Header Info (shown when collapsed) */
.header-info {
    display: inline-flex;
    gap: 12px;
    margin-left: 16px;
    align-items: center;
}

.traffic-badge,
.rules-badge {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    font-weight: 500;
}

.traffic-badge {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary);
}

.rules-badge {
    background: rgba(139, 92, 246, 0.15);
    color: var(--secondary);
}

/* Table Container for horizontal scroll */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .header {
        flex-direction: column;
        gap: 12px;
        padding: 16px;
    }

    .logo h1 {
        font-size: 20px;
    }

    .header-actions {
        flex-wrap: wrap;
        width: 100%;
        gap: 8px;
    }

    .header-actions .btn {
        flex: 1;
        min-width: 100px;
        padding: 8px 12px;
        font-size: 12px;
    }

    /* 移动端：启用水平滚动，保持桌面布局 */
    #sitesContainer {
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 10px;
    }

    .card {
        min-width: 1020px;
        /* 加宽卡片 */
        padding: 16px;
        overflow: visible;
        /* 确保内容可见 */
    }

    .card-header {
        margin-bottom: 12px;
        padding-bottom: 12px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    /* 保持桌面端的水平布局，不改为垂直 */
    .site-info-row {
        flex-wrap: nowrap;
        /* 不换行 */
        overflow-x: visible;
        flex: 1;
    }

    .site-stats {
        flex-wrap: nowrap;
        /* 标签不换行 */
        gap: 12px;
        /* 添加标签之间的间距 */
    }

    .stat-compact {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* 确保操作按钮区域在卡片内 */
    .site-actions {
        gap: 8px;
        margin-left: 5px;
    }

    .action-btns {
        display: flex;
        gap: 8px;
        flex-shrink: 0;
    }

    .site-name {
        font-size: 16px;
        min-width: auto;
    }

    .site-stats {
        gap: 8px;
        width: 100%;
    }

    .stat-compact {
        font-size: 11px;
        padding: 3px 8px;
    }

    .site-actions {
        width: 100%;
        justify-content: space-between;
    }

    .header-info {
        margin-left: 0;
        margin-top: 8px;
        width: 100%;
        gap: 8px;
    }

    .traffic-badge,
    .rules-badge {
        font-size: 11px;
        padding: 3px 8px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stat-item {
        padding: 12px;
    }

    .stat-label {
        font-size: 11px;
    }

    .stat-value {
        font-size: 16px;
    }

    /* 规则表格 - 启用水平滚动而不是隐藏列 */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .rules-table {
        font-size: 11px;
        min-width: 800px;
        /* 保持表格最小宽度，需要滚动查看 */
    }

    .rules-table th,
    .rules-table td {
        padding: 6px 4px;
        white-space: nowrap;
        /* 防止文字换行 */
    }

    .icon-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .modal-content {
        padding: 20px;
        width: 95%;
    }

    .modal-header {
        font-size: 18px;
    }

    .form-input {
        padding: 10px 12px;
        font-size: 13px;
    }

    .btn {
        padding: 8px 16px;
        font-size: 13px;
    }
}