/* ============================================================
   合同一键生成 · 填报面板样式
   专业稳重 · 国企蓝（延续 prototype/css/style.css 视觉语言）
   ============================================================ */

:root {
  --brand: #1a4d8f;
  --brand-600: #163f75;
  --brand-700: #10305b;
  --brand-50: #eef3fa;
  --brand-100: #dbe6f5;
  --accent: #c99a3a;
  --ok: #2e7d54;
  --ok-50: #e8f5ee;
  --warn: #c1553b;
  --warn-50: #fbeee9;
  --pending: #b0762a;
  --ink: #1e2530;
  --ink-2: #4b5563;
  --ink-3: #8791a0;
  --line: #e3e8ef;
  --line-2: #eef1f6;
  --bg: #f4f6fa;
  --panel: #ffffff;
  --readonly: #f6f8fb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16,48,91,.05), 0 8px 24px rgba(16,48,91,.06);
  --shadow-sm: 0 1px 2px rgba(16,48,91,.06);
  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", -apple-system, "Segoe UI", sans-serif;
  --serif: "Songti SC", "SimSun", "STSong", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
button { font-family: var(--font); }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 56px;
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-600) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(16,48,91,.15);
}
.topbar .logo {
  width: 30px; height: 30px; border-radius: 7px;
  background: rgba(255,255,255,.16);
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px; letter-spacing: -1px;
  border: 1px solid rgba(255,255,255,.25);
}
.topbar .brandname { font-size: 15.5px; font-weight: 600; letter-spacing: .3px; }
.topbar .sub { font-size: 12px; color: rgba(255,255,255,.7); margin-left: -6px; }
.topbar .spacer { flex: 1; }
.topbar .rolepill {
  font-size: 12.5px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  padding: 5px 12px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 6px;
}
.topbar .rolepill .dot { width: 7px; height: 7px; border-radius: 50%; background: #7fe0a5; }
.topbar .navlink { color: rgba(255,255,255,.85); font-size: 13px; }
.topbar .navlink:hover { color: #fff; text-decoration: none; }

/* ---------- 布局容器 ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px; }

/* 页头 */
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; gap: 16px; flex-wrap: wrap; }
.pagehead h1 { font-size: 20px; }
.pagehead .desc { color: var(--ink-2); font-size: 13px; margin-top: 4px; }

/* ---------- AI 智能填充条 ---------- */
.ai-bar {
  background: linear-gradient(135deg, var(--brand-50), #fff 70%);
  border: 1px solid var(--brand-100);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.ai-bar .ai-h { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.ai-bar .ai-h .icon {
  width: 24px; height: 24px; border-radius: 6px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.ai-bar .ai-h h3 { font-size: 14.5px; color: var(--brand-700); }
.ai-bar .ai-h .hint { font-size: 12px; color: var(--ink-3); margin-left: 4px; }
.ai-bar .ai-row { display: flex; gap: 10px; align-items: flex-start; }
.ai-bar textarea {
  flex: 1; min-height: 64px; resize: vertical;
  font-family: var(--font); font-size: 13.5px; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; outline: none; background: #fff;
}
.ai-bar textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.ai-bar .ai-match {
  margin-top: 10px; font-size: 12.5px; color: var(--brand-700);
  background: #fff; border: 1px dashed var(--brand-100); border-radius: var(--radius-sm);
  padding: 8px 12px; display: none;
}
.ai-bar .ai-match.show { display: block; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-h {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; gap: 10px;
}
.card-h h3 { font-size: 15px; }
.card-h .tag { margin-left: auto; }
.card-b { padding: 18px; }
.mb16 { margin-bottom: 16px; }

/* section 分组标题 */
.grouphead {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--brand);
  padding: 10px 0 12px; margin-top: 6px;
  border-bottom: 1px dashed var(--line);
}
.grouphead .bar { width: 3px; height: 14px; background: var(--brand); border-radius: 2px; }

/* ---------- 表单 · 类 Excel ---------- */
.formgrid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0; }
.formgrid.cols2 { grid-template-columns: 1fr 1fr; }
.formgrid.one { grid-template-columns: 1fr; }
.field {
  display: flex; flex-direction: column; gap: 5px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-2);
  border-right: 1px solid var(--line-2);
}
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; color: var(--ink-2); font-weight: 500; display: flex; gap: 6px; align-items: center; }
.field label .req { color: var(--warn); }
.field .auto-tag {
  font-size: 10.5px; color: var(--brand); background: var(--brand-50);
  border: 1px solid var(--brand-100); padding: 1px 6px; border-radius: 4px;
}
.field input, .field select, .field textarea {
  font-family: var(--font);
  font-size: 13.5px; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 10px; background: #fff; outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50);
}
.field textarea { resize: vertical; min-height: 64px; }
.field .val { font-size: 13.5px; color: var(--ink); padding: 8px 10px; min-height: 17px; }
.field.readonly { background: var(--readonly); }
.field.readonly input, .field.readonly .val {
  background: var(--readonly); color: var(--ink-2); border-color: var(--line-2);
}
.field .hint { font-size: 11.5px; color: var(--ink-3); }
.field .unit { font-size: 12px; color: var(--ink-3); }

/* 条款区（AI 起草） */
.clause-block { padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
.clause-block:last-child { border-bottom: none; }
.clause-block .ct { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.clause-block .ct label { font-size: 13px; font-weight: 600; color: var(--ink); }
.clause-block .ct .spacer { flex: 1; }
.clause-block .points {
  font-size: 12.5px; padding: 6px 9px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  width: 260px; outline: none;
}
.clause-block .points:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.clause-block textarea {
  width: 100%; min-height: 78px; resize: vertical;
  font-family: var(--font); font-size: 13.5px; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 11px; outline: none;
}
.clause-block textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }

/* ---------- 动态表格（排期 / 付款） ---------- */
.dyn-table { width: 100%; border-collapse: collapse; }
.dyn-table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2);
  background: var(--readonly); padding: 9px 12px; border-bottom: 1px solid var(--line);
}
.dyn-table td { padding: 8px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.dyn-table input {
  font-family: var(--font); font-size: 13.5px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 7px 9px; width: 100%; outline: none;
}
.dyn-table input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.dyn-table .idx { color: var(--ink-3); font-size: 13px; width: 36px; text-align: center; }
.dyn-table .op { width: 56px; text-align: center; }
.dyn-table .row-del {
  border: none; background: none; color: var(--warn); cursor: pointer; font-size: 13px;
}
.dyn-table .row-del:hover { text-decoration: underline; }
.dyn-table-wrap { padding: 4px 16px 12px; }
.dyn-table-foot { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 16px; }

.sum-badge { font-size: 13px; font-weight: 600; padding: 4px 12px; border-radius: 999px; }
.sum-badge.ok { background: var(--ok-50); color: var(--ok); }
.sum-badge.warn { background: var(--warn-50); color: var(--warn); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: var(--font); font-size: 13.5px; font-weight: 500;
  padding: 9px 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  cursor: pointer; transition: all .15s; text-decoration: none;
}
.btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.btn-lg { padding: 12px 26px; font-size: 15px; }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- 徽章/标签 ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 500;
  background: var(--line-2); color: var(--ink-2);
}
.tag .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag-brand { background: var(--brand-50); color: var(--brand); }
.tag-ok { background: var(--ok-50); color: var(--ok); }
.tag-warn { background: var(--warn-50); color: var(--warn); }

/* ---------- 错误提示区 ---------- */
.errors-box {
  display: none;
  background: var(--warn-50); border: 1px solid #f0c9bd; border-radius: var(--radius-sm);
  padding: 12px 16px; margin-bottom: 16px; color: var(--warn); font-size: 13px;
}
.errors-box.show { display: block; }
.errors-box ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed; right: 24px; bottom: 24px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--ink); color: #fff; font-size: 13px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow); opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.warn { background: var(--warn); }
.toast.ok { background: var(--ok); }

.muted { color: var(--ink-3); }
.flex { display: flex; }
.gap8 { gap: 8px; }
.gap12 { gap: 12px; }
.between { justify-content: space-between; }
.center { align-items: center; }

/* ============================================================
   合同预览页 · A4 正文排版 + AI 审查侧栏
   ============================================================ */

.preview-layout {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 22px;
  align-items: start;
}
@media (max-width: 980px) {
  .preview-layout { grid-template-columns: 1fr; }
}

/* A4 纸张容器 */
.contract-paper {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
  max-width: 794px;
  margin: 0 auto;
  padding: 64px 68px 80px;
  font-family: var(--serif);
  color: var(--ink);
}
.contract-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 8px;
}
.contract-subno {
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-3);
  margin-bottom: 32px;
  font-family: var(--font);
}
.contract-section { margin: 26px 0; }
.contract-section h3 {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--brand-700);
  border-left: 4px solid var(--brand);
  padding-left: 10px;
  margin-bottom: 14px;
}
.contract-section h4 {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--brand);
  margin: 0 0 8px;
  font-family: var(--font);
}
.contract-kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; }
.contract-kv-grid.one-col { grid-template-columns: 1fr; }
.kv-row { display: flex; gap: 6px; font-size: 14px; line-height: 1.9; }
.kv-row .k { color: var(--ink-2); white-space: nowrap; }
.kv-row .v { color: var(--ink); word-break: break-all; }
.party-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.party-block .kv-row { flex-direction: column; gap: 0; }
.contract-para { font-size: 14px; line-height: 1.9; margin: 6px 0; }
.clause-text { white-space: pre-wrap; font-size: 14px; line-height: 1.9; margin: 0; }

/* 高亮：来自面板勾稽 / 后端计算得出的字段 */
.contract-paper mark {
  background: var(--brand-100);
  color: var(--brand-700);
  border-radius: 3px;
  padding: 0 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* 合同表格 */
.contract-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13.5px; font-family: var(--font); }
.contract-table th, .contract-table td {
  border: 1px solid var(--line); padding: 8px 10px; text-align: left;
}
.contract-table th { background: var(--readonly); font-weight: 600; color: var(--ink-2); }

/* 签署区 */
.sign-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 22px; }
.sign-col .sign-line { margin: 30px 0 8px; border-bottom: 1px solid var(--ink-3); width: 100%; height: 1px; }
.sign-meta { margin-top: 20px; font-size: 13.5px; color: var(--ink-2); }

.contract-error {
  text-align: center; color: var(--warn); font-size: 14px; padding: 60px 0;
  font-family: var(--font);
}

/* ---------- AI 审查侧栏 ---------- */
.review-panel {
  position: sticky;
  top: 72px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.review-panel .rp-head {
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--brand-50), #fff 70%);
  border-bottom: 1px solid var(--brand-100);
  display: flex; align-items: center; gap: 8px;
}
.review-panel .rp-head .icon {
  width: 22px; height: 22px; border-radius: 6px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-size: 11.5px; font-weight: 700;
}
.review-panel .rp-head h3 { font-size: 14px; color: var(--brand-700); }
.review-panel .rp-body {
  padding: 14px 16px; max-height: calc(100vh - 160px); overflow-y: auto;
  font-size: 13px; color: var(--ink-2);
}
.risk-item { border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 10px; }
.risk-item:last-child { margin-bottom: 0; }
.risk-item .risk-level {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700;
  padding: 2px 9px; border-radius: 999px; margin-bottom: 6px;
}
.risk-level.high { background: var(--warn-50); color: var(--warn); }
.risk-level.mid { background: #fdf1e0; color: var(--pending); }
.risk-level.low { background: var(--ok-50); color: var(--ok); }
.risk-item .risk-pos { font-size: 12.5px; color: var(--ink-3); margin-bottom: 4px; }
.risk-item .risk-issue { font-size: 13px; color: var(--ink); margin-bottom: 4px; }
.risk-item .risk-suggest { font-size: 12.5px; color: var(--ink-2); }
.risk-item .risk-suggest b { color: var(--brand-700); font-weight: 600; }
.review-empty, .review-loading, .review-error {
  font-size: 13px; color: var(--ink-3); text-align: center; padding: 20px 6px;
}
.review-error { color: var(--warn); }

/* ============================================================
   对话主导录入 chat.html
   ============================================================ */
.chat-layout {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* ---------- 左栏：对话 ---------- */
.chat-col {
  flex: 1 1 62%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  border-right: 1px solid var(--line);
}
.chat-head {
  height: 56px;
  flex: 0 0 auto;
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-600) 100%);
  color: #fff;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 24px;
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(16,48,91,.15);
}
.chat-head .hint {
  font-size: 12.5px;
  font-weight: 400;
  color: rgba(255,255,255,.75);
}
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}
.msg.user {
  align-self: flex-end;
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 3px;
}
.chat-input {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 24px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.chat-input textarea {
  flex: 1 1 auto;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  resize: vertical;
  min-height: 40px;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-50);
}
.chat-input button {
  flex: 0 0 auto;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.chat-input button:hover { background: var(--brand-600); }
.chat-input button:disabled { background: var(--ink-3); cursor: not-allowed; }

/* ---------- 右栏：可改摘要 ---------- */
.summary-col {
  flex: 1 1 38%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  overflow-y: auto;
  background: var(--panel);
}
.sum-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sum-row label {
  flex: 0 0 44px;
  font-size: 12.5px;
  color: var(--ink-2);
  font-weight: 500;
}
.sum-row select {
  flex: 1 1 auto;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.sum-row select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-50);
}
.summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--readonly);
}
.sum-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sum-field label {
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 500;
}
.sum-field input {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.sum-field input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-50);
}
.sum-field .ro {
  font-size: 13px;
  color: var(--ink-2);
  padding: 7px 0;
}
.missing {
  font-size: 12.5px;
  color: var(--pending);
  padding: 2px 2px;
  min-height: 17px;
}
#btn-generate {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
#btn-generate:hover:not(:disabled) { background: var(--brand-600); }
#btn-generate:disabled {
  background: var(--line-2);
  color: var(--ink-3);
  cursor: not-allowed;
}
.advlink {
  align-self: center;
  font-size: 12px;
  color: var(--ink-3);
}
.advlink:hover { color: var(--brand); }
