/**
 * 公共样式 - 从 index.php 抽离
 * 包含：基础样式、布局、按钮、表单、卡片、导航等
 */

/* ========== 基础重置 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { 
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; 
    background: #f5f5f5; 
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========== 容器布局 ========== */
.container { max-width: none; width: 100%; margin: 0; padding: 20px 24px; flex: 1 0 auto; box-sizing: border-box; }
h1 { text-align: center; color: #333; margin-bottom: 10px; }
.subtitle { text-align: center; color: #666; margin-bottom: 20px; }

/* ========== 导航栏 ========== */
.nav { display: flex; justify-content: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.nav a { padding: 10px 20px; background: #fff; border-radius: 8px; text-decoration: none; color: #555; }
.nav a.active, .nav a:hover { background: #4f46e5; color: #fff; }

/* ========== 状态栏 ========== */
.status-bar { background: #fff; border-radius: 8px; padding: 12px 16px; margin-bottom: 20px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.status-item { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.green { background: #10b981; }
.status-dot.red { background: #ef4444; }
.status-dot.yellow { background: #f59e0b; }

/* ========== 卡片 ========== */
.card { background: #fff; border-radius: 12px; padding: 24px; margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.card h2 { color: #444; margin-bottom: 16px; font-size: 18px; border-bottom: 1px solid #eee; padding-bottom: 10px; }
.card h3 { color: #555; margin-bottom: 12px; font-size: 16px; }

/* ========== 表单 ========== */
.form-group { margin-bottom: 16px; }
label { display: block; margin-bottom: 6px; color: #555; font-weight: 500; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; }
textarea { min-height: 120px; resize: vertical; font-family: inherit; }
.inline-group { display: flex; gap: 12px; }
.inline-group .form-group { flex: 1; }
.help-text { font-size: 12px; color: #888; margin-top: 4px; }

/* ========== 按钮 ========== */
.btn-group { display: flex; gap: 10px; flex-wrap: wrap; }
button { padding: 10px 20px; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500; transition: all 0.2s; }
.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-secondary { background: #10b981; color: #fff; }
.btn-secondary:hover { background: #059669; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-info { background: #06b6d4; color: #fff; }
.btn-info:hover { background: #0891b2; }
.btn-danger { background: #ef4444; color: #fff; padding: 6px 12px; font-size: 12px; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ========== 结果展示 ========== */
.result { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 16px; white-space: pre-wrap; line-height: 1.8; max-height: 500px; overflow-y: auto; }
.error { background: #fef2f2; border-color: #fecaca; color: #dc2626; }

/* ========== 提示框 ========== */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; }
.alert-warning { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }
.alert-info { background: #eff6ff; border: 1px solid #93c5fd; color: #1e40af; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }

/* ========== 网格布局 ========== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 1200px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 768px) { 
    .grid-2, .grid-3 { grid-template-columns: 1fr; } 
    .container { padding: 16px 20px; } 
}
@media (max-width: 640px) { 
    .container { padding: 14px 16px; } 
    .card { padding: 16px; border-radius: 10px; }
    .card h2 { font-size: 16px; }
    button { padding: 8px 16px; font-size: 13px; }
    .btn-group { gap: 8px; }
    .form-group { margin-bottom: 12px; }
    input, select, textarea { padding: 8px 10px; font-size: 13px; }
    .inline-group { flex-direction: column; gap: 0; }
}
@media (max-width: 480px) {
    .container { padding: 12px; }
    .card { padding: 14px; border-radius: 8px; margin-bottom: 14px; }
    .card h2 { font-size: 15px; padding-bottom: 8px; margin-bottom: 12px; }
    button { padding: 7px 14px; font-size: 12px; border-radius: 6px; }
    .nav { gap: 6px; }
    .nav a { padding: 8px 14px; font-size: 13px; }
    .tabs a { padding: 10px 12px; font-size: 13px; }
}

/* ========== 项目卡片 ========== */
.item-card { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.item-card h4 { margin-bottom: 6px; color: #333; font-size: 14px; }
.item-card p { color: #666; font-size: 13px; margin-bottom: 8px; }
.item-actions { display: flex; gap: 6px; }

/* ========== 章节列表 ========== */
.chapter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}
.chapter-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.btn-import {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1d4ed8;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.btn-export {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.chapter-item { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid #eee; }
.chapter-item:last-child { border-bottom: none; }

/* 手机端章节列表优化 */
@media (max-width: 640px) {
    .chapter-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .chapter-header h2 {
        font-size: 15px !important;
        line-height: 1.4;
    }
    .chapter-actions {
        width: 100%;
        gap: 8px;
    }
    .btn-import,
    .btn-export {
        flex: 1;
        padding: 10px 12px !important;
        font-size: 13px !important;
        text-align: center;
        white-space: nowrap;
    }
    .chapter-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 8px;
    }
    .chapter-item > div:first-child {
        width: 100%;
    }
    .item-actions {
        width: 100%;
        gap: 8px;
    }
    .item-actions .btn-sm {
        flex: 1;
        padding: 10px 12px !important;
        font-size: 14px !important;
        text-align: center;
        white-space: nowrap;
    }
}


/* ========== 空状态提示 ========== */
.empty-tip { color: #888; font-size: 14px; padding: 20px; text-align: center; background: #f8fafc; border-radius: 8px; }

/* ========== 标签页 ========== */
.tabs { display: flex; gap: 0; margin-bottom: 20px; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.tabs a { flex: 1; padding: 14px 20px; text-decoration: none; color: #666; text-align: center; border-bottom: 3px solid transparent; }
.tabs a:hover { background: #f8fafc; color: #4f46e5; }
.tabs a.active { color: #4f46e5; border-bottom-color: #4f46e5; background: #f8fafc; font-weight: 500; }

/* ========== 服务商卡片 ========== */
.provider-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.provider-card { padding: 16px; border: 2px solid #e2e8f0; border-radius: 10px; cursor: pointer; text-align: center; }
.provider-card:hover { border-color: #4f46e5; background: #f8fafc; }
.provider-card.active { border-color: #4f46e5; background: #eef2ff; }
.provider-card .name { font-weight: 600; color: #333; }

/* ========== 表格 ========== */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px; text-align: left; border-bottom: 1px solid #eee; }
.table th { background: #f8fafc; font-weight: 500; }

/* ========== 锁定提示 ========== */
.lock-tip { background: #fff3cd; border: 1px solid #ffc107; color: #856404; padding: 20px; border-radius: 10px; text-align: center; }
.lock-tip h3 { margin-bottom: 10px; }

/* ========== 宽屏布局 ========== */
.wide-layout { display: grid; grid-template-columns: 1fr 350px; gap: 24px; }
@media (max-width: 1200px) { .wide-layout { grid-template-columns: 1fr 300px; gap: 20px; } }
@media (max-width: 1024px) { .wide-layout { grid-template-columns: 1fr; } }

/* ========== 侧边栏响应式 ========== */
@media (max-width: 1024px) { #chapterSidebar { display: none; } }

/* ========== 表格响应式 ========== */
@media (max-width: 768px) {
    .table { font-size: 13px; }
    .table th, .table td { padding: 8px 6px; }
}
@media (max-width: 640px) {
    .table { font-size: 12px; }
    .table th, .table td { padding: 6px 4px; }
    .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ========== 状态栏响应式 ========== */
@media (max-width: 768px) {
    .status-bar { padding: 10px 12px; gap: 12px; }
    .status-item { font-size: 13px; }
}
@media (max-width: 640px) {
    .status-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ========== 标签页响应式 ========== */
@media (max-width: 768px) {
    .tabs { border-radius: 8px; }
    .tabs a { padding: 12px 16px; font-size: 13px; }
}
@media (max-width: 640px) {
    .tabs { flex-wrap: wrap; }
    .tabs a { flex: none; min-width: 50%; padding: 10px 12px; }
}
@media (max-width: 480px) {
    .tabs a { min-width: 100%; border-bottom: 1px solid #eee; }
    .tabs a:last-child { border-bottom: none; }
}

/* ========== 服务商卡片响应式 ========== */
@media (max-width: 768px) {
    .provider-cards { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
    .provider-card { padding: 12px; }
}
@media (max-width: 480px) {
    .provider-cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .provider-card { padding: 10px; border-radius: 8px; }
    .provider-card .name { font-size: 13px; }
}

/* ========== Toast 动画 ========== */
@keyframes toastIn { 
    from { opacity: 0; transform: translateX(-50%) translateY(-20px); } 
    to { opacity: 1; transform: translateX(-50%) translateY(0); } 
}
@keyframes toastOut { 
    from { opacity: 1; transform: translateX(-50%) translateY(0); } 
    to { opacity: 0; transform: translateX(-50%) translateY(-20px); } 
}

/* ========== 通用动画 ========== */
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(-20px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(-50%) translateY(0); } to { opacity: 0; transform: translateX(-50%) translateY(-20px); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

/* ========== 深色模式 - 公共组件适配 ========== */
body.dark-mode {
    background: #1a1a2e !important;
    color: #e0e0e0 !important;
}

/* 容器和标题 */
body.dark-mode h1 { color: #e0e0e0 !important; }
body.dark-mode .subtitle { color: #aaa !important; }

/* 导航 */
body.dark-mode .nav a { background: #16213e; color: #aaa; }
body.dark-mode .nav a.active, body.dark-mode .nav a:hover { background: #4f46e5; color: #fff; }

/* 状态栏 */
body.dark-mode .status-bar { background: #16213e !important; }
body.dark-mode .status-item { color: #e0e0e0; }

/* 卡片 */
body.dark-mode .card { background: #16213e !important; color: #e0e0e0 !important; box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important; }
body.dark-mode .card h2 { color: #e0e0e0 !important; border-bottom-color: #2a2a4a !important; }
body.dark-mode .card h3 { color: #d0d0d0 !important; }

/* 表单 */
body.dark-mode label { color: #ccc !important; }
body.dark-mode input, body.dark-mode select, body.dark-mode textarea {
    background: #0f3460 !important;
    color: #e0e0e0 !important;
    border-color: #2a2a4a !important;
}
body.dark-mode .help-text { color: #888 !important; }
body.dark-mode ::placeholder { color: #666 !important; }

/* 结果展示 */
body.dark-mode .result { background: #1a1a3e !important; border-color: #2a2a4a !important; color: #e0e0e0 !important; }
body.dark-mode .error { background: #2e0a0a !important; border-color: #991b1b !important; color: #fca5a5 !important; }

/* 提示框 */
body.dark-mode .alert-warning { background: #2e1a0a !important; border-color: #854d0e !important; color: #fcd34d !important; }
body.dark-mode .alert-info { background: #0a1a2e !important; border-color: #1e40af !important; color: #93c5fd !important; }
body.dark-mode .alert-success { background: #0a2e1a !important; border-color: #166534 !important; color: #6ee7b7 !important; }

/* 项目卡片 */
body.dark-mode .item-card { background: #1a1a3e !important; border-color: #2a2a4a !important; }
body.dark-mode .item-card h4 { color: #e0e0e0 !important; }
body.dark-mode .item-card p { color: #aaa !important; }

/* 章节列表 */
body.dark-mode .chapter-item { border-bottom-color: #2a2a4a !important; }

/* 空状态 */
body.dark-mode .empty-tip { color: #888 !important; background: #1a1a3e !important; }

/* 标签页 */
body.dark-mode .tabs { background: #16213e !important; box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important; }
body.dark-mode .tabs a { color: #aaa !important; }
body.dark-mode .tabs a:hover { background: #1a1a3e !important; color: #a78bfa !important; }
body.dark-mode .tabs a.active { color: #a78bfa !important; border-bottom-color: #a78bfa !important; background: #1a1a3e !important; }

/* 服务商卡片 */
body.dark-mode .provider-card { border-color: #2a2a4a !important; background: #16213e !important; }
body.dark-mode .provider-card:hover { border-color: #4f46e5 !important; background: #1a1a3e !important; }
body.dark-mode .provider-card.active { border-color: #4f46e5 !important; background: #1a1a3e !important; }
body.dark-mode .provider-card .name { color: #e0e0e0 !important; }

/* 表格 */
body.dark-mode .table th { background: #1a1a3e !important; color: #ccc !important; }
body.dark-mode .table th, body.dark-mode .table td { border-bottom-color: #2a2a4a !important; }

/* 锁定提示 */
body.dark-mode .lock-tip { background: #2e1a0a !important; border-color: #854d0e !important; color: #fcd34d !important; }

/* 按钮 - 次要按钮 */
body.dark-mode .btn-secondary { background: #059669 !important; }
body.dark-mode .btn-danger { background: #dc2626 !important; }

/* ========== 深色模式 - hover/active 状态修复（8.1.9） ========== */
body.dark-mode .tabs a:hover { background: #1a1a3e !important; color: #a78bfa !important; }
body.dark-mode .tabs a.active { background: #1a1a3e !important; color: #a78bfa !important; border-bottom-color: #a78bfa !important; }
body.dark-mode .provider-card:hover { border-color: #4f46e5 !important; background: #1a1a3e !important; }
body.dark-mode .provider-card.active { border-color: #4f46e5 !important; background: #1a1a3e !important; }
