:root {
  --primary: #1f4e79;
  --primary-dark: #16385c;
  --bg: #f4f6f9;
  --line: #d9dee5;
  --input-bg: #ffffff;
  --computed-bg: #eef4fb;
  --manual-bg: #fff8e6;
  --override-bg: #e8f7ee;
  --error-bg: #fdecea;
  --error-line: #d93025;
  --head-bg: #1f4e79;
  --head-text: #ffffff;
  --group-bg: #375e86;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: #222;
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; line-height: 1; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 600; }
.brand .sub { margin: 2px 0 0; font-size: 12px; opacity: .8; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  background: #fff;
  color: #1f2937;
  transition: filter .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(.94); }
.btn.primary { background: #ffffff; color: var(--primary-dark); font-weight: 600; }
.btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); }
.btn.danger-ghost { background: transparent; color: #ffd9d6; border-color: rgba(255,160,150,.6); }
.btn.danger { background: #fdecea; color: #b3261e; border-color: #f5c6c2; }
.btn.small { padding: 4px 10px; font-size: 12px; background: #fff; color: #1f2937; border-color: var(--line); }
.btn.small.danger { background: #fdecea; color: #b3261e; border-color: #f5c6c2; }
.btn.small.ghost { background: #fff; color: #555; border-color: var(--line); }

/* 页签 */
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 14px 0;
  background: var(--bg);
  border-bottom: 2px solid var(--line);
}
.tab {
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  padding: 9px 18px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  color: #4b5563;
}
.tab:hover { background: #e8edf4; }
.tab.active {
  background: #fff;
  border-color: var(--line);
  color: var(--primary-dark);
  font-weight: 600;
  box-shadow: 0 -2px 6px rgba(0,0,0,.04);
}
.badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  background: #e2e8f0;
  color: #334155;
  font-size: 11px;
  text-align: center;
}

/* 存储模式提示条 */
.notice {
  margin: 8px 14px 0;
  padding: 8px 14px;
  border-radius: 6px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  font-size: 13px;
  line-height: 1.6;
}
.notice.hidden { display: none; }

/* GitHub 同步状态提示条 */
.sync-status {
  margin: 8px 14px 0;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid;
}
.sync-status.ok { background: #ecfdf5; border-color: #6ee7b7; color: #065f46; }
.sync-status.err { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.sync-status.syncing { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.sync-status.hidden { display: none; }

.tab-panel { display: none; flex: 1; min-height: 0; padding: 12px 14px; }
.tab-panel.active { display: flex; flex-direction: column; }

/* 工具栏 */
.grid-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 10px;
  flex-wrap: wrap;
}
.grid-toolbar .left, .grid-toolbar .right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.legend { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: #475569; }
.dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; border: 1px solid rgba(0,0,0,.15); }
.dot.input { background: var(--input-bg); }
.dot.computed { background: var(--computed-bg); }
.dot.manual { background: var(--manual-bg); }
.dot.override { background: var(--override-bg); }
.dot.error { background: var(--error-bg); border-color: var(--error-line); }
.status { font-size: 12px; color: #475569; }
.status.err { color: #b3261e; font-weight: 600; }
.search { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; width: 260px; font-size: 13px; }

/* 网格 */
.grid-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  position: relative;
}
table.grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  width: max-content;
  min-width: 100%;
}
.grid th, .grid td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
}
.grid thead th {
  position: sticky;
  z-index: 5;
  font-size: 11.5px;
  color: var(--head-text);
  background: var(--head-bg);
  text-align: center;
  line-height: 1.3;
  padding: 4px 2px;
}
.grid thead tr.group-row th { background: var(--group-bg); font-weight: 600; font-size: 12px; }
.grid thead th.corner { background: var(--primary-dark); }
.grid thead th.field { top: 30px; }
.grid tbody td { height: 30px; background: var(--input-bg); }
.grid tbody td.computed { background: var(--computed-bg); }
.grid tbody td.manual { background: var(--manual-bg); }
.grid tbody td.override { background: var(--override-bg); }
.grid tbody td.error { background: var(--error-bg); box-shadow: inset 0 0 0 1.5px var(--error-line); }
.grid tbody td.rowno {
  background: #eef1f5;
  color: #64748b;
  text-align: center;
  cursor: pointer;
  font-size: 11px;
  user-select: none;
  width: 40px;
}
.grid tbody tr.selected td.rowno { background: var(--primary); color: #fff; font-weight: 700; }
.grid tbody tr.selected td { background-color: #f3f7ff; }
.grid tbody tr.selected td.computed { background-color: #e3eefb; }
.grid tbody td.sel {
  background: #dbeafe !important;
  box-shadow: inset 0 0 0 1.5px var(--primary);
}
.grid.hazard tbody tr.selected td { background: #dbeafe !important; }
.grid.hazard tbody tr.selected td.rowno {
  background: var(--primary) !important;
  color: #fff;
  font-weight: 700;
}
.grid tbody td.cur {
  position: relative;
  z-index: 2;
  box-shadow: inset 0 0 0 2px var(--primary);
}

.grid input, .grid select {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  padding: 2px 6px;
  font-size: 12px;
  font-family: inherit;
  color: inherit;
}
.grid select {
  -webkit-appearance: none;
  appearance: none; /* 去掉原生箭头，改用右侧独立的自定义箭头，避免压住文字 */
  padding-right: 22px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2364748b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 5px center;
  background-size: 10px 6px;
}
.grid input:focus, .grid select:focus { background: #fff; box-shadow: inset 0 0 0 1.5px var(--primary); }
.grid input[readonly], .grid select[disabled] { cursor: default; }
.grid td.readonly { cursor: default; }
.cell-num { text-align: right; }
.cell-num input { text-align: right; }

/* 危害因素表 */
.hazard-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}
table.grid.hazard thead th { top: 0; }
table.grid.hazard td { height: 26px; }

/* 检测项目列表 */
.items-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  column-count: 4;
  column-gap: 18px;
}
.items-list .item {
  break-inside: avoid;
  padding: 2px 4px;
  border-bottom: 1px dashed #e5e7eb;
  font-size: 12px;
  cursor: pointer;
  border-radius: 3px;
}
.items-list .item.selected {
  background: #dbeafe;
  box-shadow: inset 0 0 0 1.5px var(--primary);
}
.items-list .item.dup { color: #b3261e; font-weight: 600; }
.lib-ok { color: #067647 !important; }

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }

/* 全屏模式：浮动操作条 */
.fs-bar {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  justify-content: flex-start;
  align-items: center;
  max-width: calc(100vw - 16px);
  padding: 6px 10px;
  background: rgba(15, 23, 42, .9);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  backdrop-filter: blur(4px);
}
.fs-bar.hidden { display: none; }
.fs-bar .btn {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 12px;
  padding: 4px 10px;
  color: #f1f5f9;
  border-color: rgba(255, 255, 255, .35);
  background: transparent;
}
.fs-bar .btn:hover { background: rgba(255, 255, 255, .12); }
.fs-bar .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.fs-bar .btn.danger-ghost { color: #fecaca; border-color: rgba(254, 202, 202, .4); }

body.fullscreen-mode {
  height: 100vh;
  overflow: hidden;
}
body.fullscreen-mode .topbar,
body.fullscreen-mode nav.tabs,
body.fullscreen-mode .notice,
body.fullscreen-mode .sync-status {
  display: none !important;
}
body.fullscreen-mode .tab-panel.active {
  height: 100vh;
  padding: 66px 12px 12px;
}

.modal-box {
  background: #fff;
  border-radius: 10px;
  max-width: 780px;
  width: 92%;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal-box.modal-sm { max-width: 440px; }
.modal-box.modal-lg { max-width: 720px; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 17px; color: var(--primary-dark); }
.modal-body { padding: 8px 22px 20px; overflow: auto; }
.modal-body h3 { color: var(--primary-dark); margin: 14px 0 6px; font-size: 14px; }
.modal-body p, .modal-body li { line-height: 1.7; font-size: 13px; }
.modal-body ol, .modal-body ul { margin: 4px 0 0; padding-left: 22px; }
.modal-body .tip { color: #92400e; background: #fef3c7; border-radius: 6px; padding: 8px 12px; }
.prompt-hint { color: #475569; margin: 4px 0 8px; }
.prompt-input { width: 100% !important; box-sizing: border-box; margin-bottom: 4px; }
.err-msg { color: #b3261e; font-size: 12px; min-height: 16px; margin: 2px 0 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.field-label { display: block; font-size: 12px; color: #475569; margin: 8px 0 4px; }
.token-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #475569;
  margin: 8px 0 2px;
  cursor: pointer;
}
.gh-saved { font-size: 12px; margin: 2px 0 4px; line-height: 1.6; }
.gh-saved.ok { color: #065f46; }
.gh-saved.warn { color: #92400e; }

/* 数据记录 */
.db-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.db-toolbar .search { flex: 1; min-width: 220px; width: auto; }
.db-list { max-height: 48vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.db-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid #eef1f5;
}
.db-item:last-child { border-bottom: none; }
.db-item:hover { background: #f6f9fd; }
.db-item-main { min-width: 0; flex: 1; }
.db-item-name { font-size: 14px; font-weight: 600; color: #1f2937; }
.db-item-meta { font-size: 12px; color: #64748b; margin-top: 2px; }
.db-item-preview {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.db-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.db-empty { padding: 24px; text-align: center; color: #94a3b8; }

@media (max-width: 900px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .items-list { column-count: 2; }
}
