/* ========================================
   TextCutter - 在线文本切割工具
   混合模式 | 纯前端 + PWA
   ======================================== */

/* ---------- CSS 变量 (主题) ---------- */
:root {
    --bg-primary: #f4f6fb;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-header: rgba(255, 255, 255, 0.85);
    --text-primary: #1e1e2f;
    --text-secondary: #4a4a6a;
    --text-muted: #8888a0;
    --border-color: #e2e5f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: #eef2ff;
    --gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --max-width: 1100px;
    --scrollbar-track: #f0f0f5;
    --scrollbar-thumb: #c0c4d8;
}

/* 深色主题 */
[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #1e1e32;
    --bg-header: rgba(15, 15, 26, 0.9);
    --text-primary: #e8e8f0;
    --text-secondary: #b0b0c8;
    --text-muted: #6a6a8a;
    --border-color: #2a2a44;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
    --accent-light: #1e1e3a;
    --scrollbar-track: #1a1a2e;
    --scrollbar-thumb: #3a3a5a;
}

/* ---------- 重置 & 基础 ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
    min-height: 100vh;
    padding-top: 70px; /* header 高度 */
}

/* 自定义滚动条 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}

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

img, svg { max-width: 100%; display: block; }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}
.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: var(--gradient);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}
.btn-primary:hover {
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
}
.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; border-radius: var(--radius); }
.btn-block { width: 100%; }

/* ---------- 头部 ---------- */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 100;
    background: var(--bg-header);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition), box-shadow var(--transition);
}
.app-header.scrolled {
    box-shadow: var(--shadow-md);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 70px;
}
.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.logo i { font-size: 1.6rem; -webkit-text-fill-color: var(--accent); }

.main-nav {
    display: flex;
    gap: 6px;
}
.nav-link {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}
.nav-link:hover, .nav-link.active {
    background: var(--accent-light);
    color: var(--accent);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
    font-size: 1.1rem;
}
.theme-toggle:hover {
    background: var(--accent-light);
    color: var(--accent);
}

/* 汉堡菜单 */
.mobile-menu-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    gap: 5px;
    padding: 8px;
}
.mobile-menu-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all var(--transition);
}

/* ---------- 卡片区 ---------- */
.section-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
    transition: all var(--transition);
    overflow: hidden;
}
.section-card:hover {
    box-shadow: var(--shadow-md);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 12px;
}
.card-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
}
.card-header h2 i { color: var(--accent); }
.card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.card-body {
    padding: 24px;
}

/* ---------- 输入文本域 ---------- */
.code-textarea {
    width: 100%;
    min-height: 200px;
    padding: 16px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.7;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: vertical;
    transition: border var(--transition), box-shadow var(--transition);
    outline: none;
}
.code-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.input-stats {
    display: flex;
    gap: 20px;
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ---------- 选项区域 ---------- */
.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.option-group-wide {
    grid-column: 1 / -1;
}
.option-group label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}
.option-group label i { margin-right: 6px; color: var(--accent); }
.option-group small {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 6px;
}
.option-group .option-label {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
}

/* 单选卡片组 */
.radio-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.radio-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-primary);
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.radio-card i { font-size: 1.1rem; }
.radio-card:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}
.radio-card.active {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.input-number, .input-text {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border var(--transition);
    outline: none;
}
.input-number:focus, .input-text:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.code-font { font-family: 'SF Mono', 'Fira Code', monospace; }

.quick-delimiters {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.chip {
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all var(--transition);
    color: var(--text-secondary);
}
.chip:hover {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent);
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

/* ---------- 输出区域 ---------- */
.output-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.view-switch {
    display: flex;
    gap: 4px;
    background: var(--bg-primary);
    padding: 4px;
    border-radius: var(--radius-sm);
}
.view-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}
.view-btn.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}
.view-btn:hover:not(.active) { color: var(--text-secondary); }
.search-output {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-primary);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    flex: 1;
    max-width: 280px;
}
.search-output i { color: var(--text-muted); }
.search-output input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    color: var(--text-primary);
    font-size: 0.85rem;
}
.output-container {
    min-height: 180px;
}
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-muted);
    text-align: center;
}
.empty-state i { font-size: 3rem; margin-bottom: 16px; opacity: 0.5; }

/* 结果卡片 */
.chunk-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.chunk-card {
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 16px;
    border: 1px solid var(--border-color);
    transition: all var(--transition);
    position: relative;
}
.chunk-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}
.chunk-card .chunk-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.chunk-card .chunk-num {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--accent);
    background: var(--accent-light);
    padding: 2px 10px;
    border-radius: 20px;
}
.chunk-card .chunk-actions {
    display: flex;
    gap: 4px;
}
.chunk-card .chunk-actions button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-muted);
    transition: all var(--transition);
}
.chunk-card .chunk-actions button:hover { background: var(--accent-light); color: var(--accent); }
.chunk-card .chunk-content {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-card);
    padding: 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

/* 列表视图 */
.chunk-list .chunk-item {
    display: flex;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    align-items: flex-start;
}
.chunk-list .chunk-item:last-child { border-bottom: none; }
.chunk-list .chunk-num {
    font-weight: 700;
    color: var(--accent);
    min-width: 50px;
    font-size: 0.9rem;
}
.chunk-list .chunk-content {
    flex: 1;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 120px;
    overflow-y: auto;
    background: var(--bg-primary);
    padding: 8px 12px;
    border-radius: 6px;
}
.chunk-list .chunk-actions {
    display: flex;
    gap: 4px;
}
.chunk-list .chunk-actions button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-muted);
    transition: all var(--transition);
}
.chunk-list .chunk-actions button:hover { background: var(--accent-light); color: var(--accent); }

/* 原始视图 */
.chunk-raw {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-break: break-all;
    background: var(--bg-primary);
    padding: 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    max-height: 500px;
    overflow-y: auto;
}
.chunk-raw .raw-block {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 2px dashed var(--border-color);
}
.chunk-raw .raw-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.chunk-raw .raw-block::before {
    content: attr(data-label);
    display: block;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.output-stats {
    display: flex;
    gap: 24px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-muted);
}
.output-stats strong { color: var(--text-primary); }

/* ---------- 历史记录 ---------- */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    transition: all var(--transition);
}
.history-item:hover { border-color: var(--accent); }
.history-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
}
.history-info .history-title {
    font-weight: 600;
    color: var(--text-primary);
}
.history-info .history-meta {
    color: var(--text-muted);
    font-size: 0.78rem;
}
.history-actions {
    display: flex;
    gap: 8px;
}
.history-actions button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    transition: all var(--transition);
}
.history-actions button:hover { background: var(--accent-light); color: var(--accent); }

/* ---------- 页脚 ---------- */
.app-footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    padding: 20px 0;
    margin-top: 40px;
}
.footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.footer-links {
    display: flex;
    gap: 16px;
}
.footer-links a {
    color: var(--text-muted);
    transition: color var(--transition);
}
.footer-links a:hover { color: var(--accent); }

/* ---------- 弹窗 ---------- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 460px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    transform: scale(0.95);
    transition: transform 0.3s;
}
.modal-overlay.open .modal-content { transform: scale(1); }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-header h3 { font-size: 1.3rem; font-weight: 600; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: color var(--transition);
    line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body p { margin-bottom: 12px; color: var(--text-secondary); }
.modal-body ul { list-style: none; padding: 0; }
.modal-body ul li {
    padding: 6px 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.modal-body ul li::before {
    content: "✓ ";
    color: var(--accent);
    font-weight: 700;
}
.tech-tag {
    margin-top: 16px;
    padding: 8px 16px;
    background: var(--accent-light);
    border-radius: 20px;
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
}

/* ---------- Badge ---------- */
.badge {
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 12px;
    border-radius: 20px;
    margin-left: 8px;
}

/* ---------- Toast ---------- */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    font-size: 0.9rem;
    color: var(--text-primary);
    max-width: 360px;
}
.toast i { color: var(--accent); }
.toast.success i { color: #10b981; }
.toast.error i { color: #ef4444; }
@keyframes slideIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
    body { padding-top: 60px; }
    .header-inner { height: 60px; }
    .main-nav { display: none; }
    .main-nav.open {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 60px;
        left: 0;
        width: 100%;
        background: var(--bg-header);
        backdrop-filter: blur(16px);
        border-bottom: 1px solid var(--border-color);
        padding: 12px 20px;
        gap: 4px;
    }
    .mobile-menu-btn { display: flex; }
    .options-grid {
        grid-template-columns: 1fr;
    }
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .card-actions {
        width: 100%;
        justify-content: flex-start;
    }
    .output-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .search-output { max-width: 100%; }
    .chunk-grid {
        grid-template-columns: 1fr;
    }
    .footer-inner {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }
    .input-stats { flex-wrap: wrap; gap: 12px; }
}

@media (max-width: 480px) {
    .container { padding: 0 12px; }
    .card-body { padding: 16px; }
    .card-header { padding: 14px 16px; }
    .radio-group { flex-direction: column; }
    .radio-card { width: 100%; justify-content: center; }
    .output-stats { flex-direction: column; gap: 8px; }
}