/* ============================================================
   DevToolbox - 开发者工具集 样式表
   ============================================================ */

/* --- CSS 变量 (亮色主题) --- */
:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: #334155;
    --bg-sidebar-active: #4F46E5;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-sidebar: #cbd5e1;
    --text-sidebar-title: #94a3b8;
    --border-color: #e2e8f0;
    --accent: #4F46E5;
    --accent-hover: #4338CA;
    --accent-light: #EEF2FF;
    --danger: #EF4444;
    --danger-light: #FEF2F2;
    --success: #10B981;
    --success-light: #ECFDF5;
    --warning: #F59E0B;
    --warning-light: #FFFBEB;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --transition: 0.2s ease;
    --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
}

/* --- 暗色主题 --- */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-sidebar: #0f172a;
    --bg-sidebar-hover: #1e293b;
    --bg-sidebar-active: #4F46E5;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-sidebar: #cbd5e1;
    --text-sidebar-title: #64748b;
    --border-color: #334155;
    --accent-light: #1e1b4b;
    --danger-light: #1c1917;
    --success-light: #022c22;
    --warning-light: #1c1917;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- 侧边栏 --- */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s ease, background var(--transition);
}

.sidebar-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.5px;
}

.logo-sub {
    font-size: 0.75rem;
    color: var(--text-sidebar-title);
    margin-top: 2px;
}

/* 搜索框 */
.sidebar-search {
    padding: 12px 16px;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.06);
    color: #fff;
    font-size: 0.85rem;
    outline: none;
    transition: all var(--transition);
}
.sidebar-search input::placeholder { color: var(--text-sidebar-title); }
.sidebar-search input:focus {
    border-color: var(--accent);
    background: rgba(255,255,255,0.1);
}

/* 导航 */
.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}

.nav-group {
    margin-bottom: 4px;
}

.nav-group-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-sidebar-title);
    padding: 12px 20px 6px;
}

.nav-item {
    display: block;
    padding: 8px 20px;
    font-size: 0.875rem;
    color: var(--text-sidebar);
    transition: all var(--transition);
    border-left: 3px solid transparent;
    cursor: pointer;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: #fff;
    text-decoration: none;
}

.nav-item.active {
    background: rgba(79, 70, 229, 0.15);
    color: #fff;
    border-left-color: var(--accent);
    font-weight: 500;
}

/* 侧边栏底部 */
.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.btn-theme {
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.btn-theme:hover { background: rgba(255,255,255,0.2); }

.version {
    font-size: 0.75rem;
    color: var(--text-sidebar-title);
}

/* --- 移动端菜单按钮 --- */
.menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: var(--accent);
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

/* --- 主内容区 --- */
.main-content {
    flex: 1;
    padding: 32px 40px;
    max-width: 1000px;
    overflow-y: auto;
}

/* --- 工具区域 --- */
.tool-section {
    display: none;
    animation: fadeSlideIn 0.3s ease;
}

.tool-section.active {
    display: block;
}

@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.tool-header {
    margin-bottom: 24px;
}

.tool-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.tool-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

.tool-body {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

/* --- 表单元素 --- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group { flex: 1; }

.flex-1 { flex: 1; }

textarea, input[type="text"], input[type="number"], input[type="datetime-local"], select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-mono);
    outline: none;
    transition: all var(--transition);
    resize: vertical;
}

textarea { line-height: 1.5; min-height: 100px; }

input[type="text"]:focus, input[type="number"]:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

select {
    font-family: inherit;
    cursor: pointer;
}

input[readonly], textarea[readonly] {
    background: var(--bg-tertiary);
    cursor: default;
}

/* --- 按钮 --- */
.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
    font-family: inherit;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border-color: var(--border-color);
}
.btn-outline:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

/* --- 状态徽章 --- */
.status-badge {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
}

.status-badge.success { background: var(--success-light); color: var(--success); }
.status-badge.error { background: var(--danger-light); color: var(--danger); }
.status-badge.info { background: var(--accent-light); color: var(--accent); }

/* --- 输出框 --- */
.output-box {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 500px;
    overflow-y: auto;
    color: var(--text-primary);
}

.output-box .placeholder,
.placeholder {
    color: var(--text-secondary);
    font-style: italic;
    font-family: inherit;
}

/* --- 输入行 --- */
.input-row {
    display: flex;
    gap: 8px;
}

.input-row input[type="text"],
.input-row input[type="number"],
.input-row input[type="datetime-local"] {
    flex: 1;
}

.input-with-flags {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.input-with-flags:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.input-with-flags input[type="text"] {
    border: none;
    background: transparent;
    padding: 10px 8px;
    box-shadow: none;
}

.input-with-flags input[type="text"]:focus {
    box-shadow: none;
}

.input-with-flags .flags {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 600;
}

.flags-input {
    width: 60px !important;
    flex: none !important;
}

/* --- 信息栏 --- */
.info-bar {
    background: var(--accent-light);
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.info-bar strong {
    color: var(--accent);
    font-family: var(--font-mono);
}

/* --- 分隔线 --- */
hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 20px 0;
}

/* --- 复选框标签 --- */
.checkbox-label {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem !important;
    cursor: pointer;
    color: var(--text-secondary) !important;
    user-select: none;
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.checkbox-label:has(input:checked) {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent) !important;
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--accent);
}

.checkbox-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* --- 隐藏辅助类 --- */
.hidden { display: none !important; }

/* --- 数量选择 --- */
select {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
}

/* --- 颜色选择器 --- */
.color-picker-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.color-swatch {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
    transition: all var(--transition);
}

input[type="color"] {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
    background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border-radius: var(--radius-sm); border: 1px solid var(--border-color); }

/* --- 分栏布局 --- */
.split-pane {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.split-pane textarea { min-height: 350px; }

.diff-pane {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* --- Markdown 预览 --- */
.markdown-body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    white-space: normal !important;
}

.markdown-body h1 { font-size: 1.5rem; margin: 16px 0 8px; border-bottom: 1px solid var(--border-color); padding-bottom: 6px; }
.markdown-body h2 { font-size: 1.25rem; margin: 14px 0 6px; }
.markdown-body h3 { font-size: 1.1rem; margin: 12px 0 4px; }
.markdown-body p { margin: 6px 0; }
.markdown-body code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.85em;
}
.markdown-body pre {
    background: var(--bg-sidebar);
    color: #e2e8f0;
    padding: 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}
.markdown-body pre code {
    background: none;
    padding: 0;
}
.markdown-body blockquote {
    border-left: 3px solid var(--accent);
    margin: 8px 0;
    padding: 4px 12px;
    color: var(--text-secondary);
}
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin: 6px 0; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.markdown-body th, .markdown-body td {
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    text-align: left;
}
.markdown-body th { background: var(--bg-tertiary); font-weight: 600; }
.markdown-body a { color: var(--accent); }
.markdown-body img { max-width: 100%; }

/* --- Diff 输出 --- */
.diff-output .diff-added {
    background: var(--success-light);
    color: var(--success);
}
.diff-output .diff-removed {
    background: var(--danger-light);
    color: var(--danger);
}
.diff-output .diff-unchanged {
    color: var(--text-secondary);
}
.diff-output .diff-line {
    padding: 2px 8px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    white-space: pre-wrap;
}

/* --- 统计卡片 --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
    font-family: var(--font-mono);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* --- 密码列表 --- */
.password-list {
    font-family: var(--font-mono) !important;
    white-space: pre !important;
}

.password-list .pwd-item {
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.password-list .pwd-item:last-child { border-bottom: none; }

/* --- 强度条 --- */
.strength-bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.strength-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease, background 0.3s ease;
}

/* --- 哈希输出 --- */
.hash-output-group {
    display: flex;
    gap: 8px;
}

.hash-output-group input {
    flex: 1;
}

/* --- 二维码结果 --- */
.qr-result {
    text-align: center;
    padding: 20px;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-result canvas {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1e293b;
    color: #fff;
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 0.875rem;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    box-shadow: var(--shadow-lg);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

[data-theme="dark"] .toast {
    background: #f1f5f9;
    color: #0f172a;
}

/* --- 替换组 --- */
.replace-group {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

/* --- 滚动条 --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

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

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

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

    .main-content {
        padding: 60px 16px 24px;
    }

    .split-pane,
    .diff-pane {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-row {
        flex-direction: column;
    }

    .info-bar {
        flex-direction: column;
        gap: 8px;
    }

    .btn-row {
        flex-direction: column;
    }

    .btn-row .btn {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .tool-body {
        padding: 16px;
    }

    .tool-header h2 {
        font-size: 1.35rem;
    }
}

/* --- 侧边栏遮罩 --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

@media (max-width: 768px) {
    .sidebar-overlay.show {
        display: block;
    }
}
