:root {
    --sidebar-width: 220px;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #3b82f6;
    --content-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--content-bg);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 14px;
}

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

/* 布局 */
.layout {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.sidebar-nav {
    flex: 1;
    padding: 15px 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    transition: all 0.2s;
}

.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: #fff;
    text-decoration: none;
}

.sidebar-nav a.active {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-nav a svg {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    opacity: 0.7;
}

.sidebar-nav a.active svg,
.sidebar-nav a:hover svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    color: rgba(255,255,255,0.5);
    font-size: 13px;
}

.sidebar-footer a:hover {
    color: #fff;
    text-decoration: none;
}

/* 主内容区 */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 30px;
    min-height: 100vh;
}

.page-header {
    margin-bottom: 25px;
}

.page-header h2 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.page-header p {
    color: var(--text-secondary);
    margin-top: 5px;
}

/* 卡片 */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 20px;
}

.card-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--info);
    color: #fff;
}
.btn-primary:hover { background: #2563eb; }

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover { background: #16a34a; }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: #dc2626; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.btn-outline:hover { background: var(--content-bg); }

.btn-sm {
    padding: 5px 10px;
    font-size: 13px;
}

.btn-link {
    background: none;
    border: none;
    color: var(--info);
    padding: 0;
    cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

.btn-link-danger {
    color: var(--danger);
}

/* 表单 */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--info);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

select.form-control {
    cursor: pointer;
}

.form-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-section {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 16px;
}

.form-section-header {
    padding: 12px 16px;
    background: var(--content-bg);
    border-bottom: 1px solid var(--border-color);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.form-section-header:hover {
    background: #e2e8f0;
}

.form-section-body {
    padding: 16px;
}

.form-section.collapsed .form-section-body {
    display: none;
}

.form-section-header .arrow {
    transition: transform 0.2s;
}

.form-section.collapsed .form-section-header .arrow {
    transform: rotate(-90deg);
}

/* 开关 */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #cbd5e1;
    border-radius: 24px;
    transition: 0.3s;
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.switch input:checked + .switch-slider {
    background: var(--success);
}

.switch input:checked + .switch-slider:before {
    transform: translateX(20px);
}

/* 表格 */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    background: var(--content-bg);
}

.table tr:hover {
    background: #f8fafc;
}

.table-actions {
    display: flex;
    gap: 10px;
}

/* 标签 */
.tag {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    margin: 2px;
}

.tag-blue { background: #dbeafe; color: #1d4ed8; }
.tag-green { background: #dcfce7; color: #15803d; }
.tag-yellow { background: #fef3c7; color: #b45309; }
.tag-red { background: #fee2e2; color: #b91c1c; }
.tag-gray { background: #f1f5f9; color: #475569; }

/* 状态 */
.status {
    display: inline-flex;
    align-items: center;
    font-size: 13px;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-on .status-dot { background: var(--success); }
.status-off .status-dot { background: #cbd5e1; }

/* 提示 */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-success {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.alert-danger {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fde68a;
}

/* 紧急停用框 */
.emergency-box {
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    border: 2px solid var(--danger);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.emergency-box.active {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

.emergency-box h3 {
    color: var(--danger);
    margin-bottom: 10px;
}

/* 分页 */
.pagination {
    display: flex;
    gap: 5px;
    margin-top: 20px;
}

.pagination a,
.pagination span {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
}

.pagination a:hover {
    background: var(--content-bg);
    text-decoration: none;
}

.pagination .current {
    background: var(--info);
    color: #fff;
    border-color: var(--info);
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
}

/* 代码块 */
code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 13px;
}

/* 登录页 */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-box {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.login-box h2 {
    text-align: center;
    margin-bottom: 30px;
    font-size: 22px;
}

.login-box .form-control {
    padding: 12px 15px;
}

.login-box .btn {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    margin-top: 10px;
}

/* 规则卡片 */
.rule-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 12px;
    display: flex;
    align-items: flex-start;
    gap: 15px;
    transition: box-shadow 0.2s;
}

.rule-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.rule-card.disabled {
    opacity: 0.6;
    background: #f8fafc;
}

.rule-order {
    width: 32px;
    height: 32px;
    background: var(--content-bg);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.rule-content {
    flex: 1;
    min-width: 0;
}

.rule-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.rule-action {
    font-weight: 600;
    font-size: 15px;
}

.rule-action-301,
.rule-action-302 { color: var(--info); }
.rule-action-append { color: var(--warning); }
.rule-action-pass { color: var(--text-secondary); }

.rule-remark {
    color: var(--text-secondary);
    font-size: 13px;
}

.rule-tags {
    margin-bottom: 8px;
}

.rule-target {
    font-size: 13px;
    color: var(--text-secondary);
    word-break: break-all;
}

.rule-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

/* 手机适配 */
.menu-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 200;
    width: 40px;
    height: 40px;
    background: var(--sidebar-bg);
    border: none;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main {
        margin-left: 0;
        padding: 70px 15px 30px;
    }
    
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .rule-card {
        flex-direction: column;
    }
    
    .rule-actions {
        flex-direction: row;
        width: 100%;
    }
}

/* 遮罩 */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 50;
}

.overlay.show {
    display: block;
}
