:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #e5e9f2;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  color: #fff; font-weight: 700; display: grid; place-items: center; letter-spacing: .5px;
}
.topbar h1 { margin: 0; font-size: 17px; }
.topbar p { margin: 0; font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 6px; }
.tab {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 8px;
  font-size: 14px; color: var(--muted); cursor: pointer;
}
.tab:hover { background: #eef2ff; color: var(--primary); }
.tab.active { background: #eef2ff; color: var(--primary); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-box { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.user-box input {
  width: 110px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}

.container { max-width: 1560px; margin: 0 auto; padding: 20px 24px 60px; }
.view.hidden, .hidden { display: none; }
/* 放在文件末尾的强规则：确保 .hidden 不会被 .modal{display:grid} 覆盖 */
.hidden { display: none !important; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 16px;
}
.section-title { margin: 0 0 12px; font-size: 14px; color: #374151; }
.muted { color: var(--muted); font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* 按钮与表单控件 */
.btn {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: 13px; color: var(--text);
}
.btn:hover { border-color: #c7d2fe; color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); color: #fff; }
.btn.ghost { background: #fff; }
/* 新建项目：高亮，一眼能看到 */
.btn.highlight {
  background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600;
  box-shadow: 0 2px 8px rgba(22, 163, 74, .28);
}
.btn.highlight:hover { background: #15803d; border-color: #15803d; color: #fff; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.link { border: 0; background: none; color: var(--primary); padding: 0; }

input, select, textarea {
  font-family: inherit; font-size: 13px; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.search { flex: 1; min-width: 320px; padding: 9px 12px; }
.filters { margin-top: 10px; gap: 8px; }
.filters select { min-width: 130px; }
.check { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); margin-left: auto; }

/* 表格 */
.table-wrap { overflow: auto; padding: 0; }
.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
.grid th, .grid td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid thead th {
  position: sticky; top: 0; z-index: 2; background: #f8fafc; font-size: 12.5px; color: #475569;
  white-space: nowrap; cursor: pointer; user-select: none;
}
.grid tbody tr:hover { background: #f8fafc; }
.grid td.link { color: var(--primary); cursor: pointer; font-weight: 600; }
.grid td.nowrap { white-space: nowrap; }
/* 主要芯片：按 + 拆行显示，每个型号一行，型号本身不折行 */
.grid td.chip-col { white-space: nowrap; line-height: 1.55; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.badge.完成 { background: #dcfce7; color: #15803d; }
.badge.进行中 { background: #dbeafe; color: #1d4ed8; }
.badge.暂停 { background: #fef3c7; color: #b45309; }
.badge.取消 { background: #f1f5f9; color: #64748b; }
.cell-text { max-width: 260px; }
/* 功能描述列：默认 300px，列宽可拖动调整（双击分隔线复位） */
.grid td.desc { max-width: none; min-width: 200px; }
/* 拖动列宽的手柄 */
.grid th .resizer {
  position: absolute; top: 0; right: 0; width: 7px; height: 100%;
  cursor: col-resize; user-select: none; z-index: 3;
}
.grid th .resizer:hover { background: rgba(37, 99, 235, .22); }
.grid th .resizer.active { background: rgba(37, 99, 235, .45); }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.flash { animation: flash 1.2s ease; }
@keyframes flash { from { background: #fef9c3; } to { background: transparent; } }

.pager { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 6px 0 20px; }

/* 详情 */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.detail-head h2 { margin: 0; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field.col-2 { grid-column: span 2; }
.field textarea { resize: vertical; min-height: 48px; }
.field-state { font-size: 11px; color: var(--muted); min-height: 14px; }
.field-state.ok { color: var(--ok); }
.field-state.err { color: var(--danger); }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.issue-grid textarea { width: 100%; min-height: 56px; }

/* 登录 / 注册 */
.auth {
  position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eef2ff, #f8fafc);
}
.auth-card {
  background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 28px;
  width: min(400px, 92vw); display: flex; flex-direction: column; gap: 12px;
}
.auth-card input { width: 100%; padding: 10px; box-sizing: border-box; }
.auth-switch { text-align: center; margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.user-chip { font-weight: 600; font-size: 13px; color: var(--primary); }
.perm-tip { font-size: 12.5px; }
.editable-input[readonly] { background: #f1f5f9; color: #475569; cursor: default; }
.editable-input[readonly]:focus { outline: none; box-shadow: none; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.ok-mark { background: #dcfce7; color: #166534; }
/* 工具借还状态 */
.badge.已借出, .badge.借出 { background: #dbeafe; color: #1d4ed8; }
.badge.在库 { background: #f1f5f9; color: #475569; }
.badge.待审批 { background: #fef3c7; color: #92400e; }
.badge.内部使用 { background: #ede9fe; color: #5b21b6; }
/* 新建工具弹窗：两列布局 */
.tool-new-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; }
.tool-new-grid .field { margin: 0; }
.tool-new-grid input, .tool-new-grid select { width: 100%; }
/* 备注固定在右列第 4 行起、纵向占 3 行；左列依次是保管人 / 客户 / 录入日期 */
.tool-new-grid .remark-field { grid-column: 2; grid-row: 4 / span 3; display: flex; flex-direction: column; }
.tool-new-grid .remark-field textarea {
  flex: 1; width: 100%; min-height: 150px; resize: vertical;
}
.badge.丢失 { background: #fee2e2; color: #b91c1c; }
.badge.报废 { background: #e5e7eb; color: #374151; }
/* 工具台账：行内直接编辑 */
.tool-item-table { font-size: 13px; }
.tool-item-table th, .tool-item-table td { padding: 6px 8px; white-space: nowrap; }
.tool-item-table input, .tool-item-table select {
  border: 1px solid transparent; background: transparent;
  padding: 3px 5px; border-radius: 4px; font: inherit; max-width: 100%;
}
.tool-item-table input:hover, .tool-item-table select:hover { border-color: var(--line); }
.tool-item-table input:focus, .tool-item-table select:focus {
  border-color: var(--primary); background: #fff; outline: none;
}
.tool-item-table input[type="date"] { width: 130px; }
.tool-item-table select { min-width: 92px; }
/* 备注（历史）：多行文本，最多显示 3 行，悬停看全文 */
/* 注意：pre-wrap 只加在只读文本上，加在 td 上会把模板换行渲染成空行、把输入框顶下去 */
.tool-item-table td.remark-col { max-width: 240px; vertical-align: top; }
.tool-item-table .remark-text {
  white-space: pre-wrap; font-size: 12px; line-height: 1.5; color: #475569;
}
.tool-item-table textarea {
  display: block;                                /* 块级显示，顶部与单元格内容平齐 */
  width: 100%; min-height: 40px; resize: vertical; font: inherit;
  border: 1px solid var(--line); border-radius: 4px; padding: 3px 5px; background: #fff;
}
.tool-item-table textarea:focus { border-color: var(--primary); outline: none; }
/* 操作列固定在右侧，横向滚动时始终可见 */
.ops-col { position: sticky; right: 0; background: #fff; box-shadow: -6px 0 8px -6px rgba(15, 23, 42, .18); }
th.ops-col { background: #f8fafc; }
.badge.已归还 { background: #dcfce7; color: #15803d; }
.badge.已退回 { background: #f1f5f9; color: #64748b; }
/* 样品申请 */
.badge.已寄出 { background: #dcfce7; color: #15803d; }
.badge.待送样 { background: #fef3c7; color: #b45309; }
.badge.已通过 { background: #dcfce7; color: #15803d; }
.badge.已驳回 { background: #fee2e2; color: #b91c1c; }
.sample-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 16px; }
.sample-grid .field { margin: 0; }
.sample-grid input, .sample-grid select { width: 100%; }
.sample-item-table td { padding: 4px 6px; }
.sample-item-table select, .sample-item-table input { width: 100%; }
.sample-kv { display: grid; grid-template-columns: 120px 1fr 120px 1fr; gap: 6px 12px; font-size: 13px; }
.sample-kv dt { color: var(--muted); }
.sample-kv dd { margin: 0; }
.small { font-size: 12px; }
.issue-table td { padding: 4px 8px; border-bottom: 1px dashed var(--line); }
.issue-table textarea { width: 100%; min-height: 42px; resize: vertical; }
.issue-table td.act { width: 70px; }
.editable textarea { width: 100%; }
.saving { border-color: var(--warn); }

/* 附件 */
.dropzone {
  border: 1.5px dashed #cbd5e1; border-radius: 10px; padding: 18px; text-align: center;
  color: var(--muted); cursor: pointer; background: #fbfcfe; transition: all .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
.dropzone.compact { padding: 10px; font-size: 12.5px; }
.attach-list { list-style: none; margin: 10px 0 0; padding: 0; }
.attach-list li {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px;
  border-bottom: 1px dashed var(--line); font-size: 13px; flex-wrap: wrap;
}
.attach-list li a { color: var(--primary); text-decoration: none; font-weight: 500; word-break: break-all; }
.attach-list li a:hover { text-decoration: underline; }
.attach-list li .muted { font-size: 12px; }
.attach-list li button { margin-left: auto; }
.issue-attach { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.issue-attach .attach-list li { padding: 3px 0; border-bottom: 0; font-size: 12px; gap: 6px; }
.issue-attach .attach-list li button { margin-left: 0; }

/* 日志 */
.log-list { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.log-list li { padding: 8px 4px; border-bottom: 1px dashed var(--line); font-size: 13px; }
.log-list .meta { color: var(--muted); font-size: 12px; margin-right: 8px; }

/* 弹窗与提示 */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 40; }
.modal-card {
  background: #fff; border-radius: 12px; padding: 20px; width: min(760px, 92vw);
  max-height: 88vh; overflow: auto; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 14px; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  padding: 10px 14px; border-radius: 8px; background: #111827; color: #fff; font-size: 13px;
  box-shadow: var(--shadow); animation: slide .2s ease; max-width: 380px;
}
.toast.ok { background: #15803d; }
.toast.err { background: #b91c1c; }
.toast.warn { background: #b45309; }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 统计页：条形图（纯 CSS，不依赖外部图表库） */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 13px; }
.bar-name {
  width: 84px; flex: none; text-align: right; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar-track {
  flex: 1; height: 18px; background: #f1f5f9; border-radius: 6px;
  overflow: hidden; cursor: pointer; position: relative;
}
.bar-fill {
  height: 100%; border-radius: 6px; min-width: 2px;
  background: linear-gradient(90deg, #60a5fa, var(--primary));
  transition: width .35s ease;
}
.bar-row.orange .bar-fill { background: linear-gradient(90deg, #fdba74, #ea580c); }
.bar-row.green .bar-fill { background: linear-gradient(90deg, #6ee7b7, #16a34a); }
.bar-row.purple .bar-fill { background: linear-gradient(90deg, #c4b5fd, #7c3aed); }
.bar-track:hover { box-shadow: inset 0 0 0 1px var(--primary); }
.bar-val { width: 42px; flex: none; font-weight: 600; color: var(--text); }
.bar-empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.stat-kpis { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 4px; }
.stat-kpi b { font-size: 20px; color: var(--primary); }
