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

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-hover: #f0f1f3;
    --bg-active: #e7f1ff;
    --text-primary: #1a1a2e;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --sidebar-width: 300px;
    --toolbar-height: 56px;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-hover: #334155;
    --bg-active: #1e3a5f;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --accent-color: #60a5fa;
    --accent-hover: #3b82f6;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s, color 0.3s;
}

/* 顶部导航栏 */
.top-nav {
    height: 48px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
}

.nav-brand {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: opacity 0.2s;
}

.nav-brand:hover {
    opacity: 0.8;
}

.nav-title {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.app {
    display: flex;
    height: calc(100% - 48px);
}

/* 侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: background 0.3s, transform 0.3s;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-color), #8b5cf6);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.brand-title {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-color), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.icon-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* 搜索框 */
.search-box {
    padding: 12px 20px;
    position: relative;
}

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

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 40px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 0.9rem;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s;
}

.search-box input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

/* 分组 */
.groups-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.group {
    margin-bottom: 4px;
}

.group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    cursor: pointer;
    font-weight: 500;
    border-radius: 8px;
    user-select: none;
    transition: background 0.2s;
}

.group-header:hover {
    background: var(--bg-hover);
}

.group-name {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.group-toggle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.group.collapsed .group-toggle {
    transform: rotate(-90deg);
}

.group.collapsed .tools-list {
    display: none;
}

.tools-list {
    padding: 4px 0 4px 8px;
}

/* 工具项 */
.tool-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin: 2px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.tool-item:hover {
    background: var(--bg-hover);
}

.tool-item.active {
    background: var(--bg-active);
}

.tool-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.tool-icon {
    width: 22px;
    height: 22px;
    object-fit: contain;
    border-radius: 4px;
}

.tool-name {
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.tool-item:hover .tool-actions {
    opacity: 1;
}

.tool-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 4px 6px;
    border-radius: 4px;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.tool-actions button:hover:not(:disabled) {
    background: var(--bg-secondary);
    color: var(--accent-color);
}

.tool-actions button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* 侧边栏底部 */
.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.sidebar-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8rem;
    transition: color 0.2s;
}

.sidebar-footer a:hover {
    color: var(--accent-color);
}

/* 移动端菜单按钮 */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

/* 右侧内容区 */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.iframe-toolbar {
    height: var(--toolbar-height);
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-primary);
}

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

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

.tool-name {
    font-weight: 500;
    font-size: 1rem;
    color: var(--text-primary);
}

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

.toolbar-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.toolbar-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

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

/* iframe 区域 */
.iframe-wrapper {
    flex: 1;
    position: relative;
    background: var(--bg-primary);
}

#contentIframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* 欢迎页 */
.welcome-page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 24px;
}

.welcome-page h2 {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome-page p {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.ad-container {
    max-width: 728px;
    overflow: hidden;
}

/* iframe 加载失败遮罩 */
.iframe-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.overlay-content {
    text-align: center;
    padding: 40px;
    background: var(--bg-secondary);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
}

.overlay-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.overlay-content h3 {
    font-size: 1.2rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.overlay-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* 滚动条样式 */
.groups-container::-webkit-scrollbar {
    width: 6px;
}

.groups-container::-webkit-scrollbar-track {
    background: transparent;
}

.groups-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.groups-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* 自定义Tooltip */
.custom-tooltip {
    position: fixed;
    display: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    max-width: 280px;
    word-wrap: break-word;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    z-index: 1000;
    pointer-events: none;
}

/* 响应式 */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-md);
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .iframe-toolbar {
        padding-left: 60px;
    }

    .ad-container {
        width: 100%;
        padding: 0 16px;
    }

    .ad-container ins {
        width: 100% !important;
        max-width: 728px;
    }
}
