/* ===== 基础 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --radius: 10px;
}
body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* ===== 顶栏 ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 10px 18px; position: sticky; top: 0; z-index: 20; flex-wrap: wrap; gap: 8px;
}
.brand { font-size: 18px; font-weight: 700; color: var(--primary); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }

/* ===== 按钮 ===== */
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: all .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-ghost { display: none; }

/* ===== 布局 ===== */
.edit-layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 57px); }

.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 14px; }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sidebar-head h2 { font-size: 15px; }
.template-list { list-style: none; }
.template-list li {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px;
  cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 6px;
}
.template-list li.active { border-color: var(--primary); background: #eff6ff; color: var(--primary-dark); font-weight: 600; }
.template-list .tpl-meta { font-size: 11px; color: var(--muted); font-weight: 400; }
.sidebar-foot { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar-foot label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.sidebar-foot input { width: 70px; }

.editor { padding: 16px; max-width: 980px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 15px; }
.panel-actions { display: flex; gap: 6px; }
.panel-body { padding: 14px 16px; }

.field-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.field-row label { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
input[type=text], input[type=number], select {
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-size: 13px; background: #fff; color: var(--text);
}
input[type=text]:focus, input[type=number]:focus, select:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
input[type=number] { width: 90px; }
input[type=checkbox] { accent-color: var(--primary); width: 15px; height: 15px; }

/* ===== 题型块卡片 ===== */
.block-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; background: #f8fafc; }
.block-head {
  display: flex; justify-content: space-between; align-items: center; padding: 10px 14px;
  background: #fff; border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0;
}
.block-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.block-title .type-badge {
  background: #dbeafe; color: var(--primary-dark); font-size: 11px; padding: 2px 8px; border-radius: 20px;
}
.block-title .count-badge { color: var(--muted); font-weight: 400; }
.block-actions { display: flex; gap: 4px; }
.block-body { padding: 12px 14px; }
.param-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 16px; }
.param-item { display: flex; flex-direction: column; gap: 4px; }
.param-item > label { font-size: 12px; color: var(--muted); }
.param-item .inline { display: flex; align-items: center; gap: 6px; }
.param-item input[type=number] { width: 100%; }
.param-item input[type=number].sm { width: 70px; }
.param-item .inline input[type=number] { width: 70px; }
.check-group { display: flex; flex-wrap: wrap; gap: 10px; }
.check-group label { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.range-inline { display: flex; align-items: center; gap: 6px; }
.range-inline input[type=number] { width: 70px; }
.range-inline span { color: var(--muted); }

.hint-panel { color: var(--muted); }
.hint-panel summary { cursor: pointer; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.hint-panel ul { padding-left: 20px; line-height: 1.9; }

/* ===== 对话框 ===== */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: min(560px, 92vw); max-height: 80vh; overflow: auto; }
.modal h3 { margin-bottom: 14px; }
.modal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.type-option {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; text-align: center;
  transition: all .15s;
}
.type-option:hover { border-color: var(--primary); background: #eff6ff; }
.type-option .t-icon { font-size: 22px; }
.type-option .t-name { font-weight: 600; margin-top: 4px; }
.type-option .t-desc { font-size: 11px; color: var(--muted); margin-top: 2px; }
.modal-actions { margin-top: 14px; text-align: right; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 20px; border-radius: 8px; z-index: 100;
  font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}

/* ===== 预览 / 打印视图 ===== */
.preview-wrap { padding: 20px; }
#previewContent .paper { background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.08); margin: 0 auto 24px; }

/* ===== 打印样式（A4）===== */
@page {
  size: A4;
  margin: 1.4cm 1.4cm 1.8cm 1.4cm;
  @bottom-center { content: " - " counter(page) " - "; font-size: 10pt; color: #666; }
  @bottom-right { content: "eersoft.top"; font-size: 9pt; color: #c5c5c5; }
}
@media print {
  .topbar, .sidebar, .modal-mask, .toast, .btn-ghost { display: none !important; }
  .edit-layout { display: none; }
  #previewView { display: block !important; padding: 0; }
  body { background: #fff; font-size: 12pt; }
  .preview-wrap { padding: 0; }
  .paper {
    page-break-after: always;
    box-shadow: none !important;
    margin: 0 !important;
  }
  .paper:last-child { page-break-after: auto; }
  .paper-content { padding: 0; }
  .paper-footer { display: none; } /* 打印时由 @page @bottom-right 输出网站链接 */
  .answer-page { page-break-before: always; }
  .question-line { break-inside: avoid; }
  .q-item { break-inside: avoid; }
}

/* 打印视图内的排版 */
.paper-content { padding: 26px 32px; }
.paper-title { text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.paper-meta { display: flex; justify-content: space-between; color: #555; font-size: 12px; margin-bottom: 14px; border-bottom: 1px dashed #ccc; padding-bottom: 8px; }
.paper-footer { text-align: right; color: #c5c5c5; font-size: 11px; margin-top: 6px; }
.paper-block-title { font-size: 15px; font-weight: 700; margin: 14px 0 8px; }
.question-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 18px; }
.question-line { font-size: 13px; line-height: 1.9; display: flex; align-items: baseline; gap: 6px; overflow-wrap: break-word; word-break: normal; }
.question-line .q-no { color: #888; min-width: 18px; flex-shrink: 0; }
.question-line > span:nth-child(2) { min-width: 0; }
/* 题目下方空行（竖式计算预留空间等），高度由 JS 按空行数设置 */
.q-item { break-inside: avoid; }
.q-blank-rows { height: 1.8em; }
.question-line .q-no { color: #888; min-width: 18px; }
.question-line .q-blank { display: inline-block; min-width: 72px; height: 1.1em; border-bottom: 1px solid #999; }
.answer-line { font-size: 13px; line-height: 2; }
.answer-line .q-no { color: #888; min-width: 22px; margin-right: 6px; display: inline-block; }
.answer-page h3 { text-align: center; margin-bottom: 10px; }
.answer-paper-title { font-weight: 700; font-size: 14px; margin: 12px 0 6px; border-bottom: 1px solid #ccc; padding-bottom: 3px; }
.frac-inline { display: inline-block; text-align: center; vertical-align: middle; line-height: 1.1; }
.frac-inline .num { display: block; border-bottom: 1px solid currentColor; padding: 0 3px; }
.frac-inline .den { display: block; padding: 0 3px; }

/* 标题后的返回首页链接（淡化，不随试卷打印） */
.topbar .brand .eersoft-home-link {
  font-size: 12px;
  font-weight: 400;
  color: #a8a8a8;
  margin-left: 10px;
  text-decoration: none;
  opacity: 0.75;
  vertical-align: middle;
}
.topbar .brand .eersoft-home-link:hover {
  opacity: 1;
  color: #666;
  text-decoration: underline;
}
