/* 合同智能体 —— 浅色主题 */

:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e3e8ef;
  --line-soft: #eef2f7;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 14px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- 启动遮罩 ---------- */
.boot {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.boot[hidden] { display: none; }
.boot-inner { text-align: center; color: var(--ink-2); }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 14px;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; padding: 14px 28px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--primary), #3b82f6);
  color: #fff; font-size: 19px; font-weight: 700;
}
.brand-text h1 { font-size: 17px; letter-spacing: .2px; }
.brand-text p { margin: 1px 0 0; font-size: 12px; color: var(--ink-3); }

.tabs { display: flex; gap: 4px; background: var(--line-soft); padding: 4px; border-radius: 10px; }
.tab {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 16px; border-radius: 7px;
  font-size: 13.5px; color: var(--ink-2); font-weight: 500;
  transition: .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }

/* ---------- 布局 ---------- */
.shell { max-width: 1360px; margin: 0 auto; padding: 22px 28px 60px; }
.view[hidden] { display: none; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.col-side { position: relative; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card.sticky { position: sticky; top: 86px; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.card-head h2 { font-size: 15px; }
.hint, .mini-note { font-size: 12px; color: var(--ink-3); }
.mini-note { margin: 8px 0 0; }
.req-tag { font-size: 11.5px; color: var(--ink-3); }
.row-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- 表单 ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; color: var(--ink-2); }
.field > span b { color: var(--danger); font-weight: 600; }
.field input, textarea, select {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink);
  font: inherit; font-size: 13.5px;
  outline: none; transition: .15s;
}
.field input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, .1); }
.field input.miss { border-color: #fbbf24; background: #fffbeb; }
textarea { resize: vertical; font-size: 13.5px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 17px; font: inherit; font-size: 13.5px; font-weight: 500;
  cursor: pointer; text-decoration: none; transition: .15s; white-space: nowrap;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn.ghost:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn.link { background: none; border: 0; color: var(--primary); padding: 4px 2px; }
.btn.link:hover { text-decoration: underline; }
.btn.link.danger { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  border: 0; background: none; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--ink-3); padding: 2px 6px;
}
.icon-btn:hover { color: var(--ink); }

.action-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 18px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.miss-box { font-size: 12.5px; color: var(--ink-2); flex: 1; }
.miss-box .ok { color: var(--ok); }
.miss-box .bad { color: var(--warn); }
.miss-box em { font-style: normal; color: var(--danger); font-weight: 600; }

/* ---------- 产品列表 ---------- */
.prod-list { display: flex; flex-direction: column; gap: 8px; }
.prod-item {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) 96px;
  gap: 10px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  transition: .15s; background: #fff;
}
.prod-item:hover { border-color: #cbd5e1; }
.prod-item.on { border-color: var(--primary); background: var(--primary-soft); }
.prod-item input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.prod-item .pi-title { font-size: 13.5px; font-weight: 500; }
.prod-item .pi-desc { font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.prod-item .pi-price { text-align: right; min-width: 0; }
/* width:100% 必须显式写：本输入框不在 .field 内，拿不到全局那条 100% 规则，
   会退回浏览器默认尺寸（size≈20 → 约 188px），而所在网格列只有 96px，
   于是横向越界 91px、直接顶穿卡片右边界。 */
.prod-item .pi-price input { width: 100%; text-align: right; padding: 5px 8px; font-size: 13px; }
.prod-item .pi-price input:disabled { background: var(--line-soft); color: var(--ink-3); }

/* ---------- 预览 ---------- */
.preview {
  max-height: 52vh; overflow: auto;
  padding: 14px 16px; border: 1px solid var(--line-soft);
  border-radius: 8px; background: #fcfdff;
  font-size: 12.5px; line-height: 1.9; color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word;
}
.preview .pv-h { color: var(--ink); font-weight: 600; }
.preview .pv-title { text-align: center; font-size: 15px; font-weight: 700; color: var(--ink); letter-spacing: 1px; }
.preview .pv-empty { color: var(--ink-3); }
.sum-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line);
}
.sum-row strong { font-size: 19px; color: var(--primary); }

/* ---------- 历史 ---------- */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.hist-item {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 15px; border: 1px solid var(--line); border-radius: 8px;
}
.hist-item:hover { border-color: #cbd5e1; background: #fcfdff; }
.hist-main { min-width: 0; }
.hist-main strong { font-size: 14px; display: block; }
.hist-meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.hist-ops { display: flex; gap: 10px; flex-shrink: 0; }
.empty { padding: 34px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12.5px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafbfd;
}
.data-table td { padding: 7px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table input { padding: 6px 9px; font-size: 13px; }

/* ---------- 公章 ---------- */
.seal-row { display: flex; gap: 20px; align-items: flex-start; }
.seal-box {
  width: 130px; height: 130px; flex: 0 0 130px;
  border: 1px dashed var(--line); border-radius: 8px;
  display: grid; place-items: center; background: #fff;
}
.seal-box img { max-width: 100%; max-height: 100%; }
.seal-ctrls { display: flex; flex-direction: column; gap: 9px; align-items: flex-start; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---------- 模板编辑器 ---------- */
#tpl-editor { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.tpl-block { margin-bottom: 12px; }
.tpl-block > label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; }
.tpl-block .tpl-tag {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 4px;
  background: var(--line-soft); color: var(--ink-3); margin-left: 6px;
}

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 120; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .42); }
.modal-panel {
  position: relative; z-index: 1;
  width: min(880px, 92vw); height: min(88vh, 900px);
  display: flex; flex-direction: column;
  background: var(--card); border-radius: 12px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .25);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 15px; }
.modal-body { flex: 1; min-height: 0; overflow: hidden; background: #525659; }
.modal-body iframe { width: 100%; height: 100%; border: 0; display: block; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 18px; border-top: 1px solid var(--line);
}
.modal-foot > div { display: flex; gap: 10px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  z-index: 300; padding: 11px 20px; border-radius: 9px;
  background: #0f172a; color: #fff; font-size: 13.5px;
  box-shadow: 0 8px 26px rgba(15, 23, 42, .3);
}
.toast[hidden] { display: none; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- 账号 / 云端状态 ---------- */
.account { display: flex; align-items: center; gap: 8px; }
.acct-name {
  font-size: 12.5px; color: var(--ink-2);
  max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.acct-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--ink-3); }
.acct-dot.on { background: var(--ok); }
.acct-dot.off { background: var(--warn); }

/* ---------- 登录弹窗 ---------- */

/* ---------- 登录闸门（全屏；未登录或未过审时挡住整个界面） ---------- */

.gate {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow: auto;
  background: linear-gradient(180deg, #f1f5f9 0%, #e2e8f0 100%);
}
.gate[hidden] { display: none; }

/* 闸门打开时把主界面彻底藏掉：避免 Tab 键还能聚焦到底下的表单 */
body.gate-on .topbar,
body.gate-on .shell { visibility: hidden; }

.gate-panel {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 30px 26px;
  box-shadow: 0 18px 40px -18px rgba(15, 23, 42, .28);
  text-align: center;
}
.gate-panel h2 { margin: 12px 0 4px; font-size: 19px; }

.gate-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 13px;
  background: var(--primary); color: #fff; font-size: 21px; font-weight: 600;
}
.gate-mark.warn { background: var(--warn); }

.gate-sub { font-size: 13px; color: var(--ink-2); margin-bottom: 20px; }

.gate-tip {
  font-size: 13px; line-height: 1.7; color: var(--ink-2);
  background: var(--primary-soft); border-radius: 10px;
  padding: 11px 13px; margin: 0 0 18px; text-align: left;
}

.gate-err {
  margin: 14px 0 0; font-size: 13px; line-height: 1.6;
  color: var(--danger); text-align: left;
}
.gate-err[hidden] { display: none; }

.gate-tabs {
  display: flex; gap: 4px; margin-bottom: 16px;
  background: #f1f5f9; border-radius: 10px; padding: 4px;
}
.gate-tab {
  flex: 1; padding: 8px 0; border: 0; border-radius: 8px; cursor: pointer;
  background: none; color: var(--ink-2); font-size: 13.5px; font-weight: 500;
}
.gate-tab.active {
  background: #fff; color: var(--primary);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .1);
}

.gate-pane { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.gate-pane[hidden] { display: none; }
.gate-pane hr { width: 100%; border: 0; border-top: 1px dashed var(--line); margin: 4px 0; }
.gate-pane .row-actions { margin-top: 0; }
.gate-pane .row-actions input {
  flex: 1; padding: 9px 11px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; font-family: inherit;
}
.gate-pane .row-actions input:focus {
  outline: 0; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, .1);
}
.gate-pane .btn.link { align-self: flex-start; }

.btn.block { width: 100%; justify-content: center; }

/* ---------- 顶栏：角色标记 ---------- */
.acct-role {
  padding: 2px 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary);
}
.acct-role[hidden] { display: none; }

/* ---------- 设置页：账号信息 ---------- */
.acct-block {
  display: flex; flex-direction: column; gap: 8px;
  background: #f8fafc; border: 1px solid var(--line-soft);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 4px;
}
.acct-line {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; font-size: 13.5px;
}
.acct-label { color: var(--ink-3); }

/* ---------- 设置页：用户管理 ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge.ok { background: #dcfce7; color: #15803d; }
.badge.bad { background: #fee2e2; color: #b91c1c; }
.badge.wait { background: #fef3c7; color: #b45309; }
.user-acts { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
