/* WeUI 自定义样式 - AI错题管家 */

/* 全局样式 */
body {
    background: #ededed;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

.container {
    max-width: 100%;
    min-height: 100vh;
    position: relative;
    padding-bottom: 60px;
}

/* 顶部导航栏 */
.navbar-custom {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-custom .weui-navbar__title {
    color: white;
    font-size: 18px;
    font-weight: 600;
}

.navbar-right {
    display: flex;
    align-items: center;
}

.user-chip {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 12px;
    border-radius: 16px;
    color: white;
    text-decoration: none;
    font-size: 14px;
}

/* 页面内容 */
.page-content-custom {
    padding: 16px;
    padding-bottom: 80px;
}

/* 底部 Tabbar */
.tabbar-custom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 100;
    display: flex;
}

.tabbar-custom .weui-tabbar__item {
    text-decoration: none;
    color: #999;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 0 4px;
}

.tabbar-custom .weui-tabbar__item.weui-bar__item_on {
    color: #667eea;
}

.tabbar-custom .weui-tabbar__icon {
    font-size: 24px;
    display: block;
    text-align: center;
    margin-bottom: 4px;
}

.tabbar-custom .weui-tabbar__label {
    text-align: center;
}

/* 按钮样式 */
.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 14px 24px;
    font-size: 16px;
    width: 100%;
    cursor: pointer;
    transition: opacity 0.3s;
}

.btn-primary:active {
    opacity: 0.8;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 登录页 */
.login-logo {
    text-align: center;
    padding: 40px 0;
}

.login-logo .logo-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.login-logo h2 {
    color: #333;
    margin: 0 0 8px 0;
    font-size: 24px;
}

.login-logo p {
    color: #999;
    margin: 0;
    font-size: 14px;
}

/* 卡片样式 */
.card-custom {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

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

.stat-item {
    background: white;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 28px;
    font-weight: bold;
    color: #667eea;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12px;
    color: #999;
}

/* 表单输入 */
.input-custom {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    font-size: 16px;
    box-sizing: border-box;
    transition: border-color 0.3s;
}

.input-custom:focus {
    outline: none;
    border-color: #667eea;
}

/* 列表项 */
.list-item {
    background: white;
    padding: 16px;
    border-bottom: 1px solid #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

/* 标签 */
.tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.tag-primary {
    background: #e8ecfd;
    color: #667eea;
}

.tag-success {
    background: #e6f7e6;
    color: #52c41a;
}

.tag-warning {
    background: #fff7e6;
    color: #fa8c16;
}

.tag-danger {
    background: #fff1f0;
    color: #ff4d4f;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state-icon {
    font-size: 48px;
    color: #ddd;
    margin-bottom: 16px;
}

.empty-state-title {
    color: #999;
    font-size: 16px;
}

/* 响应式 */
@media (min-width: 768px) {
    .container {
        max-width: 430px;
        margin: 0 auto;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    }
}

/* 动画 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* =============================================================================
 * Markdown 渲染样式（错题详情）
 * 适配钉钉工作台 H5：表格横滚、强可读性、移动端字号
 * ========================================================================= */

.error-section {
    padding: 12px 16px;
    background: #fff;
    border-radius: 8px;
    margin: 0 0 12px;
}
.error-section-title {
    font-size: 14px;
    color: #999;
    margin-bottom: 8px;
}

.md-body {
    color: #1f2937;
    font-size: 15px;
    line-height: 1.7;
    word-break: break-word;
}
.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4 {
    margin: 14px 0 8px;
    line-height: 1.4;
    font-weight: 600;
    color: #111827;
}
.md-body h1 { font-size: 18px; }
.md-body h2 { font-size: 17px; }
.md-body h3 { font-size: 16px; }
.md-body h4 { font-size: 15px; }
.md-body p {
    margin: 6px 0;
}
.md-body ul,
.md-body ol {
    padding-left: 22px;
    margin: 6px 0;
}
.md-body li { margin: 2px 0; }
.md-body code {
    background: #f3f4f6;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 13px;
}
.md-body pre {
    background: #f3f4f6;
    padding: 10px 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 13px;
}
.md-body img {
    max-width: 100%;
    height: auto;
}

/* 表格：钉钉小屏环境下 OCR 表格容易撑爆，加横向滚动 */
.md-body table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 8px 0;
}
.md-body th,
.md-body td {
    border: 1px solid #d9d9d9;
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
    white-space: normal;
}
.md-body thead th {
    background: #f8fafc;
    font-weight: 600;
}

/* 折叠：默认最多显示 ~280px 高，超出渐隐 */
.md-collapsed {
    max-height: 280px;
    overflow: hidden;
    position: relative;
}
.md-collapsed::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 60px;
    background: linear-gradient(to bottom, rgba(255,255,255,0), #fff);
    pointer-events: none;
}

.content-toggle-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    padding: 8px 0 0;
    border-top: 1px dashed #e5e7eb;
    margin-top: 8px;
}
.md-toggle-link {
    color: #576b95;
    font-size: 13px;
    text-decoration: none;
}
.md-toggle-link:active {
    opacity: 0.7;
}
.md-fallback {
    background: #fff7e6;
    padding: 8px;
    border-radius: 6px;
    color: #b45309;
    font-size: 12px;
    white-space: pre-wrap;
}

.processing-error-tip {
    margin-top: 8px;
    padding: 8px 12px;
    background: #fff1f0;
    color: #b91c1c;
    font-size: 13px;
    border-radius: 6px;
    border-left: 3px solid #f5222d;
}

/* Markdown 全屏弹层 */
.md-modal-mask {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    padding: 16px;
}
.md-modal-card {
    background: #fff;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.md-modal-head,
.md-modal-foot {
    padding: 12px 16px;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: none;
}
.md-modal-head {
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    color: #111827;
}
.md-modal-close {
    color: #6b7280;
    text-decoration: none;
    font-size: 18px;
    padding: 4px 8px;
}
.md-modal-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}
.md-modal-foot {
    border-top: 1px solid #e5e7eb;
    gap: 8px;
    justify-content: flex-end;
}
.md-modal-foot-btn {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    border: 1px solid #d1d5db;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
}
.md-modal-foot-btn.primary {
    background: #07c160;
    color: #fff;
    border-color: #07c160;
}

/* 钉钉容器内（is-dingtalk 标记由 base.html 注入）的小幅适配 */
body.is-dingtalk .md-body { font-size: 14px; }
body.is-dingtalk .md-collapsed { max-height: 220px; }

/* =============================================================================
 * PDF 导出/打印样式
 * 通过 body.pdf-export-mode 类或 @media print 控制，只输出错题内容
 * ========================================================================= */

body.pdf-export-mode .no-print {
    display: none !important;
}

@media print {
    .no-print {
        display: none !important;
    }

    /* 页面容器重置 */
    .container {
        padding-bottom: 0 !important;
        max-width: 100% !important;
        box-shadow: none !important;
    }

    .page-content-custom {
        padding: 0 !important;
        padding-bottom: 0 !important;
    }

    /* 卡片去阴影、去边距，避免打印出现多余空白 */
    .card-custom {
        box-shadow: none !important;
        border-radius: 0 !important;
        margin-bottom: 12px !important;
        padding: 12px !important;
    }

    /* 展开被折叠的 markdown 内容 */
    .md-collapsed {
        max-height: none !important;
        overflow: visible !important;
    }
    .md-collapsed::after {
        display: none !important;
    }

    /* 保证图片在打印页内完整显示 */
    .card-custom img {
        max-width: 100% !important;
        max-height: 240pt !important;
        page-break-inside: avoid;
    }

    /* 表格分页保护 */
    table {
        page-break-inside: avoid;
    }
}

/* 程序触发打印时使用的类（与 @media print 共享隐藏逻辑） */
body.pdf-export-mode .navbar-custom,
body.pdf-export-mode .tabbar-custom {
    display: none !important;
}

body.pdf-export-mode .container {
    padding-bottom: 0 !important;
}

body.pdf-export-mode .page-content-custom {
    padding: 0 !important;
    padding-bottom: 0 !important;
}

body.pdf-export-mode .card-custom {
    box-shadow: none !important;
    border-radius: 0 !important;
    margin-bottom: 12px !important;
}

body.pdf-export-mode .md-collapsed {
    max-height: none !important;
    overflow: visible !important;
}

body.pdf-export-mode .md-collapsed::after {
    display: none !important;
}
