/**
 * 510K 在线考试系统 - 统一主题
 * 视觉参考：form-elements.css（按钮 #4aaf51 / 50px 控件）、
 *           dashboard.css（顶部导航 + 灰色侧栏）、
 *           style1.css（考试蓝 #4ab4f5 / #3aa4e5、浅绿表格 #4f6b72）
 */
:root {
    --brand: #4aaf51;
    --brand-dark: #3d9443;
    --exam-blue: #4ab4f5;
    --exam-blue-dark: #3aa4e5;
    --nav-blue: #428bca;
    --ink: #333333;
    --ink-soft: #4f6b72;
    --muted: #888888;
    --line: #e5e7eb;
    --sidebar: #f5f5f5;
    --bg: #f4f6f9;
    --radius: 6px;
    --shadow: 0 2px 10px rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Tahoma, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
}

a { color: var(--exam-blue-dark); text-decoration: none; }
a:hover { color: var(--brand-dark); }
img { max-width: 100%; }

/* ============ 顶部导航 ============ */
.app-navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: 52px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 18px;
    background: linear-gradient(90deg, #2f6fb5, var(--exam-blue-dark));
    color: #fff;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .12);
}
.app-navbar .brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; color: #fff; }
.app-navbar .brand i { font-size: 20px; }
.app-navbar .nav-clock { margin-left: auto; font-size: 13px; opacity: .9; }
.app-navbar .navbar-nav { display: flex; align-items: center; gap: 4px; margin: 0; padding: 0; list-style: none; }
.app-navbar .nav-link {
    display: block; padding: 6px 12px; border-radius: 4px; color: rgba(255, 255, 255, .92); font-size: 14px;
}
.app-navbar .nav-link:hover, .app-navbar .nav-link.active { background: rgba(255, 255, 255, .16); color: #fff; }
.app-navbar .user-menu { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.app-navbar .user-menu .avatar {
    width: 30px; height: 30px; border-radius: 50%; background: rgba(255, 255, 255, .25);
    display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
}
.app-navbar .btn-logout { color: #fff; opacity: .9; }
.app-navbar .btn-logout:hover { opacity: 1; text-decoration: underline; }

/* ============ 布局：侧栏 + 主内容 ============ */
.app-shell { display: flex; align-items: flex-start; min-height: calc(100vh - 52px); }
.app-sidebar {
    flex: 0 0 210px;
    width: 210px;
    background: var(--sidebar);
    border-right: 1px solid var(--line);
    padding: 16px 0 30px;
    position: sticky;
    top: 52px;
    height: calc(100vh - 52px);
    overflow-y: auto;
}
.app-sidebar .side-title {
    padding: 8px 20px; color: var(--muted); font-size: 12px; letter-spacing: 1px; text-transform: uppercase;
}
.app-sidebar .side-nav { list-style: none; margin: 0 0 12px; padding: 0; }
.app-sidebar .side-nav a {
    display: flex; align-items: center; gap: 9px;
    padding: 9px 20px; color: #555; font-size: 14px; border-left: 3px solid transparent;
}
.app-sidebar .side-nav a i { width: 16px; text-align: center; color: #7b8794; }
.app-sidebar .side-nav a:hover { background: #e9eef5; color: var(--ink); }
.app-sidebar .side-nav a.active {
    background: #e7f2fd; color: var(--exam-blue-dark); border-left-color: var(--exam-blue); font-weight: 600;
}
.app-sidebar .side-badge { margin-left: auto; font-size: 12px; background: #cfd8dc; color: #455a64; border-radius: 10px; padding: 0 7px; }

.app-main { flex: 1 1 auto; min-width: 0; padding: 22px 26px 40px; }

/* 表格容器内横向滚动（手机端） */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap .table-app { min-width: 600px; }

.app-footer {
    padding: 14px 20px; text-align: center; color: var(--muted); font-size: 13px;
    background: #e9ecef; border-top: 1px solid var(--line);
}

/* ============ 通用组件 ============ */
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel + .panel { margin-top: 18px; }
.panel-head {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; color: var(--ink-soft);
}
.panel-head .h-title { font-size: 16px; }
.panel-head .h-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.panel-body { padding: 16px; }
.page-title { margin: 0 0 14px; font-size: 20px; font-weight: 700; color: var(--exam-blue-dark); }
.page-sub { color: var(--muted); font-size: 13px; }

.btn {
    display: inline-flex; align-items: center; gap: 6px; justify-content: center;
    border-radius: 4px; border: 1px solid transparent; padding: 8px 16px; font-size: 14px; cursor: pointer;
    transition: all .25s ease-in; text-decoration: none;
}
.btn-primary, .btn-app { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover, .btn-app:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-info-app { background: var(--exam-blue); border-color: var(--exam-blue); color: #fff; }
.btn-info-app:hover { background: var(--exam-blue-dark); color: #fff; }
.btn-ghost-app { background: #eef6fa; border-color: #aad3fa; color: var(--ink-soft); }
.btn-ghost-app:hover { background: #fff; color: #5f7b82; }
.btn-dangerous { background: #e05c5c; border-color: #e05c5c; color: #fff; }
.btn-dangerous:hover { background: #cc4c4c; color: #fff; }

.form-control, .form-select { border: 1px solid #d7dbe0; border-radius: 4px; padding: 8px 12px; font-size: 14px; }
.form-control:focus, .form-select:focus { border-color: var(--exam-blue); box-shadow: 0 0 0 3px rgba(74, 180, 245, .15); }
.form-label { font-size: 14px; font-weight: 600; color: #444; margin-bottom: 6px; }
.form-actions { display: flex; gap: 10px; padding-top: 6px; }

.table-app { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; }
.table-app th, .table-app td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table-app thead th { background: #eef2f6; color: var(--ink-soft); font-weight: 700; white-space: nowrap; }
.table-app tbody tr:nth-child(odd) { background: #fafcfd; }
.table-app tbody tr:hover { background: #f2f8ff; }
.table-app td.actions { white-space: nowrap; text-align: right; }

.empty-state { padding: 46px 16px; text-align: center; color: var(--muted); }
.empty-state i { font-size: 34px; color: #c3ccd5; display: block; margin-bottom: 8px; }

/* 分页（参考 Pages.css） */
.pagination-app { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 16px 0 0; padding: 0; list-style: none; }
.pagination-app a, .pagination-app span {
    display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 4px;
    background: #fff; color: #555; font-size: 13px;
}
.pagination-app .active span { background: var(--exam-blue); border-color: var(--exam-blue); color: #fff; }
.pagination-app a:hover { background: #eef6fa; border-color: #aad3fa; }

/* 统计卡片 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.stat-card {
    display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line);
    background: #fff; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat-card::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--exam-blue); }
.stat-card.is-green::after { background: var(--brand); }
.stat-card.is-orange::after { background: #f0ad4e; }
.stat-card.is-red::after { background: #e05c5c; }
.stat-card .icon {
    width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    background: #eef6fa; color: var(--exam-blue-dark); font-size: 20px; flex: 0 0 auto;
}
.stat-card .num { font-size: 24px; font-weight: 700; color: var(--ink); line-height: 1.2; }
.stat-card .label { color: var(--muted); font-size: 13px; }

/* ============ 试卷卡片（学生端） ============ */
.paper-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.paper-card {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px; display: flex; flex-direction: column; gap: 10px; transition: all .25s ease-in;
}
.paper-card:hover { border-color: var(--exam-blue); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(74, 180, 245, .18); }
.paper-card .pc-title { font-size: 16px; font-weight: 700; color: var(--exam-blue-dark); }
.paper-card .pc-meta { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 13px; }
.paper-card .pc-meta span i { color: var(--exam-blue); margin-right: 4px; }
.paper-card .pc-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-chip { background: #eef6fa; border: 1px solid #aad3fa; color: var(--ink-soft); border-radius: 20px; font-size: 12px; padding: 2px 10px; }
.tag-chip.green { background: #eefaf0; border-color: #b6e3bd; color: var(--brand-dark); }
.paper-card .pc-foot { margin-top: auto; display: flex; gap: 8px; align-items: center; }

/* 类型筛选 */
.type-filter { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.type-filter a {
    padding: 6px 16px; border: 1px solid #aad3fa; border-radius: 20px; background: #fff; color: var(--exam-blue-dark); font-size: 14px;
}
.type-filter a.active, .type-filter a:hover { background: var(--exam-blue); border-color: var(--exam-blue); color: #fff; }

/* ============ 考试页 ============ */
.exam-layout { display: flex; gap: 18px; align-items: flex-start; }
.exam-body {
    flex: 1 1 auto; min-width: 0; background: #fff; border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px 30px;
}
.exam-side { flex: 0 0 230px; width: 230px; position: sticky; top: 68px; }
.exam-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.exam-head .title { font-size: 20px; font-weight: 700; color: var(--exam-blue-dark); }
.exam-head .meta { color: var(--muted); font-size: 13px; }
.countdown-box {
    display: inline-flex; align-items: center; gap: 8px; padding: 8px 18px; border-radius: 30px;
    background: #eef6fa; border: 1px solid #aad3fa; color: var(--ink-soft); font-weight: 700; font-size: 18px;
}
.countdown-box.is-danger { background: #fdecec; border-color: #f5c2c2; color: #c0392b; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }

.q-card {
    border: 1px solid var(--line); border-radius: var(--radius); background: #fcfcfc; padding: 14px 16px; margin-bottom: 14px;
    transition: all .25s ease-in; scroll-margin-top: 70px;
}
.q-card:hover { border-color: var(--exam-blue); }
.q-card.is-answered { border-left: 4px solid var(--brand); }
.q-head { display: flex; gap: 8px; align-items: baseline; border-bottom: 1px dotted #ccc; padding-bottom: 8px; margin-bottom: 10px; }
.q-head .q-no { font-weight: 700; color: var(--exam-blue-dark); }
.q-head .q-type { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 6px; }
.q-head .q-score { margin-left: auto; color: var(--muted); font-size: 13px; }
.q-text { font-size: 15px; line-height: 1.8; }
.q-text img { margin-top: 8px; border: 1px solid var(--line); border-radius: 4px; }
.q-options { margin-top: 10px; }
.q-options label {
    display: block; padding: 6px 10px; border-radius: 4px; cursor: pointer; transition: background .2s;
}
.q-options label:hover { background: #e5f2ff; }
.q-options input[type="radio"], .q-options input[type="checkbox"] { margin-right: 8px; cursor: pointer; }
.q-fill input { min-width: 160px; }

/* 答题卡 */
.answer-sheet { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.answer-sheet .as-head { padding: 10px 14px; background: #eef6fa; border-bottom: 1px solid var(--line); font-weight: 700; color: var(--ink-soft); }
.answer-sheet .as-body { padding: 12px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 6px; }
.answer-sheet .as-body a {
    display: flex; align-items: center; justify-content: center; height: 32px; border-radius: 4px;
    border: 1px solid #d7dbe0; background: #fff; color: #666; font-size: 13px;
}
.answer-sheet .as-body a.done { background: var(--brand); border-color: var(--brand); color: #fff; }
.answer-sheet .as-foot { padding: 12px 14px; border-top: 1px solid var(--line); }
.answer-sheet .legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); padding: 0 14px 10px; }
.answer-sheet .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }

/* ============ 结果页 ============ */
.result-box { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; justify-content: center; padding: 18px; }
.result-score { font-size: 52px; font-weight: 800; color: var(--brand); line-height: 1; }
.result-score.fail { color: #e05c5c; }
.result-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.result-meta .cell { background: #fafcfd; border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; text-align: center; }
.result-meta .cell .k { color: var(--muted); font-size: 12px; }
.result-meta .cell .v { font-size: 17px; font-weight: 700; color: var(--ink-soft); }

.review-item { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; background: #fff; }
.review-item.right { border-left: 4px solid var(--brand); }
.review-item.wrong { border-left: 4px solid #e05c5c; }
.review-item .r-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.review-answer { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 8px; font-size: 14px; }
.review-answer .correct { color: var(--brand-dark); }
.review-answer .wrong-ans { color: #c0392b; }
.review-analysis { margin-top: 8px; background: #fbfcfd; border-left: 3px solid var(--exam-blue); padding: 8px 12px; color: #555; font-size: 14px; }

/* ============ 错题本 ============ */
.mistake-row { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.mistake-row.mastered { opacity: .65; }
.mistake-row .m-q { flex: 1 1 auto; }
.mistake-row .m-act { display: flex; gap: 8px; flex-shrink: 0; }

/* ============ 登录 / 注册 ============ */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 30px 15px;
    background: linear-gradient(135deg, #3aa4e5, #2f6fb5 45%, #4aaf51);
}
.auth-card {
    width: 100%; max-width: 420px; background: #fff; border-radius: 10px; box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
    padding: 28px 30px 24px;
}
.auth-card .logo { text-align: center; margin-bottom: 16px; }
.auth-card .logo i { font-size: 40px; color: var(--exam-blue); }
.auth-card h1 { font-size: 21px; text-align: center; color: var(--exam-blue-dark); margin: 6px 0 18px; font-weight: 700; }
.auth-card .form-control { height: 46px; margin-bottom: 12px; }
.auth-card .btn-submit { width: 100%; height: 48px; font-size: 16px; background: var(--brand); border: 0; color: #fff; border-radius: 4px; }
.auth-card .btn-submit:hover { opacity: .9; }
.auth-card .extra { display: flex; justify-content: space-between; font-size: 13px; margin-top: 12px; }
.auth-quote { text-align: center; color: var(--muted); font-size: 13px; margin-top: 14px; }

/* ============ Toast ============ */
.toast-stack { position: fixed; top: 62px; right: 18px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.app-toast {
    min-width: 200px; max-width: 320px; padding: 10px 16px; border-radius: 4px; background: #fff;
    border-left: 4px solid var(--exam-blue); box-shadow: 0 4px 16px rgba(0, 0, 0, .12); color: #333; font-size: 14px;
    opacity: 0; transform: translateY(-6px); transition: all .3s ease;
}
.app-toast.show { opacity: 1; transform: translateY(0); }
.app-toast-success { border-left-color: var(--brand); }
.app-toast-error { border-left-color: #e05c5c; }
.app-toast-warning { border-left-color: #f0ad4e; }
.app-toast i { margin-right: 6px; }

/* ============ 响应式 ============ */
/* 平板 */
@media (max-width: 991px) {
    .exam-layout { flex-direction: column; }
    .exam-side { position: static; width: 100%; }
    .answer-sheet .as-body { grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); }
    .app-main { padding: 18px 18px 34px; }
}

/* 手机 */
@media (max-width: 768px) {
    .app-shell { flex-direction: column; }
    .app-sidebar {
        display: none;
        position: static;
        width: 100%;
        height: auto;
        max-height: 72vh;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
    body.sidebar-open .app-sidebar { display: block; }
    .app-main { padding: 14px 12px 26px; }

    .app-navbar { padding: 0 10px; gap: 8px; height: 48px; }
    .app-navbar .brand { font-size: 15px; }
    .app-navbar .nav-clock { display: none; }
    .app-navbar .user-menu { gap: 6px; }
    .app-navbar .user-menu > span:not(.avatar) { display: none; }

    .page-title { font-size: 18px; }
    .panel-body { padding: 12px; }
    .panel-head { padding: 10px 12px; }
    .panel-head .h-actions { width: 100%; margin-left: 0; }
    .form-actions { flex-wrap: wrap; }

    .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
    .stat-card { padding: 12px; gap: 10px; }
    .stat-card .icon { width: 38px; height: 38px; font-size: 17px; }
    .stat-card .num { font-size: 20px; }

    .paper-grid { grid-template-columns: 1fr; gap: 12px; }

    .exam-body { padding: 14px 12px 20px; }
    .countdown-box { font-size: 15px; padding: 6px 14px; }
    .q-text { font-size: 14px; }
    .q-fill input { width: 100%; min-width: 100%; }

    .result-score { font-size: 40px; }
    .mistake-row { flex-direction: column; gap: 10px; }
    .mistake-row .m-act { width: 100%; flex-wrap: wrap; }

    .auth-card { padding: 22px 18px 18px; }
    .toast-stack { top: 54px; right: 10px; left: 10px; }
    .app-toast { max-width: none; }
}

/* 超小屏（≤480px） */
@media (max-width: 480px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .result-meta { grid-template-columns: repeat(2, 1fr); }
    .countdown-box { font-size: 14px; padding: 5px 12px; }
    .btn { padding: 7px 12px; font-size: 13px; }
}

/* ==========================================================
   手机端增强：方便学生用手机做题与复习
   ========================================================== */
@media (max-width: 768px) {
    /* iOS Safari 聚焦输入框时会自动放大页面，字号 ≥16px 可避免 */
    input.form-control, select.form-select, textarea.form-control,
    .q-fill input, .auth-card .form-control { font-size: 16px; }

    /* 加大选项触摸区域，避免误点 */
    .q-options label { padding: 10px 12px; margin-bottom: 6px; }
    .q-options input[type="radio"], .q-options input[type="checkbox"] {
        width: 18px; height: 18px; margin-right: 10px; vertical-align: middle;
    }

    /* 答题 / 练习页头部吸顶：做题时随时能看到倒计时 */
    .exam-body .exam-head {
        position: sticky; top: 48px; z-index: 900; background: #fff;
        padding: 8px 0 10px; margin-bottom: 12px; border-bottom: 1px solid var(--line);
    }
    .exam-head .title { font-size: 16px; }
    .exam-head .meta { font-size: 12px; }

    /* 按钮 / 分页更易点 */
    .btn { min-height: 38px; }
    .btn-sm { min-height: 32px; }
    .pagination-app { gap: 4px; }
    .pagination-app a, .pagination-app span { padding: 6px 10px; }

    /* 表格兜底：面板内可横向滚动，避免整页被撑出横向滚动条 */
    .panel-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-app thead th { white-space: normal; }
    .table-app th, .table-app td { padding: 8px 10px; }

    .result-box { gap: 12px; }
    .review-item { padding: 10px 12px; }
}

/* 答题页：手机端答题卡折叠为悬浮按钮 */
.sheet-fab { display: none; }
@media (max-width: 991px) {
    .sheet-fab {
        display: inline-flex; position: fixed; right: 14px; bottom: 18px; z-index: 1050;
        border-radius: 30px; box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
    }
    .exam-side { display: none; }
    body.sheet-open .exam-side {
        display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1060;
        max-height: 70vh; overflow-y: auto; background: #fff;
        padding: 10px; border-top: 1px solid var(--line); box-shadow: 0 -4px 18px rgba(0, 0, 0, .15);
    }
    body.sheet-open .exam-side .answer-sheet { box-shadow: none; }
}
