/* ---------- 基础 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: #e3e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-h: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 10px;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 0 20px; height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 22px; color: var(--primary); }
.brand h1 { font-size: 18px; font-weight: 600; }
.save-state { font-size: 12px; color: var(--muted); min-width: 60px; text-align: center; }
.save-state.saving::before { content: "⏳ 保存中…"; }
.save-state.saved::before { content: "✓ 已保存"; color: var(--ok); }
.save-state.conflict::before { content: "⚠ 有冲突"; color: var(--danger); }
.save-state.error::before { content: "✗ 保存失败"; color: var(--danger); }

/* ---------- 布局 ---------- */
.layout { display: flex; height: calc(100vh - 56px); }
.sidebar {
  width: 260px; min-width: 260px; background: var(--panel);
  border-right: 1px solid var(--border); overflow-y: auto; padding: 12px 10px;
}
.sidebar-head { font-size: 12px; color: var(--muted); padding: 4px 8px 10px; }
.table-list { list-style: none; }
.table-list li {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
}
.table-list li:hover { background: #f0f4ff; }
.table-list li.active { background: #e6efff; border-left: 3px solid var(--primary); }
.table-list .t-name { font-weight: 600; }
.table-list .t-meta { font-size: 12px; color: var(--muted); }

.workspace { flex: 1; overflow: auto; padding: 24px 28px; }

/* ---------- 空状态 ---------- */
.empty { text-align: center; margin-top: 12vh; color: var(--muted); }
.empty .empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty p { margin-bottom: 18px; }

/* ---------- 视图工具栏 ---------- */
.view-toolbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 16px; flex-wrap: wrap;
}
.view-toolbar h2 { font-size: 20px; margin-bottom: 4px; }
.meta { font-size: 12px; color: var(--muted); }
.desc { font-size: 13px; color: var(--muted); margin-top: 4px; }
.toolbar-right { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 7px 14px; border-radius: 8px; font-size: 13px;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-h); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }

/* ---------- 表格网格 ---------- */
.grid-wrap { overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); max-height: 66vh; }
.grid { border-collapse: collapse; width: 100%; min-width: 480px; }
.grid th, .grid td {
  border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top;
}
.grid thead th { background: #f8fafc; font-weight: 600; position: sticky; top: 0; z-index: 1; }
.grid thead th .colname { outline: none; min-width: 60px; }
.grid thead th .colname:focus { border-bottom: 2px solid var(--primary); }
.coltype { font-size: 11px; color: var(--muted); margin-left: 6px; font-weight: 400; }
.badge { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 6px; margin-left: 6px; font-weight: 500; vertical-align: middle; }
.badge.admin { color: #b45309; background: #fef3c7; }
.badge.pub { color: #2563eb; background: #e0edff; }
.grid .rownum { width: 56px; color: var(--muted); text-align: center; position: relative; }
.grid .cell { min-width: 120px; outline: none; }
.grid .cell:focus { background: #eef4ff; box-shadow: inset 0 0 0 2px var(--primary); }
.grid select { border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; background: #fff; min-width: 120px; }
.grid .addcol { width: 48px; text-align: center; }
.grid .addcol button { border: none; background: transparent; font-size: 18px; color: var(--muted); }
.grid .addcol button:hover { color: var(--primary); }
.delcol, .delrow {
  border: none; background: transparent; color: #cbd5e1; font-size: 15px; line-height: 1;
}
.delcol { position: absolute; top: 4px; right: 6px; }
.delcol:hover, .delrow:hover { color: var(--danger); }
.rownum { position: relative; }
.delrow { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }

.grid-actions { margin-top: 14px; display: flex; gap: 8px; }

/* ---------- 登记表单 ---------- */
.form-card { max-width: 560px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.form-field { margin-bottom: 16px; }
.form-field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.form-field .req { color: var(--danger); }
.form-field input[type="text"], .form-field input[type="date"], .form-field input[type="number"], .form-field select, .form-field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.form-field textarea { min-height: 80px; resize: vertical; }
.form-field .cb { display: flex; align-items: center; gap: 6px; font-weight: 400; }
#regForm .btn { margin-top: 6px; }
.form-msg { margin-top: 14px; font-size: 13px; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--danger); }

/* ---------- 附件 ---------- */
.att-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.att-item { display: inline-flex; align-items: center; gap: 6px; background: #f1f5f9; border-radius: 6px; padding: 3px 8px; font-size: 12px; width: fit-content; max-width: 100%; }
.att-item a { color: var(--primary); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-item a:hover { text-decoration: underline; }
.att-empty { color: var(--muted); font-size: 12px; }
.att-add { display: inline-block; cursor: pointer; color: var(--primary); font-size: 12px; padding: 4px 10px; border: 1px dashed var(--primary); border-radius: 6px; }
.att-add:hover { background: #eef4ff; }
.att-del { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 13px; line-height: 1; }
.grid .att { min-width: 200px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box { background: #fff; border-radius: 12px; width: 420px; max-width: 92vw; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-close { border: none; background: none; font-size: 20px; color: var(--muted); }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

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