:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --line: #dfe3e8;
  --line-strong: #cbd3dc;
  --text: #20242a;
  --muted: #68717d;
  --primary: #008f83;
  --primary-dark: #05766d;
  --primary-soft: #e2f3f0;
  --danger: #c94343;
  --warning: #b76516;
  --radius: 8px;
  --shadow: 0 12px 28px rgba(20, 30, 45, 0.08);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-size: 18px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  padding: 10px 15px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

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

button.primary:hover {
  background: var(--primary-dark);
  color: #fff;
}

button.danger {
  border-color: #f0c4c4;
  color: var(--danger);
}

button.ghost {
  border-color: transparent;
  background: transparent;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 11px 13px;
  background: #fff;
  color: var(--text);
  min-width: 0;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

td {
  position: relative;
}

.editing-badge {
  position: absolute;
  right: 6px;
  top: 5px;
  z-index: 2;
  border-radius: 999px;
  background: #fff7d6;
  color: #7a5600;
  border: 1px solid #f1d98a;
  padding: 2px 7px;
  font-size: 12px;
  pointer-events: none;
  max-width: calc(100% - 12px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.being-edited {
  box-shadow: inset 0 0 0 2px #e6c45a;
}

.realtime-flash {
  animation: realtimeFlash 1.4s ease-out;
}

@keyframes realtimeFlash {
  0% { background: #fff2b8; }
  100% { background: transparent; }
}

.app-shell {
  display: grid;
  grid-template-columns: 364px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #eceeef;
  padding: 17px 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 4px;
}

.brand-title {
  font-weight: 700;
  font-size: 21px;
}

.brand-sub {
  color: var(--muted);
  font-size: 15px;
  margin-top: 2px;
}

.online-users {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #19a974;
  box-shadow: 0 0 0 4px rgba(25, 169, 116, 0.12);
  flex: 0 0 auto;
}

.online-names {
  overflow: hidden;
  text-overflow: ellipsis;
}

.online-muted {
  color: var(--muted);
}

.nav-list,
.device-tree {
  display: grid;
  gap: 5px;
}

.tree-row {
  position: relative;
  cursor: grab;
}

.tree-row.dragging {
  opacity: 0.48;
}

.tree-row.drop-before::before,
.tree-row.drop-after::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  height: 2px;
  border-radius: 999px;
  background: var(--primary);
  z-index: 2;
}

.tree-row.drop-before::before {
  top: -3px;
}

.tree-row.drop-after::after {
  bottom: -3px;
}

.nav-item,
.tree-item {
  border: 0;
  width: 100%;
  text-align: left;
  background: transparent;
  border-radius: 7px;
  padding: 11px 13px;
  color: #4d555f;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nav-item.active,
.tree-item.active {
  color: #008074;
  background: #d7ebe8;
  font-weight: 700;
}

.tree-item {
  padding: 11px 12px;
}

.tree-item small {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.tree-filter {
  padding: 0 8px;
}

.tree-filter select {
  padding: 9px 11px;
  font-size: 15px;
}

.tree-empty {
  padding: 12px 8px;
  color: var(--muted);
  font-size: 12px;
}

.tree-list {
  overflow: auto;
  padding-right: 4px;
}

.tree-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  color: var(--muted);
  font-size: 15px;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 76px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.page-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.page-title h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.2;
}

.page-title span {
  color: var(--muted);
  font-size: 17px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.content {
  padding: 22px 26px 56px;
  min-width: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar.compact {
  grid-template-columns: minmax(240px, 1fr) repeat(3, minmax(172px, 0.5fr)) auto;
}

.availability-filters {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 10px;
}

.availability-filters select[name="warehouse"] {
  width: 120px;
}

.availability-filters select[name="model"] {
  width: 240px;
}

.availability-search {
  width: 250px;
  flex: 0 0 250px;
}

.date-inline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: 270px;
  flex: 0 0 270px;
}

.date-inline span {
  color: var(--muted);
  white-space: nowrap;
}

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

.table-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px;
  color: var(--muted);
}

.table-controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.table-controls select {
  width: 122px;
  padding: 7px 9px;
}

.check-label input {
  width: auto;
}

.color-tools {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  margin-left: 4px;
}

.color-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 5px;
  font-size: 12px;
}

.color-btn.cell-red,
.cell-red { background: #ffe3e3 !important; }

.color-btn.cell-yellow,
.cell-yellow { background: #fff2b8 !important; }

.color-btn.cell-green,
.cell-green { background: #dcf7df !important; }

.color-btn.cell-blue,
.cell-blue { background: #dff0ff !important; }

.color-btn.cell-purple,
.cell-purple { background: #efe3ff !important; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: hidden;
  overflow-y: auto;
  max-height: calc(100vh - 150px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.page-bottom-scrollbar {
  position: fixed;
  left: 390px;
  right: 18px;
  bottom: 0;
  z-index: 30;
  height: 18px;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0 0 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
  box-shadow: 0 -8px 18px rgba(20, 30, 45, 0.06);
}

.page-bottom-scrollbar > div {
  height: 1px;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 1680px;
}

.spreadsheet-table {
  min-width: 3300px;
}

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 13px 13px;
  text-align: left;
  vertical-align: middle;
  background: #fff;
  height: 58px;
}

.spreadsheet-table th,
.spreadsheet-table td {
  padding: 6px 6px;
  height: var(--grid-row-height, 48px);
  min-width: var(--grid-cell-width, 120px);
}

.spreadsheet-table td {
  vertical-align: middle;
}

.spreadsheet-table td:has(.grid-editor) {
  padding: 0;
  vertical-align: stretch;
}

.spreadsheet-table th {
  padding: 6px 8px;
  white-space: nowrap;
}

.row-no {
  width: 68px;
  min-width: 68px;
  text-align: center;
  color: var(--muted);
  background: #fbfcfd;
}

.row-no-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: var(--grid-row-height, 48px);
}

.row-open-btn {
  width: 25px;
  height: 25px;
  padding: 0;
  border-radius: 5px;
  color: var(--muted);
  opacity: 0.45;
}

tr:hover .row-open-btn,
.row-open-btn:focus {
  opacity: 1;
}

.wide-col,
.wide-cell {
  min-width: calc(var(--grid-cell-width, 120px) * 1.7) !important;
}

.grid-editor {
  display: block;
  box-sizing: border-box;
  border: 0;
  border-radius: 0;
  background: transparent;
  width: 100%;
  min-width: var(--grid-cell-width, 120px);
  min-height: var(--grid-row-height, 48px);
  height: 100%;
  padding: 8px 10px;
  font: inherit;
}

.wide-cell .grid-editor {
  min-width: calc(var(--grid-cell-width, 120px) * 1.7);
}

.grid-textarea {
  display: block;
  resize: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
  min-height: var(--grid-row-height, 48px);
}

.field-customer_real_name .grid-editor,
.field-customer_nickname .grid-editor,
.field-universal_remark .grid-editor,
.field-location .grid-editor,
.field-address .grid-editor {
  align-content: center;
}

.wrap-on .grid-editor {
  white-space: normal;
}

.spreadsheet-table td[class*="cell-"] .grid-editor {
  background: rgba(255, 255, 255, 0.45);
}

.spreadsheet-table td[class*="cell-"] .grid-editor:focus {
  background: #fff;
}

.cell-selected {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.grid-editor:hover {
  background: transparent;
}

.grid-editor:focus {
  background: transparent;
  outline: none;
  box-shadow: none;
}

.grid-editor.saving {
  background: #fff8dc;
}

.grid-editor.saved {
  background: #e6f6ea;
}

.option-editor {
  font-weight: 700;
}

.option-manager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
}

.option-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
}

.option-section h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.option-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px auto;
  gap: 8px;
  margin-bottom: 10px;
}

.option-list {
  display: grid;
  gap: 6px;
}

.option-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px auto;
  gap: 8px;
  align-items: center;
}

.option-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: #4c5560;
  background: #fbfcfd;
  font-weight: 700;
}

tr.focus-row td {
  background: #fff8dc;
  animation: pulseRow 1.8s ease-out;
}

@keyframes pulseRow {
  0% { background: #ffe999; }
  100% { background: #fff8dc; }
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 6px;
  line-height: 1;
  background: #edf1f5;
  color: #4b5663;
  white-space: nowrap;
}

.pill.primary { background: var(--primary-soft); color: #05766d; }
.pill.green { background: #e0f2e4; color: #28713d; }
.pill.orange { background: #fff0db; color: var(--warning); }
.pill.red { background: #fde6e6; color: var(--danger); }
.pill.blue { background: #e1f1fb; color: #2d6c91; }
.pill.gray { background: #e9edf1; color: #59636e; }

.summary-line {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  color: var(--muted);
}

.gap-box {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.3);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal {
  width: min(920px, 100%);
  max-height: min(760px, 92vh);
  overflow: auto;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.modal.small {
  width: min(520px, 100%);
}

.record-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.16);
  z-index: 30;
}

.record-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(620px, 92vw);
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(20, 30, 45, 0.16);
  z-index: 31;
  display: flex;
  flex-direction: column;
}

.record-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 22px 24px 14px;
  border-bottom: 1px solid var(--line);
}

.record-drawer-head h2 {
  margin: 0;
  font-size: 24px;
}

.record-drawer-head span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.record-tabs {
  display: flex;
  gap: 22px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
}

.record-tabs button {
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 14px 0 12px;
  color: var(--muted);
}

.record-tabs button.active {
  color: var(--primary-dark);
  box-shadow: inset 0 -3px 0 var(--primary);
  font-weight: 700;
}

.record-panel {
  display: none;
  overflow: auto;
  padding: 22px 24px 86px;
}

.record-panel.active {
  display: block;
}

.record-detail-form {
  display: grid;
  gap: 18px;
}

.record-form-field label {
  display: block;
  color: var(--muted);
  margin-bottom: 7px;
  font-weight: 600;
}

.record-form-field textarea {
  min-height: 84px;
}

.record-drawer-foot {
  position: sticky;
  bottom: -86px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 0 0;
  background: linear-gradient(180deg, rgba(255,255,255,0), #fff 18px);
}

.record-activity-list {
  display: grid;
  gap: 12px;
}

.record-activity-item {
  border-bottom: 1px solid var(--line);
  padding: 0 0 14px;
}

.record-activity-meta,
.record-activity-main,
.record-activity-values {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 14px;
  align-items: start;
}

.record-activity-meta {
  color: var(--muted);
  margin-bottom: 8px;
}

.activity-action {
  color: var(--primary-dark);
  font-weight: 700;
}

.activity-field {
  font-weight: 700;
}

.record-activity-values label {
  color: var(--muted);
  font-size: 13px;
}

.record-activity-values p {
  margin: 4px 0 0;
  padding: 7px 9px;
  border-radius: 6px;
  background: var(--panel-soft);
  min-height: 34px;
}

.record-activity-remark {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.modal-head,
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
}

.group-tool {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.group-tool-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.group-tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.group-output {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  overflow: hidden;
}

.group-output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.group-output pre {
  min-height: 180px;
  margin: 0;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font: inherit;
  line-height: 1.7;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-field label {
  display: block;
  color: #4e5864;
  font-size: 12px;
  margin-bottom: 5px;
}

.span-2 {
  grid-column: span 2;
}

.span-3 {
  grid-column: 1 / -1;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #f7f8fa, #eef2f3);
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.login-card p {
  margin: 0 0 18px;
  color: var(--muted);
}

.login-card form {
  display: grid;
  gap: 12px;
}

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

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #1f2937;
  color: #fff;
  padding: 10px 13px;
  border-radius: 7px;
  z-index: 50;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .page-bottom-scrollbar {
    left: 12px;
    right: 12px;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 8;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 44vh;
  }

  .group-tool-grid {
    grid-template-columns: 1fr;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar,
  .toolbar.compact {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar .actions {
    justify-content: flex-start;
  }

  .form-grid,
  .form-grid.two,
  .option-manager {
    grid-template-columns: 1fr;
  }

  .span-2,
  .span-3 {
    grid-column: auto;
  }

  .topbar {
    align-items: flex-start;
    height: auto;
    min-height: 58px;
    padding: 12px;
    gap: 10px;
  }
}

@media (max-width: 620px) {
  .nav-list,
  .toolbar,
  .toolbar.compact {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 12px;
  }

  .page-title {
    flex-direction: column;
    gap: 3px;
  }
}
