/* --- UI CSS (V3.2.6 "Hybrid" Optimized) --- */
:root {
    --font-family-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --font-family-mono: "SFMono-Regular", "Consolas", "Roboto Mono", monospace;
    --font-family-serif: "Georgia", "Times New Roman", serif;
    --border-radius-xl: 20px;
    --border-radius-lg: 16px;
    --border-radius-md: 12px;
    --border-radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 30px -5px rgba(0, 0, 0, 0.1), 0 8px 16px -8px rgba(0, 0, 0, 0.06);
    --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-med: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 主题色系统 */
[data-color-scheme="indigo"] {
    --color-accent-primary: #4f46e5;
    --color-accent-primary-hover: #4338ca;
    --glow-color: rgba(79, 70, 229, 0.2);
}

[data-color-scheme="pink"] {
    --color-accent-primary: #ec4899;
    --color-accent-primary-hover: #db2777;
    --glow-color: rgba(236, 72, 153, 0.2);
}

[data-color-scheme="teal"] {
    --color-accent-primary: #14b8a6;
    --color-accent-primary-hover: #0d9488;
    --glow-color: rgba(20, 184, 166, 0.15);
}

[data-color-scheme="orange"] {
    --color-accent-primary: #f97316;
    --color-accent-primary-hover: #ea580c;
    --glow-color: rgba(249, 115, 22, 0.2);
}

[data-color-scheme="green"] {
    --color-accent-primary: #22c55e;
    --color-accent-primary-hover: #16a34a;
    --glow-color: rgba(34, 197, 94, 0.2);
}

[data-color-scheme="violet"] {
    --color-accent-primary: #8b5cf6;
    --color-accent-primary-hover: #7c3aed;
    --glow-color: rgba(139, 92, 246, 0.2);
}

[data-theme="dark"][data-color-scheme="indigo"] {
    --color-accent-primary: #6d9dff;
    --color-accent-primary-hover: #80b6f8;
    --glow-color: rgba(88, 166, 255, 0.15);
}

[data-theme="dark"][data-color-scheme="pink"] {
    --color-accent-primary: #f778ba;
    --color-accent-primary-hover: #f599ce;
    --glow-color: rgba(247, 120, 186, 0.15);
}

[data-theme="dark"][data-color-scheme="teal"] {
    --color-accent-primary: #2dd4bf;
    --color-accent-primary-hover: #5eead4;
    --glow-color: rgba(45, 212, 191, 0.15);
}

[data-theme="dark"][data-color-scheme="orange"] {
    --color-accent-primary: #fb923c;
    --color-accent-primary-hover: #fdba74;
    --glow-color: rgba(251, 146, 60, 0.15);
}

[data-theme="dark"][data-color-scheme="green"] {
    --color-accent-primary: #4ade80;
    --color-accent-primary-hover: #86efac;
    --glow-color: rgba(74, 222, 128, 0.15);
}

[data-theme="dark"][data-color-scheme="violet"] {
    --color-accent-primary: #a78bfa;
    --color-accent-primary-hover: #c4b5fd;
    --glow-color: rgba(167, 139, 250, 0.15);
}

/* 基础明暗主题变量 */
[data-theme="light"] {
    --color-bg: #f3f5f9;
    --color-bg-card: #ffffff;
    --color-bg-alt: #eef1f7;
    --color-text-primary: #0f172a;
    --color-text-secondary: #64748b;
    --color-border: #e2e8f0;
    --color-accent-secondary: #ec4899;
    --color-accent-text: #ffffff;
    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --glow-border-color: rgba(79, 70, 229, 0.3);
    --color-bg-blocked: rgba(239, 68, 68, 0.07);
    --color-bg-fail: rgba(245, 158, 11, 0.07);
}

[data-theme="dark"] {
    --color-bg: #0f121a;
    --color-bg-card: #191e29;
    --color-bg-alt: #222836;
    --color-text-primary: #c9d1d9;
    --color-text-secondary: #8b949e;
    --color-border: #30363d;
    --color-accent-secondary: #f778ba;
    --color-accent-text: #0f172a;
    --color-danger: #f87171;
    --color-danger-hover: #ff9191;
    --color-success: #56d364;
    --color-warning: #facc15;
    --glow-border-color: rgba(88, 166, 255, 0.25);
    --color-bg-blocked: rgba(248, 113, 113, 0.1);
    --color-bg-fail: rgba(250, 204, 21, 0.1);
}

/* --- 基础样式 --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--color-accent-primary) 40%, transparent);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: color-mix(in srgb, var(--color-accent-primary) 60%, transparent);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family-sans);
    background-color: var(--color-bg);
    color: var(--color-text-primary);
    margin: 0;
    position: relative;
    overflow-x: hidden;
    transition: background-color var(--transition-slow), color var(--transition-slow);
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 400px;
    background: linear-gradient(180deg, var(--glow-color) 0%, transparent 100%);
    z-index: 0;
    pointer-events: none;
    transition: var(--transition-slow);
}

.container {
    max-width: 1300px;
    margin: 0 auto;
    padding: 2rem;
    position: relative;
    z-index: 1;
    width: 100%;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

h2 {
    font-size: 1.35rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    line-height: 1.3;
}

h2 svg {
    width: 1.25em;
    height: 1.25em;
    color: var(--color-accent-primary);
}

h3 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

a {
    color: var(--color-accent-primary);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition-fast);
}

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

.text-right {
    text-align: right;
}

/* 居中辅助类，供“耗时”列使用 */
.text-center {
    text-align: center;
}

/* 等宽数字，解决“耗时”等数字列视觉错位问题 */
.numeric {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1, 'lnum' 1;
}

.duration-cell {
    white-space: nowrap;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.header-main-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
    max-width: 100%;
}

.last-updated {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.nav-wrapper {
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
}

.main-nav {
    display: inline-flex;
    background-color: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 0.25rem;
}

.main-nav-slider {
    position: absolute;
    top: 0.25rem;
    bottom: 0.25rem;
    border-radius: var(--border-radius-sm);
    background: var(--color-accent-primary);
    box-shadow: var(--shadow-md);
    transition: all var(--transition-med);
    z-index: 0;
    will-change: transform, width;
}

.main-nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.6rem 1.1rem;
    color: var(--color-text-primary);
    opacity: 0.7;
    font-weight: 600;
    font-size: 0.95rem;
    position: relative;
    z-index: 1;
    transition: color var(--transition-med), opacity var(--transition-med);
    white-space: nowrap;
}

.main-nav a:hover:not(.active),
.main-nav a.active {
    opacity: 1;
}

[data-theme="light"] .main-nav a.active {
    color: var(--color-accent-text) !important;
}

[data-theme="dark"] .main-nav a.active {
    color: #fff !important;
}

.main-nav a .status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: currentColor;
    opacity: 0.6;
    transition: all var(--transition-med);
}

.main-nav a.active .status-indicator {
    opacity: 1;
}

.main-nav a .status-indicator.running {
    background-color: var(--color-success);
    opacity: 1;
    animation: pulse-small 2s infinite;
}

.main-nav a .status-indicator.stopped {
    background-color: var(--color-danger);
    opacity: 1;
}

@keyframes pulse-small {

    0%,
    100% {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-success) 40%, transparent);
    }

    70% {
        box-shadow: 0 0 0 5px transparent;
    }
}

.refresh-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: var(--border-radius-md);
    background-color: var(--color-bg-alt);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.refresh-btn:hover:not(:disabled):not([aria-busy="true"]) {
    color: var(--color-accent-primary);
    border-color: var(--color-accent-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.refresh-btn:hover:not(:disabled):not([aria-busy="true"]) svg {
    transform: rotate(45deg);
}

.refresh-btn[aria-busy="true"] {
    cursor: wait;
    pointer-events: none;
}

.refresh-btn[aria-busy="true"] svg {
    animation: spin 1s linear infinite;
}

.refresh-btn:active:not(:disabled) {
    transform: scale(0.95);
    box-shadow: none;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    padding: 1.5rem;
    border-radius: var(--border-radius-xl);
    position: relative;
    overflow: hidden;
    color: var(--color-accent-text);
    box-shadow: var(--shadow-lg);
    transition: transform var(--transition-med), box-shadow var(--transition-med);
    background-size: cover;
    background-position: center;
    will-change: transform, box-shadow;
}

.icon-bg-pattern {
    position: absolute;
    inset: 0;
    opacity: 0.1;
}

.stat-card.default-gradient-1 {
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
}

.stat-card.theme-gradient {
    background: linear-gradient(135deg, var(--color-accent-primary) 0%, var(--color-accent-secondary) 100%);
}

.stat-card:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 15px 30px -10px color-mix(in srgb, var(--color-accent-primary) 30%, black);
}

.stat-card-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.stat-card h3 {
    color: var(--color-accent-text);
    opacity: 0.8;
    text-transform: none;
    font-size: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.stat-card-main {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    margin-top: 0.75rem;
    flex-grow: 1;
}

.stat-card .value {
    font-size: 2.75rem;
    font-weight: 800;
    line-height: 1;
}

.stat-change {
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 99px;
    background-color: rgba(255, 255, 255, 0.15);
    margin-bottom: 0.2rem;
}

.stat-change.up {
    color: #bef264;
}

.stat-change.down {
    color: #fca5a5;
}

.stat-change svg {
    width: 1.1em;
    height: 1.1em;
}

.sparkline-container {
    position: relative;
    margin-top: auto;
    height: 50px;
}

.sparkline-path {
    stroke: var(--color-accent-primary);
    stroke-width: 2.0;
    fill: url(#sparkline-gradient);
    fill-opacity: 0.15;
    stroke-linecap: round;
    stroke-linejoin: round;
}

[data-theme="light"] .sparkline-path,
[data-theme="dark"] .sparkline-path {
    stroke: var(--color-accent-text);
}

#sparkline-gradient stop {
    stop-color: var(--color-accent-primary);
}

[data-theme="light"] #sparkline-gradient stop,
[data-theme="dark"] #sparkline-gradient stop {
    stop-color: var(--color-accent-text);
}

.card {
    background-color: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-lg);
    /* Softer radius */
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
    position: relative;
    overflow: hidden;
    /* Contain pseudo-elements */
}

.card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(400px circle at var(--glow-x, 50%) var(--glow-y, 50%), var(--glow-color), transparent 40%);
    opacity: 0;
    transition: opacity 0.4s ease-out;
    pointer-events: none;
    z-index: 0;
}

.card:hover {
    border-color: var(--glow-border-color);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.card:hover::before {
    opacity: 1;
}

.card>* {
    position: relative;
    z-index: 1;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.card-body {
    padding: 1.5rem;
}

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

.card-header .header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-grow: 1;
    justify-content: flex-end;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1rem;
    flex-wrap: wrap;
}

.control-item strong {
    color: var(--color-text-primary);
    font-weight: 500;
    flex-shrink: 0;
}

.control-item>div,
.control-item>form,
.control-item>button,
.control-item>select {
    margin-left: auto;
}

/* Universal Form Inputs */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="datetime-local"],
select,
.input {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    color: var(--color-text-primary);
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    box-sizing: border-box;
    min-height: 40px;
}

select {
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
}

[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23c9d1d9' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--color-accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
    /* Indigo tint */
}

/* Datetime Icon Styling */
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
    margin-left: auto;
}

[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
    opacity: 0.8;
}

.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 0.5rem;
}

#capacity-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
}

a.control-item-link {
    all: unset;
    box-sizing: border-box;
    text-decoration: none;
    color: inherit;
    display: inline-block;
    cursor: pointer;
    font-weight: 600;
    color: var(--color-accent-primary);
    text-decoration: underline;
}

a.control-item-link:hover {
    color: var(--color-accent-primary-hover);
}

#domain-stats-table td {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

#domain-stats-table td:first-child strong {
    font-weight: 500;
}

#domain-stats-table,
#cache-stats-table {
    table-layout: auto;
}

#cache-stats-table th:first-child,
#domain-stats-table th:first-child {
    width: 25%;
}

/* 避免“Fake IP 域名”等在桌面视口被逐字换行，保持一行显示并超出省略 */
@media (min-width: 992px) {

    #domain-stats-table td:first-child,
    #domain-stats-table th:first-child {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}


.control-item-static {
    border-top: 1px solid var(--color-border);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}


.auto-refresh-form {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.auto-refresh-form input[type="number"] {
    width: 80px;
    text-align: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    vertical-align: middle;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--color-border);
    transition: var(--transition-fast);
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: var(--transition-fast);
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--color-accent-primary);
}

input:checked+.slider:before {
    transform: translateX(22px);
}

.color-palette {
    display: flex;
    gap: 0.5rem;
}

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: var(--transition-fast);
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: var(--color-accent-primary);
}

#theme-switcher-select {
    max-width: 200px;
}

#layout-density-select {
    max-width: 200px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: all var(--transition-fast);
}

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

.button:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
    box-shadow: var(--shadow-sm);
}

.button.primary {
    background-color: var(--color-accent-primary);
    color: var(--color-accent-text);
    border-color: var(--color-accent-primary);
}

.button.primary:hover:not(:disabled) {
    background-color: var(--color-accent-primary-hover);
    border-color: var(--color-accent-primary-hover);
}

[data-theme="dark"] .button.primary {
    color: #fff;
}

.button.secondary {
    background-color: var(--color-bg-card);
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

.button.secondary:hover:not(:disabled) {
    border-color: var(--color-accent-primary);
    color: var(--color-accent-primary);
}

.button.danger {
    background-color: var(--color-danger);
    color: #fff;
}

.button.danger:hover:not(:disabled) {
    background-color: var(--color-danger-hover);
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.button svg {
    width: 1.2em;
    height: 1.2em;
}

input[type="search"],
input[type="url"],
textarea {
    width: 100%;
    padding: 0.8rem 1.2rem;
    font-size: 1rem;
    background-color: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    color: var(--color-text-primary);
    transition: var(--transition-fast);
    font-family: var(--font-family-sans);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

textarea:focus,
input[type="search"]:focus {
    outline: none;
    border-color: var(--color-accent-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent-primary) 25%, transparent);
}

#search-results-info {
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    height: 1.2em;
    transition: opacity 0.3s;
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2rem;
    margin-top: 2.5rem;
}

.scrollable-table-container {
    max-height: 400px;
    overflow-y: auto;
    position: relative;
}

.overview-grid .scrollable-table-container {
    max-height: 350px;
}

#log-query-table-container {
    max-height: calc(100vh - 380px);
    min-height: 200px;
}

#adguard-table-container,
#diversion-table-container {
    max-height: calc(100vh - 350px);
    min-height: 300px;
}

#data-view-table-container {
    max-height: 50vh;
}

/* Data View: Cache Accordion */
#data-view-modal .accordion-item {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    background: var(--color-bg);
    margin-bottom: 0.75rem;
    overflow: hidden;
}

#data-view-modal .accordion-header {
    margin: 0;
}

#data-view-modal .accordion-button {
    width: 100%;
    text-align: left;
    border: 0;
    background: var(--color-bg-alt);
    padding: 0.75rem 1rem;
    color: var(--color-text-primary);
    font-weight: 600;
    cursor: pointer;
}

#data-view-modal .accordion-button::after {
    content: '▾';
    float: right;
    transition: transform 0.2s ease;
}

#data-view-modal .accordion-button.collapsed::after {
    transform: rotate(-90deg);
}

#data-view-modal .accordion-collapse {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

#data-view-modal .accordion-collapse.show {
    border-top: 1px solid var(--color-border);
}

#data-view-modal .accordion-body {
    padding: 0.75rem 1rem;
}

#data-view-modal .data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 0.75rem 0;
}

#data-view-modal .data-table td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
    word-break: break-all;
}

#data-view-modal .data-table td:first-child {
    color: var(--color-text-secondary);
    width: 9rem;
}

#data-view-modal pre {
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    padding: 0.6rem 0.8rem;
    border-radius: var(--border-radius-sm);
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
}


table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.95rem;
    table-layout: fixed;
}

th,
td {
    padding: 0.8rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    transition: background-color var(--transition-fast);
    word-break: break-word;
    vertical-align: middle;
}

thead th {
    background-color: var(--color-bg-alt);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-text-secondary);
}

.scrollable-table-container thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.scrollable-table-container thead {
    transition: padding-right 0.2s ease-in-out;
}

.domain-response-cell {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.domain-response-cell .domain-name {
    font-weight: 500;
}

.response-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--color-text-secondary);
}

.response-summary {
    flex-shrink: 1;
}

th[data-sortable] {
    cursor: pointer;
}

th[data-sortable]:hover {
    color: var(--color-text-primary);
}

.sort-indicator {
    display: inline-block;
    width: 1em;
    text-align: center;
    opacity: 0.5;
}

th.sorted .sort-indicator {
    opacity: 1;
}

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

tbody tr {
    transition: background-color var(--transition-fast), transform var(--transition-fast);
}

tbody tr:nth-child(even) {
    background-color: var(--color-bg-alt);
}

tbody tr:hover {
    background-color: color-mix(in srgb, var(--color-accent-primary) 8%, transparent);
    transform: scale(1.01);
    box-shadow: var(--shadow-sm);
    z-index: 1;
    position: relative;
}

tbody tr:hover .domain-name[style*="color"] {
    color: inherit !important;
}

tbody tr.is-blocked {
    background-color: var(--color-bg-blocked) !important;
}

tbody tr.is-fail {
    background-color: var(--color-bg-fail) !important;
}

@keyframes row-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

tbody tr.animate-in {
    animation: row-fade-in 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.truncate-text {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

tbody td a.clickable-link {
    position: relative;
    text-decoration: none;
}

tbody td a.clickable-link::after {
    content: '';
    position: absolute;
    width: 0;
    height: 1px;
    bottom: -3px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--color-accent-primary);
    transition: width var(--transition-fast);
}

tbody td a.clickable-link:hover::after {
    width: 100%;
}

tbody tr[data-log-index],
tbody tr[data-rank-index],
tbody tr[data-rule-id] {
    cursor: help;
}

.touch tbody tr[data-log-index],
.touch tbody tr[data-rank-index],
.touch [data-rule-id] {
    cursor: pointer;
}

.lazy-placeholder {
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    color: var(--color-text-secondary);
}

.empty-state-row td {
    text-align: center !important;
    padding: 3rem 1.5rem !important;
    white-space: normal !important;
}

.empty-state-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--color-text-secondary);
}

.empty-state-content svg {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

.empty-state-content strong {
    color: var(--color-text-primary);
    font-size: 1.1rem;
}

.empty-state-content .button {
    margin-top: 0.5rem;
}

.tab-content {
    display: none;
    margin-top: 2.5rem;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.client-alias {
    font-weight: 600;
}

.response-tag,
.rule-tag {
    padding: 0.2rem 0.6rem;
    font-size: 0.8rem;
    border-radius: var(--border-radius-sm);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}

.response-tag {
    font-weight: 700;
}

.response-tag.noerror {
    background-color: color-mix(in srgb, var(--color-success) 20%, transparent);
    color: var(--color-success);
}

.response-tag.nxdomain {
    background-color: color-mix(in srgb, var(--color-warning) 20%, transparent);
    color: var(--color-warning);
}

.response-tag.servfail {
    background-color: color-mix(in srgb, var(--color-danger) 20%, transparent);
    color: var(--color-danger);
}

.response-tag.refused {
    background-color: color-mix(in srgb, var(--color-danger) 25%, transparent);
    color: var(--color-danger);
}

.response-tag.other {
    background-color: var(--color-border);
    color: var(--color-text-secondary);
}

.rule-tag {
    font-weight: 600;
    gap: 0.4rem;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

.rule-tag::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: currentcolor;
    flex-shrink: 0;
}

.interactive-btn-container {
    display: inline-flex;
    gap: 0.5rem;
    vertical-align: middle;
    margin-left: 0.5rem;
}

#log-detail-modal .modal-body li span {
    display: flex;
    align-items: center;
}

#answers-tooltip {
    visibility: hidden;
    opacity: 0;
    position: fixed;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-md);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    width: max-content;
    max-width: calc(100vw - 20px);
    z-index: 9999;
    transition: opacity 0.2s, transform 0.2s;
    text-align: left;
    pointer-events: none;
    font-size: 0.9rem;
    transform: translateY(10px);
}

#answers-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#answers-tooltip h5 {
    margin: 0 0 0.75rem 0;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.5rem;
}

#answers-tooltip ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

#answers-tooltip li {
    font-family: var(--font-family-mono);
    white-space: normal;
    word-break: break-all;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

#answers-tooltip li>strong {
    font-family: var(--font-family-sans);
    flex-shrink: 0;
}

#answers-tooltip small {
    font-size: 0.85em;
    opacity: 0.8;
}

.copy-btn,
.filter-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 2px;
    border-radius: 4px;
    display: inline-flex;
    vertical-align: middle;
    transition: var(--transition-fast);
}

.copy-btn:hover,
.filter-btn:hover {
    color: var(--color-accent-primary);
    background-color: var(--color-border);
}

#toast {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-sm);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform: translateY(-20px) scale(0.95);
    box-shadow: var(--shadow-lg);
    color: var(--color-accent-text);
    font-weight: 500;
}

#toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

#toast.success {
    background-color: var(--color-success);
}

#toast.error {
    background-color: var(--color-danger);
}

#toast svg {
    width: 1.25em;
    height: 1.25em;
}

dialog {
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 0;
    max-width: 600px;
    width: 90%;
    background-color: var(--color-bg-card);
    color: var(--color-text-primary);
    overflow: hidden;
    /* Ensure content respects border-radius */
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

dialog[open] {
    animation: modal-fade-in 0.3s ease-out forwards;
    will-change: opacity, transform;
}

@keyframes modal-fade-in {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

dialog[open]::before {
    content: "";
    position: absolute;
    inset: -2px;
    /* Slightly larger inset for the glow */
    border-radius: inherit;
    border: 2px solid var(--glow-border-color);
    animation: modal-glow-pulse 2.5s ease-out forwards;
    pointer-events: none;
    z-index: -1;
}

@keyframes modal-glow-pulse {
    0% {
        opacity: 0.8;
        transform: scale(1);
    }

    100% {
        opacity: 0;
        transform: scale(1.02);
    }
}

/* Override card hover effects for dialogs */
dialog.card:hover::before {
    opacity: 0 !important;
}

dialog.card:hover {
    border-color: var(--color-border) !important;
    transform: none !important;
    box-shadow: var(--shadow-lg) !important;
}

.modal-header {
    padding: 1.25rem 1.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    background-color: var(--color-bg-alt);
    /* Subtle background for header */
    border-top-left-radius: var(--border-radius-xl);
    border-top-right-radius: var(--border-radius-xl);
}

.modal-body {
    padding: 1.75rem;
    max-height: 60vh;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.modal-footer {
    padding: 1.25rem 1.75rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    background-color: var(--color-bg-alt);
    border-bottom-left-radius: var(--border-radius-xl);
    border-bottom-right-radius: var(--border-radius-xl);
}

.modal-footer .footer-actions-right {
    display: flex;
    gap: 0.75rem;
    margin-left: auto;
}

#log-detail-modal .modal-body ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

#log-detail-modal .modal-body li {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

#log-detail-modal .modal-body li strong {
    flex-shrink: 0;
    color: var(--color-text-secondary);
}

#log-detail-modal .modal-body li span {
    word-break: break-all;
    text-align: right;
}

#log-detail-modal .modal-body h5 {
    margin: 1.25rem 0 0.75rem;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 0.5rem;
}

#log-detail-modal .modal-body h5:first-child {
    margin-top: 0;
}

.alias-item {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1rem;
    align-items: center;
    padding: 0.75rem;
    border-radius: var(--border-radius-sm);
}

.alias-item:nth-child(even) {
    background-color: var(--color-bg-alt);
}

#manual-alias-form {
    padding: 1.25rem;
    background: var(--color-bg-alt);
    border-radius: var(--border-radius-md);
    margin-bottom: 1.5rem;
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 1rem;
    align-items: center;
    border: 1px solid var(--color-border);
}

#initial-loader {
    position: fixed;
    inset: 0;
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s;
}

#log-loader {
    text-align: center;
    padding: 2rem;
    display: none;
}

.spinner {
    display: inline-block;
    width: 2.5rem;
    height: 2.5rem;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.control-panel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    align-items: stretch;
}

/* 在中等偏大的屏幕上（1288px~1600px）强制 3 栏栅格，使每张卡片有更合理的宽度 */
@media (min-width: 1288px) and (max-width: 1599.98px) {
    .control-panel-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    /* 让“版本与更新”模块占两列，避免按钮/徽标拥挤换行 */
    #update-module {
        grid-column: span 2;
    }
}

@media (min-width: 1400px) {
    .control-panel-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.control-module {
    background-color: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-xl);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.control-module h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    text-transform: none;
    letter-spacing: 0;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.control-module h3 svg {
    width: 1.1em;
    height: 1.1em;
    color: var(--color-accent-primary);
    opacity: 0.8;
}

.control-hint {
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 0;
}

#update-module {
    gap: 1rem;
    height: 100%;
}

#update-module .control-item-text {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
}

#update-module #update-status-text {
    width: 100%;
    margin: 0;
    padding: 0.8rem 0.9rem;
    background-color: var(--color-bg-alt);
    border-radius: var(--border-radius-md);
    border: 1px solid var(--color-border);
    min-height: 3.5rem;
    white-space: pre-line;
    word-break: break-all;
    line-height: 1.5;
}

#update-module .button-group {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
}

#update-module .button-group .button {
    min-height: 2.6rem;
}

/* Update module layout */
.update-header {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem 2rem;
    align-items: center;
}

.update-versions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.4rem;
}

.update-actions {
    align-items: center;
}

.update-status-banner {
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 0.75rem 0.9rem;
}

.update-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 1rem;
}

.update-meta-grid code {
    padding: 0.2rem 0.45rem;
    border-radius: 6px;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.update-auto {
    border-top: 1px solid var(--color-border);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.update-auto-grid {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 0.75rem 1rem;
    align-items: center;
}

.field-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

/* --- Update module micro-badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.8rem;
    line-height: 1;
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    color: var(--color-text-secondary);
    vertical-align: middle;
}

.badge.success {
    background: color-mix(in srgb, var(--color-success) 18%, transparent);
    border-color: color-mix(in srgb, var(--color-success) 40%, var(--color-border));
    color: var(--color-success);
}

.badge.info {
    background: color-mix(in srgb, var(--color-accent-primary) 18%, transparent);
    border-color: color-mix(in srgb, var(--color-accent-primary) 40%, var(--color-border));
    color: var(--color-accent-primary);
}

.badge.warning {
    background: color-mix(in srgb, var(--color-warning) 18%, transparent);
    border-color: color-mix(in srgb, var(--color-warning) 40%, var(--color-border));
    color: var(--color-warning);
}

.badge.danger {
    background: color-mix(in srgb, var(--color-danger) 18%, transparent);
    border-color: color-mix(in srgb, var(--color-danger) 40%, var(--color-border));
    color: var(--color-danger);
}

/* --- Callout for v3 hint --- */
.callout {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem 1rem;
    align-items: center;
    padding: 0.9rem 1rem;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
}

.callout.info {
    border-color: color-mix(in srgb, var(--color-accent-primary) 40%, var(--color-border));
    background: color-mix(in srgb, var(--color-accent-primary) 12%, var(--color-bg-alt));
}

.callout .callout-content p {
    margin: 0.25rem 0 0;
    color: var(--color-text-secondary);
}

.callout .callout-actions .button {
    min-height: 2.2rem;
}

@media (max-width: 768px) {
    .update-header {
        grid-template-columns: 1fr;
    }

    .update-meta-grid {
        grid-template-columns: 1fr;
    }

    .update-auto-grid {
        grid-template-columns: 1fr;
    }
}

.tip-inline {
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    gap: 0.4rem;
}

.tip-inline .info-inline svg {
    opacity: 0.75;
}

.form-field {
    margin-bottom: 1.25rem;
}

.form-field label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

/* Overrides (覆盖配置)：横排布局，随屏幕自适应列数 */
#overrides-module .overrides-grid {
    display: grid;
    grid-template-columns: minmax(360px, 1fr) minmax(360px, 1fr) auto;
    gap: 1rem 1.5rem;
    align-items: end;
}

@media (max-width: 992px) {
    #overrides-module .overrides-grid {
        grid-template-columns: 1fr;
    }
}

#overrides-module .overrides-actions {
    align-self: end;
}

#overrides-module .button-group {
    margin-top: 0;
}

/* 覆盖配置：行内表单对齐（标签-输入-提示） */
#overrides-module .control-item {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 0.5rem 1rem;
    align-items: center;
}

#overrides-module .control-item .control-hint {
    grid-column: 2 / 3;
    margin-top: 0.1rem;
}

#overrides-module input[type="text"] {
    width: 100%;
    max-width: none;
}

#overrides-module .overrides-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

#overrides-module .overrides-actions .button-group {
    display: inline-grid;
    grid-auto-flow: column;
    gap: 1rem;
}

.rule-card {
    background-color: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas: "toggle name" "meta meta" "actions actions";
    gap: 0.5rem 1rem;
    align-items: center;
}

.rule-card-toggle {
    grid-area: toggle;
}

.rule-card-name {
    grid-area: name;
    font-weight: 600;
    word-break: break-all;
}

.rule-card-meta {
    grid-area: meta;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    padding-top: 0.75rem;
    margin-top: 0.75rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    align-items: center;
}

.rule-card-meta .url {
    flex-basis: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rule-card-actions {
    grid-area: actions;
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.rule-card-actions .button {
    flex-grow: 1;
    padding: 0.6rem 1rem;
}

.sub-nav {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    margin: 0 1.75rem 1.5rem;
}

.sub-nav-link {
    padding: 0.75rem 1.25rem;
    margin-bottom: -1px;
    border: 1px solid transparent;
    color: var(--color-text-secondary);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.sub-nav-link.active {
    color: var(--color-accent-primary);
    border-color: var(--color-border);
    border-bottom-color: var(--color-bg-card);
    border-top-left-radius: var(--border-radius-sm);
    border-top-right-radius: var(--border-radius-sm);
}

.sub-tab-content {
    display: none;
}

.sub-tab-content.active {
    display: block;
}

.rules-card .card-header {
    border-bottom: none;
}

.rule-actions-wrapper {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.skeleton {
    opacity: 0.7;
    animation: skeleton-loading 1.5s linear infinite alternate;
}

.skeleton-row td>div {
    background-color: var(--color-bg-alt);
    border-radius: var(--border-radius-sm);
    height: 20px;
}

.skeleton-row td:first-child>div {
    width: 60%;
}

.skeleton-row td:nth-child(2)>div {
    width: 90%;
}

.skeleton-row td:nth-child(3)>div {
    width: 30%;
}

@keyframes skeleton-loading {
    from {
        background-color: var(--color-bg-alt);
    }

    to {
        background-color: color-mix(in srgb, var(--color-bg-alt) 60%, var(--color-border));
    }
}

.donut-chart-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 3rem;
}

.donut-chart {
    position: relative;
    width: 160px;
    height: 160px;
    flex-shrink: 0;
}

.donut-chart svg {
    transform: rotate(-90deg);
}

.donut-chart-center-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.donut-chart-center-text .total {
    font-size: 1.6rem;
    font-weight: 700;
}

.donut-chart-center-text .label {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.donut-legend {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    flex-basis: 220px;
    flex-grow: 1;
}

.donut-legend-item {
    display: flex;
    align-items: center;
    font-size: 1rem;
}

.legend-color-box {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

.legend-label {
    color: var(--color-text-secondary);
    flex-grow: 1;
    margin-right: 1rem;
}

.legend-value {
    font-weight: 600;
    white-space: nowrap;
}

#slowest-queries-table th:last-child,
#slowest-queries-table td:last-child {
    white-space: nowrap;
}

/* --- [新增] 名单管理样式 --- */
.list-mgmt-grid {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 1.5rem;
    min-height: 400px;
}

.list-mgmt-nav {
    border-right: 1px solid var(--color-border);
    padding-right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.list-mgmt-link {
    display: block;
    padding: 0.6rem 1rem;
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: var(--transition-fast);
    border: 1px solid transparent;
}

.list-mgmt-link:hover {
    background-color: var(--color-bg-alt);
    color: var(--color-text-primary);
}

.list-mgmt-link.active {
    background-color: color-mix(in srgb, var(--color-accent-primary) 10%, transparent);
    color: var(--color-accent-primary);
    font-weight: 600;
    border-color: var(--color-accent-primary);
}

.list-mgmt-content {
    display: flex;
    flex-direction: column;
    position: relative;
}

#list-content-textarea {
    flex-grow: 1;
    resize: vertical;
    font-family: var(--font-family-mono);
    font-size: 0.9rem;
    line-height: 1.6;
}

.list-mgmt-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
    gap: 1rem;
}

#list-content-info {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

/* --- [新增] 功能开关样式 --- */
.segmented-control {
    display: flex;
    gap: 0.5rem;
    background-color: var(--color-bg-alt);
    border-radius: var(--border-radius-sm);
    padding: 0.25rem;
    border: 1px solid var(--color-border);
}

.segmented-control .button {
    flex: 1;
    padding: 0.5rem 1rem;
    background-color: transparent;
    color: var(--color-text-secondary);
    border: none;
    box-shadow: none;
    font-weight: 600;
}

.segmented-control .button:hover:not(:disabled) {
    color: var(--color-text-primary);
    transform: none;
    box-shadow: none;
}

.segmented-control .button.active {
    background-color: var(--color-accent-primary);
    color: var(--color-accent-text) !important;
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .segmented-control .button.active {
    color: #fff !important;
}

.secondary-switches-grid {
    display: grid;
    /* 增大每格最小宽度，减少拥挤与误读 */
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem 1.25rem;
    padding-top: 1.25rem;
    margin-top: 1.25rem;
    border-top: 1px solid var(--color-border);
}

.secondary-switches-grid .control-item {
    /* 让标题在左、开关在右且顶端对齐 */
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.75rem 1rem;
    background-color: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
}

.secondary-switches-grid .control-item strong {
    /* 使标题与说明垂直排列，避免与右侧开关混淆 */
    display: block;
    flex: 1 1 auto;
    margin-right: 0.75rem;
}

.secondary-switches-grid .control-item strong .title-line {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.secondary-switches-grid .control-item .switch-desc {
    display: block;
    color: var(--color-text-secondary);
    font-weight: 400;
    font-size: 0.85rem;
    margin-top: 0.25rem;
    line-height: 1.35;
    max-width: 38ch;
}

/* 开关保持靠右并顶端对齐 */
.secondary-switches-grid .control-item>label.switch {
    margin-left: auto;
    align-self: flex-start;
}

/* 轻微悬浮强调，帮助识别每个独立项 */
.secondary-switches-grid .control-item:hover {
    box-shadow: var(--shadow-sm);
}

.info-icon {
    display: inline-flex;
    align-items: center;
}

.info-icon:hover {
    color: var(--color-accent-primary);
}

.info-icon svg {
    display: inline-block;
    vertical-align: middle;
}

/* --- [新增] 系统信息样式 --- */
.info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.8rem 1.5rem;
    align-items: center;
}

.info-item {
    display: contents;
    /* Allows label and value to be direct grid children */
}

.info-item-label {
    font-weight: 500;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.info-item-value {
    font-weight: 600;
    color: var(--color-text-primary);
    text-align: right;
    word-break: break-all;
}

.info-item-value.accent {
    color: var(--color-accent-primary);
}


[data-layout="compact"] .container {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

[data-layout="compact"] .overview-grid,
[data-layout="compact"] .control-panel-grid {
    gap: 1rem;
}

[data-layout="compact"] th,
[data-layout="compact"] td {
    padding: 0.5rem 1rem;
}

[data-layout="compact"] #log-query-table-container {
    max-height: calc(100vh - 280px);
}

@media (max-width: 1440px) {
    [data-layout="comfortable"] #log-query-tab table {
        font-size: 0.9rem;
    }

    [data-layout="comfortable"] #log-query-tab th,
    [data-layout="comfortable"] #log-query-tab td {
        padding-top: 0.55rem;
        padding-bottom: 0.55rem;
    }

    [data-layout="comfortable"] #log-query-table-container {
        max-height: calc(100vh - 320px);
    }

    [data-layout="comfortable"] #log-query-tab .card-header #log-header-actions {
        display: flex;
        flex-grow: 1;
    }

    [data-layout="comfortable"] #log-query-tab .card-header #log-search {
        flex-grow: 1;
        max-width: 450px;
        margin-left: 1rem;
    }

    #log-query-tab.search-moved-to-header #log-search-container-original {
        display: none;
    }
}

@media (min-width: 1600px) {
    [data-layout="comfortable"] .container {
        max-width: 1500px;
    }

    [data-layout="comfortable"] .overview-grid {
        grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    }

    /* 大屏采用12栅格：
     - 顶部4个mini模块：每个占3列 (4x3=12)
     - 下面3个核心模块：每个占4列 (3x4=12)  */
    .control-panel-grid {
        grid-template-columns: repeat(12, 1fr);
    }

    .control-panel-grid>.control-module--mini {
        grid-column: span 3;
    }

    #domain-stats-module,
    #system-info-module,
    #update-module {
        grid-column: span 4;
    }
}

@media (min-width: 2000px) {
    [data-layout="comfortable"] .container {
        max-width: 1900px;
    }
}

@media (max-width: 992px) {
    .page-header {
        justify-content: center;
        gap: 0.75rem;
    }

    h1 {
        flex-basis: 100%;
        text-align: center;
        margin-bottom: 0.5rem;
    }

    .header-main-actions {
        order: 1;
        flex-grow: 1;
        justify-content: center;
    }

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


/* Accordion styles removed */


/* --- [REFACTORED] Responsive & Mobile Styles --- */
@media (max-width: 1440px) {
    [data-layout="comfortable"] #log-query-tab table {
        font-size: 0.9rem;
    }

    [data-layout="comfortable"] #log-query-tab th,
    [data-layout="comfortable"] #log-query-tab td {
        padding-top: 0.55rem;
        padding-bottom: 0.55rem;
    }

    [data-layout="comfortable"] #log-query-table-container {
        max-height: calc(100vh - 320px);
    }

    [data-layout="comfortable"] #log-query-tab .card-header .header-actions {
        display: flex;
        flex-grow: 1;
    }

    [data-layout="comfortable"] #log-query-tab .card-header #log-search {
        flex-grow: 1;
        max-width: 450px;
        margin-left: 1rem;
    }

    #log-query-tab.search-moved-to-header #log-search-container-original {
        display: none;
    }
}

@media (min-width: 1600px) {
    [data-layout="comfortable"] .container {
        max-width: 1500px;
    }

    [data-layout="comfortable"] .overview-grid {
        grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    }

    .control-panel-grid {
        grid-template-columns: repeat(12, 1fr);
    }

    .control-panel-grid>.control-module--mini {
        grid-column: span 3;
    }

    #domain-stats-module,
    #system-info-module,
    #update-module {
        grid-column: span 4;
    }
}

@media (min-width: 2000px) {
    [data-layout="comfortable"] .container {
        max-width: 1900px;
    }
}

@media (max-width: 992px) {
    .page-header {
        flex-direction: column;
        justify-content: center;
        gap: 1rem;
    }

    h1 {
        text-align: center;
    }

    .header-main-actions {
        width: 100%;
        justify-content: center;
    }

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

@media (max-width: 768px) {
    html {
        font-size: 15px;
    }

    .container {
        padding: 1.5rem 1rem 4rem;
    }

    h1 {
        font-size: 1.8rem;
    }

    .card-header {
        padding: 1rem 1.25rem;
    }

    .card-body {
        padding: 1.25rem;
    }

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

    .hide-on-mobile {
        display: none !important;
    }

    .show-on-mobile {
        display: block !important;
    }

    #log-search-container-original {
        display: flex;
        gap: 0.75rem;
        align-items: center;
        margin-bottom: 1rem;
    }

    #log-search-container-original #manage-aliases-btn-mobile {
        flex-shrink: 0;
    }

    /* Unified Mobile Layout for all tables */
    .mobile-card-layout thead,
    .mobile-rule-card-layout thead {
        display: none;
    }

    .mobile-card-layout,
    .mobile-card-layout tbody,
    .mobile-rule-card-layout,
    .mobile-rule-card-layout tbody {
        display: block;
    }

    .mobile-card-layout tr,
    .mobile-rule-card-layout .rule-card {
        display: block;
        background-color: var(--color-bg-card);
        padding: 1rem;
        border-radius: var(--border-radius-md);
        margin-bottom: 0.75rem;
        border: 1px solid var(--color-border);
        box-shadow: var(--shadow-sm);
    }

    .mobile-card-layout td {
        display: block;
        border: none;
        padding: 0;
        min-width: 0;
    }

    .mobile-card-layout tr:nth-child(even) {
        background-color: var(--color-bg-card);
    }

    /* Special handling for cache stats table on mobile */
    #cache-stats-table.mobile-card-layout td {
        width: 100%;
    }


    /* The robust grid system for all mobile list items */
    .mobile-log-row {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas: "domain time" "meta meta";
        gap: 0.25rem 1rem;
        font-size: 0.9rem;
    }

    .mobile-log-row .domain {
        grid-area: domain;
        font-weight: 600;
        color: var(--color-text-primary);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        align-self: center;
        min-width: 0;
    }

    .mobile-log-row .time {
        grid-area: time;
        text-align: right;
        color: var(--color-text-secondary);
        font-size: 0.8rem;
        align-self: center;
    }

    .mobile-log-row .meta {
        grid-area: meta;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 0.5rem 1rem;
        color: var(--color-text-secondary);
        font-size: 0.85rem;
        padding-top: 0.5rem;
        margin-top: 0.5rem;
        border-top: 1px solid var(--color-border);
    }

    .mobile-log-row .meta .client {
        max-width: 15ch;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-log-row .meta .duration {
        font-weight: 500;
    }

    /* Mobile: Convert tags to colored dots */
    .mobile-log-row .response-tag,
    .mobile-log-row .rule-tag {
        width: 10px !important;
        height: 10px !important;
        min-width: 10px !important;
        min-height: 10px !important;
        max-width: 10px !important;
        max-height: 10px !important;
        padding: 0 !important;
        margin: 0 !important;
        border-radius: 50% !important;
        font-size: 0 !important;
        line-height: 0 !important;
        overflow: hidden !important;
        text-indent: -9999px !important;
        border: none !important;
        flex-shrink: 0 !important;
        position: relative !important;
        z-index: 10 !important;
        /* Increased z-index */
        display: inline-block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    .mobile-log-row .response-tag::before,
    .mobile-log-row .response-tag::after,
    .mobile-log-row .rule-tag::before,
    .mobile-log-row .rule-tag::after {
        display: none !important;
        content: none !important;
    }

    .mobile-log-row .response-tag.noerror {
        background-color: var(--color-success) !important;
    }

    .mobile-log-row .response-tag.nxdomain {
        background-color: var(--color-warning) !important;
    }

    .mobile-log-row .response-tag.servfail,
    .mobile-log-row .response-tag.refused {
        background-color: var(--color-danger) !important;
    }

    .mobile-log-row .response-tag.other {
        background-color: var(--color-text-secondary) !important;
    }

    .mobile-log-row .rule-tag {
        background-color: var(--color-accent-primary) !important;
    }

    .mobile-log-row .rule-tag::before {
        display: none !important;
    }


    /* Mobile styles for Cache Management Table */
    .cache-card-mobile {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        width: 100%;
    }

    .cache-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid var(--color-border);
        gap: 0.5rem;
    }

    .cache-card-header .cache-name {
        font-weight: 600;
        font-size: 0.95rem;
        color: var(--color-text-primary);
        flex: 1;
        min-width: 0;
    }

    .cache-card-header .button {
        flex-shrink: 0;
        font-size: 0.85rem;
        padding: 0.35rem 0.7rem !important;
    }

    /* 缓存卡片主体 - Table 布局确保对齐 */
    .cache-card-body {
        display: block !important;
        width: 100% !important;
        margin-top: 0.5rem;
    }

    /* 每一行数据 */
    .cache-stat-row {
        display: table !important;
        width: 100% !important;
        padding: 0.6rem 0 !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
        table-layout: fixed !important;
    }

    .cache-stat-row:last-child {
        border-bottom: none !important;
    }

    /* 标签（左侧） */
    .cache-stat-label {
        display: table-cell !important;
        width: 40% !important;
        color: var(--color-text-secondary) !important;
        font-size: 0.85rem !important;
        font-weight: 400 !important;
        text-align: left !important;
        vertical-align: middle !important;
        padding-right: 0.5rem !important;
    }

    /* 数值（右侧） */
    .cache-stat-value {
        display: table-cell !important;
        width: 60% !important;
        font-weight: 600 !important;
        color: var(--color-text-primary) !important;
        text-align: right !important;
        font-size: 0.9rem !important;
        vertical-align: middle !important;
        word-break: break-all !important;
    }

    .cache-stat-row .control-item-link {
        display: table-cell !important;
        width: 60% !important;
        padding: 0 !important;
        text-decoration: none !important;
        text-align: right !important;
        vertical-align: middle !important;
    }

    .cache-stat-row .control-item-link strong {
        font-size: 0.9rem !important;
        line-height: 1.4 !important;
        color: var(--color-accent-primary) !important;
    }

    /* Mobile styles for List Management */
    .list-mgmt-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        min-height: auto;
    }

    .list-mgmt-nav {
        border-right: none;
        padding-right: 0;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: center;
        border-bottom: 1px solid var(--color-border);
        padding-bottom: 1rem;
    }

    .list-mgmt-link {
        flex-grow: 1;
        text-align: center;
        border: 1px solid var(--color-border);
        background-color: var(--color-bg-card);
    }

    .list-mgmt-link.active {
        background-color: var(--color-accent-primary);
        color: var(--color-accent-text);
        border-color: var(--color-accent-primary);
    }

    [data-theme="dark"] .list-mgmt-link.active {
        color: #fff;
    }

    #list-content-textarea {
        min-height: 300px;
    }

    .list-mgmt-footer {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    #list-content-info {
        text-align: center;
    }

    #list-save-btn {
        width: 100%;
    }

    /* Other mobile adjustments */
    #log-query-table-container,
    .rules-card .sub-tab-content {
        padding: 0.75rem;
        background-color: var(--color-bg-alt);
        border-radius: var(--border-radius-md);
    }

    .rules-card .sub-nav {
        margin: 0 1.25rem 1.5rem;
    }

    .rules-card .card-body {
        padding: 0;
    }

    #adguard-table-container,
    #diversion-table-container {
        max-height: calc(100vh - 400px);
        padding: 0;
        background: none;
    }

    .control-panel-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .control-module {
        padding: 1.25rem;
    }

    .control-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .control-item>div,
    .control-item>form,
    .control-item>button,
    .control-item>select {
        margin-left: 0;
        width: 100%;
    }

    .button-group,
    #capacity-form {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .auto-refresh-form {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 1rem;
    }

    #manual-alias-form {
        grid-template-columns: 1fr;
    }

    .alias-item {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 576px) {
    .donut-chart-wrapper {
        flex-direction: column;
        gap: 1.5rem;
    }

    .donut-legend {
        width: 100%;
        max-width: 320px;
    }

    .info-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .info-item-value {
        text-align: left;
        margin-left: 1rem;
        margin-bottom: 0.5rem;
    }

    .alias-item {
        text-align: center;
    }

    .alias-item input {
        text-align: center;
    }

    .rule-actions-wrapper {
        justify-content: center;
    }
}

[data-theme="sakura"] {
    --color-bg: #191724;
    --color-bg-card: rgba(31, 29, 46, 0.7);
    --color-bg-alt: rgba(31, 29, 46, 0.9);
    --color-text-primary: #e0def4;
    --color-text-secondary: #908caa;
    --color-border: #eb6f92;
    --color-accent-primary: #eb6f92;
    --color-accent-primary-hover: #f4abc4;
    --color-accent-text: #191724;
    --glow-color: rgba(235, 111, 146, 0.25);
    --glow-border-color: #f4abc4;
    --color-success: #9ccfd8;
    --color-danger: #eb6f92;
    --color-warning: #f6c177;
}

@keyframes bg-pan {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

[data-theme="sakura"] body {
    background: linear-gradient(170deg, #191724 0%, #21202e 50%, #393552 100%);
    background-size: 200% 200%;
    animation: bg-pan 30s ease infinite;
    background-attachment: fixed;
}

[data-theme="sakura"] .card,
[data-theme="sakura"] .main-nav,
[data-theme="sakura"] dialog {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-color: rgba(235, 111, 146, 0.3);
    background-color: var(--color-bg-card);
}

[data-theme="sakura"] .card {
    box-shadow: var(--shadow-md), inset 0 0 0 1px rgba(235, 111, 146, 0.2);
}

[data-theme="sakura"] .stat-card {
    background: rgba(31, 29, 46, 0.7);
    border: 1px solid rgba(235, 111, 146, 0.5);
    color: #e0def4;
}

[data-theme="sakura"] .stat-card h3 {
    color: #e0def4;
}

[data-theme="sakura"] h1,
[data-theme="sakura"] .stat-card .value {
    text-shadow: 0 0 10px rgba(235, 111, 146, 0.8), 0 0 4px rgba(255, 255, 255, 0.5);
}

[data-theme="sakura"] .main-nav-slider {
    background: rgba(235, 111, 146, 0.8);
}

@keyframes sakura-fall {
    0% {
        transform: translateY(110vh) translateX(-10vw) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(-10vh) translateX(10vw) rotate(720deg);
        opacity: 0;
    }
}

[data-theme="sakura"] main::before,
[data-theme="sakura"] main::after {
    content: '🌸';
    position: fixed;
    bottom: -50px;
    color: #f4abc4;
    font-size: 1rem;
    z-index: 0;
    pointer-events: none;
    animation: sakura-fall 15s linear infinite;
    animation-direction: reverse;
}

[data-theme="sakura"] main::before {
    left: 10%;
    animation-delay: 0s;
}

[data-theme="sakura"] main::after {
    left: 30%;
    animation-delay: -5s;
    content: '💮';
    font-size: 1.5rem;
}

[data-theme="evergreen"] {
    --color-bg: #1a2e26;
    --color-bg-card: rgba(20, 38, 31, 0.7);
    --color-bg-alt: rgba(14, 27, 22, 0.8);
    --color-text-primary: #e2e8f0;
    --color-text-secondary: #94a3b8;
    --color-border: #4ade80;
    --color-accent-primary: #4ade80;
    --color-accent-primary-hover: #86efac;
    --color-accent-text: #064e3b;
    --glow-color: rgba(74, 222, 128, 0.15);
    --glow-border-color: #86efac;
    --color-success: #4ade80;
    --color-danger: #f87171;
    --color-warning: #fbbf24;
}

[data-theme="evergreen"] body {
    background: #1a2e26 url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"%3E%3Cg fill-rule="evenodd"%3E%3Cg fill="%232c5d4c" fill-opacity="0.2"%3E%3Cpath opacity=".5" d="M96 95h4v1h-4v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4H0v-1h4v-9H0v-1h4v-9H0v-1h4v-9H0v-1h4v-9H0v-1h4v-9H0v-1h4v-9H0v-1h4v-9H0v-1h4v-9H0v-1h4V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v4h-1v-4h-9v4h-1v-4h-h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4H1v-4H0v-1h1v-9H0v-1h1v-9H0v-1h1v-9H0v-1h1v-9H0v-1h1v-9H0v-1h1v-9H0v-1h1v-9H0v-1h1V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4h9V0h1v4z"/%3E%3Cpath d="M6 6h2v2H6V6zm2-2h2v2H8V4zM4 2h2v2H4V2zM2 4h2v2H2V4z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
}

[data-theme="evergreen"] .card,
[data-theme="evergreen"] dialog {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.2);
}

[data-theme="evergreen"] .stat-card {
    background: var(--color-bg-card);
    color: var(--color-text-primary);
    border: 1px solid rgba(74, 222, 128, 0.4);
}

[data-theme="evergreen"] .stat-card h3 {
    color: var(--color-text-primary);
}

[data-theme="starlight"] {
    --color-bg: #000;
    --color-bg-card: rgba(10, 10, 25, 0.6);
    --color-bg-alt: rgba(10, 10, 25, 0.8);
    --color-text-primary: #d1d5db;
    --color-text-secondary: #6b7280;
    --color-border: #3b82f6;
    --color-accent-primary: #3b82f6;
    --color-accent-primary-hover: #60a5fa;
    --color-accent-text: #fff;
    --glow-color: rgba(59, 130, 246, 0.2);
    --glow-border-color: #60a5fa;
    --color-success: #34d399;
    --color-danger: #f87171;
    --color-warning: #f59e0b;
}

[data-theme="starlight"] body {
    background: #000 url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 800"%3E%3Ccircle fill="%23fff" fill-opacity="0.8" cx="200" cy="200" r="1"/%3E%3Ccircle fill="%23fff" fill-opacity="0.8" cx="600" cy="600" r="1.5"/%3E%3Ccircle fill="%23fff" fill-opacity="0.8" cx="400" cy="500" r="0.5"/%3E%3Ccircle fill="%23fff" fill-opacity="0.8" cx="100" cy="50" r="0.5"/%3E%3Ccircle fill="%23fff" fill-opacity="0.8" cx="700" cy="100" r="1"/%3E%3Ccircle fill="%23fff" fill-opacity="0.8" cx="50" cy="700" r="0.5"/%3E%3Ccircle fill="%23fff" fill-opacity="0.8" cx="300" cy="50" r="1"/%3E%3Ccircle fill="%23fff" fill-opacity="0.8" cx="550" cy="300" r="2"/%3E%3C/svg%3E');
    animation: starlight-drift 40s infinite linear;
}

@keyframes starlight-drift {
    from {
        background-position: 0 0;
    }

    to {
        background-position: -800px 400px;
    }
}

@keyframes twinkle-star {

    0%,
    100% {
        opacity: 0.1;
    }

    50% {
        opacity: 0.8;
    }
}

[data-theme="starlight"] main::after {
    content: '✧';
    position: fixed;
    color: #fff;
    z-index: 0;
    pointer-events: none;
    animation: twinkle-star 5s infinite;
    top: 20%;
    left: 10%;
    font-size: 0.5rem;
}

[data-theme="starlight"] main::before {
    content: '✦';
    position: fixed;
    color: #fff;
    z-index: 0;
    pointer-events: none;
    animation: twinkle-star 7s infinite;
    top: 60%;
    right: 15%;
    animation-delay: -2s;
    font-size: 0.8rem;
}

[data-theme="starlight"] .card,
[data-theme="starlight"] .main-nav,
[data-theme="starlight"] dialog {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

[data-theme="starlight"] .stat-card {
    background: var(--color-bg-card);
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

[data-theme="starlight"] .stat-card h3,
[data-theme="starlight"] h1 {
    color: #fff;
}

[data-theme="starlight"] .stat-card .value {
    text-shadow: 0 0 5px var(--color-accent-primary);
}

[data-theme="dusk"] {
    --color-bg: #232526;
    --color-bg-card: rgba(20, 20, 20, 0.5);
    --color-bg-alt: rgba(10, 10, 10, 0.7);
    --color-text-primary: #F2F2F2;
    --color-text-secondary: #A9A9A9;
    --color-border: #FF8C00;
    --color-accent-primary: #FF8C00;
    --color-accent-primary-hover: #FFA500;
    --color-accent-text: #000;
    --glow-color: rgba(255, 140, 0, 0.2);
    --glow-border-color: #FFA500;
    --color-success: #98FB98;
    --color-danger: #F08080;
    --color-warning: #FFD700;
}

@keyframes dusk-gradient {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

[data-theme="dusk"] body {
    background: linear-gradient(-45deg, #434343, #232526, #2c3e50, #fd746c);
    background-size: 400% 400%;
    animation: dusk-gradient 20s ease infinite;
    background-attachment: fixed;
}

[data-theme="dusk"] .card,
[data-theme="dusk"] .main-nav,
[data-theme="dusk"] dialog {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-color: rgba(255, 140, 0, 0.3);
}

[data-theme="dusk"] .stat-card {
    background: var(--color-bg-card);
    color: var(--color-text-primary);
}

[data-theme="dusk"] .stat-card h3 {
    color: var(--color-text-primary);
}

[data-theme="dusk"] .main-nav a.active {
    color: var(--color-accent-text) !important;
}

[data-theme="terra"] {
    --color-bg: #4a2a22;
    --color-bg-card: rgba(45, 30, 26, 0.6);
    --color-bg-alt: rgba(30, 20, 17, 0.7);
    --color-text-primary: #f2e9e4;
    --color-text-secondary: #a99985;
    --color-border: #ff8c42;
    --color-accent-primary: #ff8c42;
    --color-accent-primary-hover: #ffac70;
    --color-accent-text: #2d1e1a;
    --glow-color: rgba(255, 140, 66, 0.2);
    --glow-border-color: #ffac70;
    --color-success: #a7c957;
    --color-danger: #e56b6f;
    --color-warning: #ffb703;
}

[data-theme="terra"] body {
    background: #4a2a22 url('data:image/svg+xml,%3Csvg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cg fill="%236b4235" fill-opacity="0.2"%3E%3Cpath d="M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
}

[data-theme="terra"] .card,
[data-theme="terra"] .main-nav,
[data-theme="terra"] dialog {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: inset 0 0 0 1px rgba(255, 140, 66, 0.2);
    border-color: rgba(255, 140, 66, 0.3);
}

[data-theme="terra"] .stat-card {
    background: var(--color-bg-card);
    color: var(--color-text-primary);
    border: 1px solid rgba(255, 140, 66, 0.4);
}

[data-theme="terra"] .stat-card h3 {
    color: var(--color-text-primary);
}

[data-theme="terra"] .main-nav a.active {
    color: var(--color-accent-text) !important;
}

.control-module--mini {
    padding: 1rem 1.25rem;
    gap: 0.6rem;
}

.control-module--mini .control-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.control-module--mini .button-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.6rem;
}

.control-module--mini .button-group .button {
    min-height: 2.2rem;
}

.control-module--mini form {
    display: flex;
    gap: 0.6rem;
    width: 100%;
}

.control-module--mini form input {
    flex: 1;
    min-width: 0;
}

#requery-module {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.requery-header {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem 2rem;
    align-items: center;
}

.requery-status-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

.requery-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: flex-end;
}

.requery-primary-btn {
    min-width: 180px;
}

.requery-progress-row {
    padding: 0.25rem 0;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-bg-alt);
    font-weight: 600;
    font-size: 0.85rem;
}

.requery-scheduler {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    border-top: 1px solid var(--color-border);
    padding-top: 1rem;
}

.requery-scheduler-grid {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 0.75rem 1rem;
    align-items: center;
}

.requery-scheduler-grid .field-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.requery-important {
    border-top: 1px solid var(--color-border);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.requery-important-actions {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

@media (max-width: 768px) {
    .requery-header {
        grid-template-columns: 1fr;
    }

    .requery-actions {
        justify-content: stretch;
    }

    .requery-primary-btn {
        flex: 1;
    }

    .requery-scheduler-grid {
        grid-template-columns: 1fr;
    }
}

/* === 移动端适配代码 (安全版 - 仅针对覆盖配置模块) === */
@media (max-width: 768px) {

    /* 1. 强制栅格/Flex容器变为竖向排列 */
    .overrides-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
    }

    /* 2. 限定只影响 overrides-grid 内部的 control-item */
    .overrides-grid .control-item {
        width: 100% !important;
        min-width: 100% !important;
        margin-right: 0 !important;
        /* 恢复默认的 flex 布局，防止被全局样式覆盖 */
        display: flex !important;
        flex-direction: column !important;
        /* 让 label 和 input 上下排列 */
        align-items: flex-start !important;
    }

    /* 3. 限定只影响 overrides-grid 内部的 input */
    .overrides-grid .control-item input {
        width: 100% !important;
        margin-left: 0 !important;
        /* 清除可能存在的左边距 */
    }

    /* 4. 限定只影响 overrides-grid 内部的提示文字 */
    .overrides-grid .control-hint {
        white-space: normal !important;
        display: block !important;
        width: 100% !important;
        margin-top: 5px !important;
    }

    /* 5. 调整按钮组 */
    .overrides-actions {
        width: 100% !important;
        margin-top: 10px !important;
        display: flex;
        justify-content: flex-end;
    }
}

/* Feature Switches Grid (Tile Layout) */
.secondary-switches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}

.secondary-switches-grid .control-item {
    background-color: var(--color-bg-alt);
    padding: 0.85rem 1rem;
    border-radius: var(--border-radius-md);
    margin-bottom: 0 !important;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.secondary-switches-grid .control-item:hover {
    border-color: var(--color-accent-primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-2px);
}

.secondary-switches-grid .control-item strong {
    font-size: 0.95rem;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    h1 {
        font-size: 1.6rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    .overview-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

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

    .control-module {
        padding: 1rem;
    }

    /* System - Base Config Optimization (Appearance Module) */
    #appearance-module .control-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    #appearance-module .control-item select {
        margin-left: 0;
        width: 100%;
        max-width: none;
    }

    #appearance-module .color-palette {
        justify-content: flex-start;
        /* Ensure colors start from left */
    }

    /* Log Capacity Module */
    #capacity-form {
        grid-template-columns: 1fr;
    }

    #capacity-form button {
        width: 100%;
    }

    /* Auto Refresh Module */
    #auto-refresh-module .control-item {
        flex-direction: row;
        /* Keep Refresh Toggle side-by-side if possible */
        flex-wrap: wrap;
    }

    #auto-refresh-form {
        margin-left: auto !important;
        /* Keep Interval right aligned */
    }

    /* Feature Switches Compact Grid for Mobile */
    .secondary-switches-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.6rem;
    }

    .secondary-switches-grid .control-item {
        padding: 0.75rem;
        flex-direction: column;
        align-items: flex-start;
        justify-content: space-between;
        min-height: 80px;
    }

    .secondary-switches-grid .control-item strong {
        font-size: 0.85rem;
        line-height: 1.3;
    }

    .secondary-switches-grid .control-item .switch {
        align-self: flex-end;
        margin-left: 0;
        transform: scale(0.9);
    }

    /* Text Wrapping */
    p,
    h1,
    h2,
    h3 {
        overflow-wrap: break-word;
    }
}