/* ===== CSS 变量与主题 ===== */
:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 8px;
    --header-height: 60px;
    --sidebar-width: 260px;
}

[data-theme="dark"] {
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
}

/* ===== 全局重置 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

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

/* ===== 布局结构 ===== */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== 顶部导航栏 ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 100;
    transition: background-color 0.3s, border-color 0.3s;
}

.header-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-logo svg {
    width: 28px;
    height: 28px;
    color: var(--primary-color);
}

.header-search {
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
}

.search-input {
    width: 100%;
    padding: 8px 16px 8px 3rem !important;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-wrapper {
    position: relative;
}

.search-wrapper::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    pointer-events: none;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* 输入框获得焦点时图标变蓝 */
.search-wrapper:focus-within::before {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%233b82f6'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* ===== 搜索结果下拉面板 ===== */
.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    z-index: 200;
    max-height: 320px;
    overflow-y: auto;
}

.search-results-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text-primary);
    transition: background 0.15s;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-size: 0.9rem;
    text-decoration: none;
}

.search-result-item:hover,
.search-result-item.selected {
    background: var(--bg-body);
}

.search-result-item svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

.search-result-item .highlight {
    color: var(--primary-color);
    font-weight: 500;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

/* ===== 主题切换按钮 ===== */
.theme-toggle {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-body);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.theme-toggle:hover {
    color: var(--primary-color);
}

/* ===== 主体内容区域 ===== */
.main {
    margin-top: var(--header-height);
    display: flex;
    min-height: calc(100vh - var(--header-height));
}

/* ===== 侧边栏 ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 20px 0;
    overflow-y: auto;
    position: fixed;
    left: 0;
    top: var(--header-height);
    bottom: 0;
    transition: background-color 0.3s, border-color 0.3s;
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-section-title {
    padding: 8px 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.sidebar-menu {
    list-style: none;
}

.sidebar-item {
    margin: 2px 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.sidebar-link:hover,
.sidebar-link.active {
    background: var(--bg-body);
    color: var(--primary-color);
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ===== 首页大尺寸赞助卡片 ===== */
.sponsor-card {
    text-align: center;
}

.sponsor-large-grid {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 40px;
    margin-top: 24px;
    flex-wrap: nowrap;
}

@media (max-width: 768px) {
    .sponsor-large-grid {
        flex-wrap: wrap;
        gap: 20px;
    }
}

.sponsor-large-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.sponsor-large-item img {
    width: 100%;
    max-width: 300px;
    aspect-ratio: 1;
    background: #fff;
    padding: 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.sponsor-large-item span {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* ===== 内容区域 ===== */
.content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 30px;
    max-width: 1400px;
}

/* ===== 卡片样式 ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
    transition: background-color 0.3s;
}

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

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.card-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ===== 按钮样式 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

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

.btn-secondary:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ===== 表单元素 ===== */
textarea,
input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

textarea:focus,
input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
}

textarea {
    resize: vertical;
    min-height: 200px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* ===== 代码块样式 ===== */
.code-block {
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
}

.code-block pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ===== JSON 语法高亮 ===== */
.json-key { color: #0550ae; }
.json-string { color: #0a3069; }
.json-number { color: #0550ae; }
.json-boolean { color: #8250df; }
.json-null { color: #6e7781; }

[data-theme="dark"] .json-key { color: #79c0ff; }
[data-theme="dark"] .json-string { color: #a5d6ff; }
[data-theme="dark"] .json-number { color: #79c0ff; }
[data-theme="dark"] .json-boolean { color: #d2a8ff; }
[data-theme="dark"] .json-null { color: #8b949e; }

/* ===== 工具页面布局 ===== */
.tool-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.tool-full {
    grid-template-columns: 1fr;
}

.tool-input-panel,
.tool-output-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
    font-size: 0.875rem;
    font-weight: 500;
}

.panel-content {
    border: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
}

.panel-textarea {
    width: 100%;
    min-height: 300px;
    border: none;
    border-radius: 0;
    resize: vertical;
}

.panel-output {
    min-height: 300px;
    max-height: 500px;
    overflow: auto;
    margin: 0;
}

.panel-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ===== 状态提示 ===== */
.status-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 12px;
    background: var(--bg-body);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-error {
    color: #ef4444;
}

.status-success {
    color: #22c55e;
}

/* ===== 工具网格（首页） ===== */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.tool-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.tool-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.tool-card-icon svg {
    width: 24px;
    height: 24px;
    color: var(--primary-color);
}

.tool-card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.tool-card-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
        z-index: 99;
    }

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

    .content {
        margin-left: 0;
        padding: 16px;
    }

    .tool-container {
        grid-template-columns: 1fr;
    }

    .header-search {
        display: none;
    }

    .mobile-menu-btn {
        display: flex;
    }
}

.mobile-menu-btn {
    display: none;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-primary);
}

@media (min-width: 769px) {
    .mobile-menu-btn {
        display: none;
    }
}

/* ===== 遮罩层（移动端） ===== */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 98;
}

.overlay.show {
    display: block;
}

/* ===== 隐藏滚动条但保留功能 ===== */
.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* ===== 复制提示 ===== */
.copy-toast {
    position: fixed;
    top: 80px;
    right: 20px;
    background: var(--text-primary);
    color: var(--bg-card);
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s;
    pointer-events: none;
    z-index: 1000;
}

.copy-toast.show {
    opacity: 1;
    transform: translateY(0);
}
