/* ============================
   全局 / 基础变量
   ============================ */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1f2328;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbeafe;
  --highlight-empty: #fef08a; /* 占位符未填：高亮黄 */
  --highlight-filled: #bbf7d0; /* 已填写：绿色 */
  --highlight-filled-border: #16a34a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --radius-sm: 4px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ============================
   顶部导航栏
   ============================ */
.navbar {
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 10;
}

.navbar-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.logo {
  font-size: 16px;
  font-weight: 600;
}

.subtitle {
  color: var(--text-muted);
  font-size: 13px;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.current-template {
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

/* ============================
   按钮
   ============================ */
.btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover {
  background: var(--bg);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
}

/* ============================
   主区域（左右分栏）
   ============================ */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 400px;
  overflow: hidden;
}

/* 左面板 */
.left-panel {
  background: var(--bg);
  overflow-y: auto;
  padding: 24px;
  border-right: 1px solid var(--border);
}

/* 模板网格 */
.grid-header {
  margin-bottom: 20px;
}

.grid-header h2 {
  margin: 0 0 4px 0;
  font-size: 20px;
}

.hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.template-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.template-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 140px;
}

.template-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.template-card .card-icon {
  font-size: 32px;
}

.template-card .card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.template-card .card-desc {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}

.template-card .card-fields {
  font-size: 12px;
  color: var(--primary);
  margin-top: 4px;
}

.loading {
  color: var(--text-muted);
  padding: 20px;
}

/* 文档预览 */
.doc-preview {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 860px;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  position: sticky;
  top: 0;
  z-index: 1;
}

.preview-label {
  font-weight: 600;
  font-size: 13px;
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.dot-empty {
  background: var(--highlight-empty);
}

.dot-filled {
  background: var(--highlight-filled);
}

/* docx 渲染出来的内容区域 */
.doc-content {
  padding: 40px 60px;
  min-height: 500px;
  font-size: 14px;
  line-height: 1.8;
  color: #111;
  word-wrap: break-word;
}

/* 占位符高亮 span（由 JS 注入） */
.doc-content .field-placeholder {
  background: var(--highlight-empty);
  border: 1px dashed #ca8a04;
  border-radius: 3px;
  padding: 1px 4px;
  transition: background 0.15s, border-color 0.15s;
  cursor: default;
}

.doc-content .field-placeholder.is-active {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  background: #fde68a;
}

.doc-content .field-placeholder.is-filled {
  background: var(--highlight-filled);
  border-color: var(--highlight-filled-border);
  border-style: solid;
  color: #14532d;
  font-weight: 500;
}

/* docx 内表格样式微调 */
.doc-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}

.doc-content table td,
.doc-content table th {
  border: 1px solid #d1d5db;
  padding: 6px 10px;
}

.doc-content h1, .doc-content h2, .doc-content h3 {
  margin-top: 1.2em;
  margin-bottom: 0.5em;
}

/* ============================
   右面板
   ============================ */
.right-panel {
  background: var(--panel);
  overflow-y: auto;
  padding: 24px;
}

.form-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.6;
}

.form-header {
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.form-header h2 {
  margin: 0 0 4px 0;
  font-size: 16px;
}

.form-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-row label .field-name {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 400;
}

.field-row label .required {
  color: #dc2626;
}

.field-row input[type="text"],
.field-row textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--panel);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: vertical;
}

.field-row textarea {
  min-height: 72px;
}

.field-row input[type="text"]:focus,
.field-row textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field-row.is-active label {
  color: var(--primary);
}

/* ============================
   响应式（小屏）
   ============================ */
@media (max-width: 960px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .right-panel {
    border-top: 1px solid var(--border);
    border-right: none;
    max-height: 50vh;
  }
}
