/* ============================================================
   工单系统样式（v2）
   —— 详情页双栏、动态表单、Markdown 渲染、管理面板
   依赖 style.css 里定义的 CSS 变量（--main / --line / --text 等）
   ============================================================ */

/* ---------- 用户名颜色 ---------- */
.uname-purple { color: #7c3aed; font-weight: 700; }
.uname-blue   { color: #2563eb; font-weight: 600; }
.uname-gray   { color: #6b7280; }

.role-tag {
    display: inline-block; margin-left: 6px; padding: 1px 7px;
    border: 1px solid transparent;   /* 边框在这里定义，后面只改颜色 */
    border-radius: 4px; font-size: 11px; font-weight: 400;
    line-height: 1.6; vertical-align: 1px; white-space: nowrap;
}
.role-tag-purple { background: #ede9fe; color: #6d28d9; border-color: #ddd6fe; }
.role-tag-blue   { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }

/* 头衔占用和身份标签同一个位置（二选一显示）。
   颜色跟着名字走：DOM 里头衔紧跟在名字 span 后面，用相邻兄弟选择器即可。 */
.uname-purple + .role-tag-title {
    background: #ede9fe;
    color: #6d28d9;
    border-color: #ddd6fe;
}
.uname-blue + .role-tag-title {
    background: #dbeafe;
    color: #1e40af;
    border-color: #bfdbfe;
}
.uname-gray + .role-tag-title {
    background: #f3f4f6;
    color: #4b5563;
    border-color: #e5e7eb;
}

/* ---------- 头像 ---------- */
.mini-avatar {
    width: 20px; height: 20px; border-radius: 50%;
    vertical-align: -4px; margin-right: 5px; background: var(--line);
}

/* ---------- 匿名用户（举报工单里隐藏举报者） ---------- */
.anon-user { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.anon-avatar {
    display: inline-block; width: 20px; height: 20px;
    border-radius: 50%; background: #1f2937;   /* 纯黑圆 */
    flex: 0 0 auto;
}

/* ============================================================
   工具类
   ============================================================ */
.mono { font-family: ui-monospace, Consolas, monospace; }
.req  { color: var(--red); margin-left: 3px; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }

/* ============================================================
   步骤条（提交工单）
   ============================================================ */
.step-bar {
    display: flex; gap: 8px; margin-bottom: 18px;
    background: var(--white); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 14px 16px;
}
.step-item { display: flex; align-items: center; gap: 10px; flex: 1; opacity: .45; }
.step-item.done, .step-item.active { opacity: 1; }
.step-num {
    width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    background: var(--line); color: var(--muted); font-size: 13px; font-weight: 700;
}
.step-item.active .step-num { background: var(--main); color: #fff; }
.step-item.done .step-num { background: var(--green); color: #fff; }
.step-title { font-size: 13px; font-weight: 600; }
.step-desc  { font-size: 12px; color: var(--muted); }

/* ============================================================
   工单类型选择卡片
   ============================================================ */
.type-grid {
    display: grid; gap: 10px; margin-bottom: 16px;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.type-card {
    position: relative; display: block; padding: 12px 14px;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--white); color: var(--text); text-decoration: none;
    transition: border-color .15s, background .15s;
}
.type-card:hover { border-color: var(--main); text-decoration: none; }
.type-card.on { border-color: var(--main); background: #f5f8ff; }
.type-card.on::after {
    content: "✓"; position: absolute; top: 8px; right: 10px;
    color: var(--main); font-weight: 700;
}
.type-card-name  { font-weight: 600; font-size: 14px; margin-bottom: 3px; }
.type-card-group { font-size: 12px; color: var(--muted); }
.type-card-tag {
    position: absolute; top: 8px; right: 26px;
    font-size: 10px; color: var(--muted); background: #f3f4f6;
    padding: 1px 5px; border-radius: 3px;
}
.type-desc {
    padding: 12px 14px; background: #f9fafb;
    border-radius: var(--radius); font-size: 13px; line-height: 1.7;
}
.type-desc p { margin: 6px 0 0; color: var(--muted); }

/* ============================================================
   标签选择器（user_picker / ticket_ref）
   ============================================================ */
.picker-wrap { position: relative; }
.picker-status { font-size: 12px; color: var(--muted); }

.pick-results { margin-top: 8px; }
.pick-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    text-align: left; padding: 8px 12px; margin-bottom: 6px;
    background: var(--white); border: 1px solid var(--line);
    border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 13px;
}
.pick-item:hover { border-color: var(--main); background: #f5f8ff; }

.ref-preview {
    padding: 12px 14px; background: #f9fafb;
    border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
}
.ref-body {
    margin-top: 8px; color: var(--muted); font-size: 12px;
    line-height: 1.7; white-space: pre-wrap;
}

/* ============================================================
   复选框组
   ============================================================ */
.check-group { display: flex; flex-wrap: wrap; gap: 10px 18px; padding: 6px 0; }
.check-item  { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 400; }
.check-item input { width: auto; }

/* ============================================================
   表单动作区
   ============================================================ */
.form-actions { margin: 20px 0 40px; }
.reply-actions {
    display: flex; gap: 10px; justify-content: flex-end;
    margin-top: 14px;
}

/* ============================================================
   工单详情：双栏布局
   ============================================================ */
.ticket-layout {
    display: grid; gap: 16px;
    grid-template-columns: 280px minmax(0, 1fr);
    align-items: start;
}
.ticket-side .card { margin-bottom: 14px; }
.ticket-main .card { margin-bottom: 14px; }

/* ---------- 左栏信息行 ---------- */
.info-row {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 12px; padding: 7px 0;
    border-bottom: 1px dashed var(--line); font-size: 13px;
}
.info-row:last-child { border-bottom: none; }
.info-row .k { color: var(--muted); flex: 0 0 auto; }
.info-row .v { text-align: right; word-break: break-word; }

/* ---------- 管理操作按钮 ---------- */
.staff-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 字段展示（工单描述里的自定义字段） ---------- */
.field-display { margin-bottom: 14px; }
.field-display-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field-display-value { font-size: 13px; }

/* ---------- 关联工单 ---------- */
.related-item {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px;
}
.related-item:last-child { border-bottom: none; }
.related-label { color: var(--muted); font-size: 12px; flex: 0 0 auto; }

/* ============================================================
   消息（对话）
   ============================================================ */
.msg { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.msg:last-child { border-bottom: none; }
.msg.agent    { background: #f8faff; }
.msg.internal { background: #fffbeb; border-left: 3px solid var(--orange); }

.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.msg-head .name { font-weight: 600; font-size: 13px; }
.msg-head .time { color: var(--muted); font-size: 12px; margin-left: auto; }
.msg-tag {
    font-size: 11px; padding: 1px 6px; border-radius: 4px;
    background: #e0e7ff; color: #3730a3;
}
.msg-tag.warn { background: #fef3c7; color: #92400e; }

/* ============================================================
   Markdown 渲染
   ============================================================ */
.md-content { font-size: 14px; line-height: 1.8; word-break: break-word; }
.md-content > *:first-child { margin-top: 0; }
.md-content > *:last-child  { margin-bottom: 0; }

.md-content .md-h1 { font-size: 20px; margin: 18px 0 10px; }
.md-content .md-h2 { font-size: 17px; margin: 16px 0 8px; }
.md-content .md-h3 { font-size: 15px; margin: 14px 0 8px; }
.md-content .md-h4,
.md-content .md-h5,
.md-content .md-h6 { font-size: 14px; margin: 12px 0 6px; color: var(--muted); }

.md-content .md-p { margin: 10px 0; }
.md-content .md-link { color: var(--main); }
.md-content .md-hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

.md-content .md-inline-code {
    background: #f3f4f6; padding: 1px 5px; border-radius: 3px;
    font-family: ui-monospace, Consolas, monospace; font-size: 13px;
}

.md-content .md-list { margin: 10px 0; padding-left: 24px; }
.md-content .md-list li { margin: 4px 0; }
.md-content .md-task { list-style: none; margin-left: -20px; }
.md-content .md-task.is-done { color: var(--muted); text-decoration: line-through; }

.md-content .md-quote {
    margin: 12px 0; padding: 8px 14px;
    border-left: 3px solid var(--line);
    background: #f9fafb; color: #4b5563;
}
.md-content .md-epigraph { font-style: italic; }
.md-content .md-epigraph footer { margin-top: 6px; font-size: 12px; color: var(--muted); text-align: right; }

.md-content .md-img { max-width: 100%; border-radius: 6px; margin: 8px 0; }

.md-align-center { text-align: center; }
.md-align-right  { text-align: right; }

/* ---------- 代码块 ---------- */
.md-content .md-code {
    margin: 14px 0; border: 1px solid var(--line);
    border-radius: var(--radius); overflow: hidden; background: #fafbfc;
}
.md-content .md-code-head {
    padding: 5px 12px; background: #f3f4f6;
    border-bottom: 1px solid var(--line);
    font-size: 12px; color: var(--muted);
}
.md-content .md-code-body {
    margin: 0; padding: 12px; overflow-x: auto;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 13px; line-height: 1.7;
}
.md-content .md-code-body code { background: none; padding: 0; }
.md-content .md-line { display: block; }
.md-content .md-ln {
    display: inline-block; width: 2.4em; margin-right: 10px;
    color: #9ca3af; text-align: right; user-select: none;
}
.md-content .md-code-body .hl {
    display: block; background: #fef9c3;
}

/* ---------- 表格 ---------- */
.md-content .md-table-wrap { overflow-x: auto; margin: 14px 0; }
.md-content .md-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md-content .md-table th,
.md-content .md-table td {
    border: 1px solid var(--line); padding: 7px 10px;
}
.md-content .md-table th { background: #f9fafb; font-weight: 600; }

/* ---------- 折叠框 ---------- */
.md-content .md-fold {
    margin: 14px 0; border: 1px solid var(--line);
    border-radius: var(--radius); overflow: hidden;
}
.md-content .md-fold-head {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 14px; cursor: pointer; font-size: 13px; font-weight: 600;
    background: #f9fafb; user-select: none;
}
.md-content .md-fold-arrow { margin-left: auto; transition: transform .15s; }
.md-content .md-fold.is-open .md-fold-arrow { transform: rotate(180deg); }
.md-content .md-fold-body { display: none; padding: 12px 14px; font-size: 13px; }
.md-content .md-fold.is-open .md-fold-body { display: block; }

.md-content .md-fold-info    { border-color: #bfdbfe; }
.md-content .md-fold-info    .md-fold-head { background: #eff6ff; color: #1e40af; }
.md-content .md-fold-success { border-color: #bbf7d0; }
.md-content .md-fold-success .md-fold-head { background: #f0fdf4; color: #166534; }
.md-content .md-fold-warning { border-color: #fde68a; }
.md-content .md-fold-warning .md-fold-head { background: #fffbeb; color: #92400e; }
.md-content .md-fold-error   { border-color: #fecaca; }
.md-content .md-fold-error   .md-fold-head { background: #fef2f2; color: #991b1b; }

/* ---------- LaTeX 公式（未接 KaTeX 时的占位） ---------- */
.md-content .md-math,
.md-content .md-math-block {
    font-family: ui-monospace, Consolas, monospace;
    background: #f9fafb; padding: 1px 5px; border-radius: 3px; font-size: 13px;
}
.md-content .md-math-block { display: block; padding: 10px; margin: 10px 0; text-align: center; }

/* 编辑器高度：CSS 只管声明，md-editor.js 会读它并写成内联样式 */
:root { --md-height: 420px; }

/* ============================================================
   Markdown 编辑器
   ============================================================
   尺寸由 md-editor.js 用内联样式控制（高度取自上面的 --md-height）。
   为什么不让 CSS 直接管高度——编辑器依赖「height:100% + position:absolute」，
   父容器一旦拿不到高度就塌陷成 0（只看得到工具栏、看不到输入框）。
   写在内联样式里，CSS 没加载/加载失败/被缓存都不影响。
*/
.md-wrap {
    /* 兜底：万一脚本没设上，至少不是 0 高 */
    min-height: 200px;
}
.md-inner .mp-editor-container {
    height: 100%;
    border: none;           /* 外框由 .md-wrap 提供，避免双边框 */
}
.md-tip {
    padding: 7px 12px;
    background: #fafbfc;
    border-top: 1px solid var(--line);
    font-size: 11px;
    color: var(--muted);
    line-height: 1.8;
}
.md-tip code {
    background: #f3f4f6; padding: 1px 5px; border-radius: 3px;
    font-family: ui-monospace, Consolas, monospace;
}
.md-fallback-warn {
    padding: 8px 12px; margin-top: 6px; font-size: 12px;
    background: #fffbeb; border: 1px solid #fde68a;
    border-radius: 6px; color: #92400e;
}

/* ============================================================
   管理操作弹窗
   ============================================================ */
.modal-mask {
    display: none; position: fixed; inset: 0; z-index: 100;
    background: rgba(17, 24, 39, .45);
    align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.show { display: flex; }

.modal-box {
    background: var(--white); border-radius: 10px;
    width: 100%; max-width: 460px; padding: 20px 22px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
    max-height: 88vh; overflow-y: auto;
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close {
    border: none; background: none; cursor: pointer;
    font-size: 22px; line-height: 1; color: var(--muted); padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

/* ============================================================
   附件
   ============================================================ */
.atts { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.att {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; background: #f3f4f6; border-radius: 6px;
    font-size: 12px; color: var(--text);
}
.att:hover { background: #e5e7eb; text-decoration: none; }
.att .size { color: var(--muted); }

/* ============================================================
   审计日志
   ============================================================ */
.logs { font-size: 12px; color: var(--muted); max-height: 280px; overflow-y: auto; }
.logs div { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.logs code { background: #f3f4f6; padding: 1px 5px; border-radius: 3px; }

/* ============================================================
   工单列表：标签页 / 搜索 / 筛选
   ============================================================ */
.tab-bar {
    display: flex; gap: 4px; margin-bottom: 14px;
    border-bottom: 1px solid var(--line);
}
.tab-item {
    padding: 9px 16px; font-size: 14px; color: var(--muted);
    text-decoration: none; border-bottom: 2px solid transparent;
    margin-bottom: -1px; white-space: nowrap;
}
.tab-item:hover { color: var(--text); text-decoration: none; }
.tab-item.on { color: var(--main); border-bottom-color: var(--main); font-weight: 600; }
.tab-num {
    display: inline-block; margin-left: 6px; padding: 0 6px;
    background: #f3f4f6; border-radius: 9px;
    font-size: 11px; color: var(--muted); line-height: 17px;
}
.tab-item.on .tab-num { background: #dbeafe; color: var(--main); }

.search-bar {
    display: flex; gap: 8px; align-items: center;
    flex-wrap: wrap; margin-bottom: 14px;
}

/* ============================================================
   登录页
   ============================================================ */
.login-page {
    max-width: 420px; margin: 48px auto 60px;
}
.login-card {
    background: var(--white); border: 1px solid var(--line);
    border-radius: 12px; padding: 32px 28px;
    box-shadow: 0 4px 20px rgba(17, 24, 39, .05);
}
.login-head { text-align: center; margin-bottom: 26px; }
.login-head h1 { font-size: 22px; margin: 0 0 6px; }
.login-head .sub { color: var(--muted); font-size: 13px; margin: 0; }

.login-section { margin: 0; }
.login-form .field { margin-bottom: 14px; }
.login-form input { padding: 10px 12px; }
.btn-block { display: block; width: 100%; text-align: center; padding: 11px; }

/* QQ 登录按钮（主推，所以做得醒目） */
.btn-qq {
    position: relative;
    display: flex; align-items: center; justify-content: center; gap: 9px;
    width: 100%; padding: 12px;
    background: #12b7f5; border: 1px solid #12b7f5; border-radius: 6px;
    color: #fff; font-size: 15px; font-weight: 600; text-decoration: none;
}
.btn-qq:hover { background: #0ea5dd; border-color: #0ea5dd; text-decoration: none; }
.qq-icon { display: inline-flex; }
.qq-badge {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    background: rgba(255, 255, 255, .26); color: #fff;
    font-size: 11px; font-weight: 400;
    padding: 2px 7px; border-radius: 9px;
}

/* 「或」分隔线 */
.login-divider {
    display: flex; align-items: center; gap: 12px;
    margin: 22px 0; color: var(--muted); font-size: 12px;
}
.login-divider::before,
.login-divider::after {
    content: ""; flex: 1; height: 1px; background: var(--line);
}

.login-hint {
    color: var(--muted); font-size: 12px; line-height: 1.7;
    margin: 10px 0 0; text-align: center;
}

@media (max-width: 640px) {
    .login-page { margin: 20px auto 40px; }
    .login-card { padding: 24px 18px; }
    .qq-badge { display: none; }
}

/* ============================================================
   主页（只要两个入口）
   ============================================================ */
.home-page { max-width: 720px; margin: 0 auto; padding: 40px 0 60px; }

.home-head { text-align: center; margin-bottom: 36px; }
.home-head h1 { font-size: 28px; margin: 0 0 8px; }
.home-head .sub { color: var(--muted); font-size: 14px; margin: 0; }

.home-entries {
    display: grid; gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.entry-card {
    display: block; padding: 28px 24px; text-align: center;
    background: var(--white); border: 1px solid var(--line);
    border-radius: 12px; color: var(--text); text-decoration: none;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.entry-card:hover {
    border-color: var(--main); text-decoration: none;
    box-shadow: 0 6px 22px rgba(37, 99, 235, .1);
    transform: translateY(-2px);
}
.entry-icon { font-size: 34px; line-height: 1; margin-bottom: 12px; }
.entry-name { font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.entry-desc { font-size: 13px; color: var(--muted); }

.home-login {
    margin-top: 32px; text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}

/* ============================================================
   公告列表
   ============================================================ */
.discuss-list { display: block; }

.discuss-row {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.discuss-row:last-child { border-bottom: none; }
.discuss-row:hover { background: #fafbfc; }
.discuss-row.pinned { background: #fffbf5; }
.discuss-row.pinned:hover { background: #fff7ec; }

.discuss-main { flex: 1; min-width: 0; }
.discuss-title-line {
    display: flex; align-items: center; gap: 7px;
    flex-wrap: wrap; margin-bottom: 5px;
}
.discuss-title {
    font-size: 15px; font-weight: 600; color: var(--text);
    text-decoration: none; word-break: break-word;
}
.discuss-title:hover { color: var(--main); text-decoration: none; }

.discuss-meta {
    font-size: 12px; color: var(--muted);
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.discuss-meta .dot { color: var(--line); }

.discuss-count {
    flex: 0 0 auto; min-width: 52px; text-align: center;
    padding: 6px 10px; background: #f9fafb; border-radius: 8px;
}
.discuss-count .num { font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.2; }
.discuss-count .lbl { font-size: 11px; color: var(--muted); }

@media (max-width: 640px) {
    .home-page { padding: 24px 0 40px; }
    .home-head h1 { font-size: 22px; }
    .entry-card { padding: 22px 18px; }
    .entry-icon { font-size: 28px; }
    .discuss-row { padding: 12px; gap: 10px; }
    .discuss-title { font-size: 14px; }
    .discuss-count { min-width: 44px; padding: 5px 8px; }
}

/* ============================================================
   手机适配
   ============================================================ */
@media (max-width: 820px) {
    .ticket-layout { grid-template-columns: 1fr; }
    .ticket-side { order: 2; }
    .ticket-main { order: 1; }
    .step-bar { flex-direction: column; gap: 10px; }
    .type-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .info-row { flex-direction: column; gap: 2px; }
    .info-row .v { text-align: left; }
    .modal-box { padding: 16px; }

    /* 标签页在手机上横向滚动，不换行挤压 */
    .tab-bar { overflow-x: auto; }
    .tab-item { padding: 8px 12px; font-size: 13px; }

    /* 手机上编辑器矮一点，别把屏幕占满（脚本会读这个变量） */
    :root { --md-height: 320px; }
}
