:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --line: #e5e7eb;
  --danger: #b91c1c;
  --ok: #059669;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
.req { color: var(--danger); }

.view { min-height: 100vh; }

/* 登录 */
#loginView {
  display: flex;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(31, 41, 55, 0.08);
}

.login-card {
  width: 340px;
  padding: 30px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h1 { margin: 0; }
.login-card .muted { margin: -8px 0 8px; }

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
}

input, textarea, select {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
}

textarea { resize: vertical; }

button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  background: var(--accent-soft);
  color: var(--accent);
}

button.primary { background: var(--accent); color: #fff; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
button.danger { background: #fef2f2; color: var(--danger); }
button.small { padding: 5px 10px; font-size: 12px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.err { color: var(--danger); font-size: 12px; min-height: 16px; }

/* 主界面 */
header {
  background: var(--card);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

header h1 { margin: 0; font-size: 18px; }
.header-actions { display: flex; gap: 8px; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
}

.stat b { font-size: 16px; margin-left: 4px; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 0 20px 10px;
  flex-wrap: wrap;
}

.tab {
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}

.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

main { padding: 0 20px 30px; }

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar input { flex: 1; }

.split {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 14px;
  align-items: start;
}

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
}

.list { display: flex; flex-direction: column; gap: 8px; }

.order-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
}

.order-row:hover { border-color: var(--accent); }
.order-row.selected { border-color: var(--accent); background: var(--accent-soft); }
.order-row.row-overdue { background: #fef2f2; }

.order-main { flex: 1; min-width: 0; }
.order-main .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-main .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }

.badge {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
  background: var(--accent-soft);
  color: var(--accent);
}

.detail {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 90px);
  overflow: auto;
}

.detail h3 { margin: 0 0 10px; }
.detail .meta { color: var(--muted); font-size: 12px; line-height: 1.7; }
.detail .section { margin-top: 14px; }
.detail .section h4 { margin: 0 0 6px; font-size: 13px; }

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 12px;
}

.file-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.history-item { font-size: 12px; color: var(--muted); padding: 4px 0; border-bottom: 1px dashed var(--line); }
.history-item b { color: var(--ink); }

.status-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* 账号管理 */
.users-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
}

.users-card h3 { margin: 0 0 10px; }

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
}

.user-row .grow { flex: 1; }

.user-row details.user-types {
  font-size: 12px;
  color: var(--muted, #64748b);
  position: relative;
}

.user-row details.user-types summary { cursor: pointer; white-space: nowrap; }

.user-row .user-types-box {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 5;
  background: var(--card, #fff);
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 8px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: auto;
  gap: 4px;
  min-width: 140px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.user-row .user-types-box label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  width: 520px;
  max-width: 100%;
  max-height: 90vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 16px; }

.upload-box {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  background: #fafbfd;
}

.upload-box:hover { border-color: var(--accent); }
.upload-box p { margin: 4px 0; }

.file-list { list-style: none; margin: 10px 0 0; padding: 0; text-align: left; }
.file-list li { font-size: 12px; padding: 3px 0; color: var(--muted); }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 50;
}

/* ---------- 公司协同布局 ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 190px;
  background: #111827;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  flex-shrink: 0;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  padding: 0 8px 18px;
}

.sidebar-user {
  color: #e5e7eb;
  font-size: 13px;
  padding: 0 8px 14px;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 10px;
  word-break: break-all;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 4px;
  background: transparent;
  color: #d1d5db;
  border-radius: 8px;
}

.nav-item:hover { background: #1f2937; color: #fff; }
.nav-item.active { background: #4f46e5; color: #fff; }

.sidebar-sub {
  margin: 2px 0 8px;
  padding-left: 10px;
  border-left: 1px solid #1f2937;
}

.nav-item.sub {
  font-size: 13px;
  padding: 7px 12px;
  color: #9ca3af;
}

.nav-item.sub.active { background: #312e81; color: #fff; }

.nav-badge {
  display: inline-block;
  margin-left: 6px;
  background: #e11d48;
  color: #fff;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 11px;
  line-height: 16px;
}

.sidebar-foot {
  margin-top: auto;
  padding: 10px 8px 0;
  border-top: 1px solid #1f2937;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-foot .ghost { border-color: #374151; color: #d1d5db; }

.content {
  flex: 1;
  min-width: 0;
  padding: 14px 20px 30px;
}

.panel { max-width: 1280px; margin: 0 auto; }

.toolbar.slim { margin-top: 8px; }
.toolbar.slim select { min-width: 140px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.customer-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.customer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.customer-actions { display: flex; gap: 6px; margin-top: 4px; }

.customer-stats {
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 4px 8px;
}

/* 表单栅格 */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-grid .span2 { grid-column: 1 / -1; }

.inline-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

label.check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
}

.milestone-row {
  display: grid;
  grid-template-columns: 1fr 150px 130px 40px;
  gap: 6px;
  margin-bottom: 6px;
}

/* 回执与回复 */
.reply-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.reply-item {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
}

.reply-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.reply-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.kind-badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 7px;
  border-radius: 999px;
}

.reply-composer {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.center { text-align: center; display: block; margin-top: 8px; }
.ok { color: var(--ok); font-size: 12px; min-height: 16px; }

/* 交期提示 */
.due {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.due-overdue { background: #fef2f2; color: #b91c1c; }
.due-today { background: #fff7ed; color: #c2410c; }
.due-soon { background: #fefce8; color: #a16207; }

.storage-warn {
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
}

/* 看板 */
.board-section { margin-bottom: 18px; }
.board-section h3 { font-size: 14px; margin: 0 0 8px; }

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.board-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.board-card:hover { border-color: var(--accent); }
.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.board-head .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.kanban {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.kanban-col {
  min-width: 240px;
  background: #eef1f6;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kanban-col h3 { margin: 0; font-size: 13px; }

.milestones {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.milestone-chip {
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  padding: 1px 6px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: var(--card);
}
.report-table th, .report-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}
.report-table th { background: #f3f4f6; }

.scan-big {
  font-size: 17px;
  padding: 14px 22px;
  margin: 8px 0 14px;
}

.scan-results {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.scan-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scan-card > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.live-scan {
  margin: 6px 0 12px;
}

.scan-camera {
  margin: 8px 0;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

.scan-camera video {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
}

.scan-tips {
  margin: 8px 0 0;
  padding-left: 18px;
  text-align: left;
  color: var(--muted);
  font-size: 12px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-head { text-align: center; font-size: 12px; color: var(--muted); padding: 4px; }
.cal-day {
  min-height: 92px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
  overflow: hidden;
}
.cal-day.today { border-color: var(--accent); }
.cal-item {
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 4px;
  padding: 2px 4px;
  margin-top: 2px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-item.overdue { background: #fef2f2; color: #b91c1c; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; gap: 6px; flex-wrap: wrap; }
  .brand { padding: 0 8px; }
  .sidebar-foot { margin-top: 0; margin-left: auto; border: 0; flex-direction: row; }
}

@media (max-width: 640px) {
  header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input { min-width: 100%; }
  input, textarea, select { font-size: 16px; }
  .modal-card { padding: 14px; width: 100%; }
  .detail { position: static; max-height: none; }
  .kanban-col { min-width: 82vw; }
  .form-grid { grid-template-columns: 1fr; }
  .milestone-row { grid-template-columns: 1fr; }
  .report-table { display: block; overflow-x: auto; white-space: nowrap; }
}
