:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #dfe4ee;
  --primary: #0f9f8f;
  --primary-strong: #087e73;
  --blue: #2878d7;
  --amber: #d98a12;
  --red: #d94b4b;
  --green: #2f9e63;
  --shadow: 0 10px 30px rgba(23, 32, 51, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

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

.sidebar {
  background: #f0f3f8;
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 18px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f2ad2e;
  color: white;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

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

.nav {
  display: grid;
  gap: 14px;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-group-title {
  padding: 4px 10px;
  color: var(--primary-strong);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0;
}

.nav-group.active .nav-group-title {
  color: var(--primary-strong);
}

.nav-group-items {
  display: grid;
  gap: 4px;
}

.nav button {
  width: 100%;
  border: 0;
  background: transparent;
  color: #263349;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}

.nav button:hover,
.nav button.active {
  background: #ffffff;
  box-shadow: inset 3px 0 0 var(--primary);
}

.nav .nav-icon {
  width: 22px;
  text-align: center;
  color: var(--primary);
}

.nav .nav-group-title {
  width: 100%;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 10px 12px;
  color: var(--primary-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0;
}

.nav .nav-group-title:hover {
  background: rgba(255, 255, 255, 0.7);
  box-shadow: none;
}

.nav-group.active .nav-group-title {
  color: var(--primary-strong);
}

.nav-group-arrow {
  color: currentColor;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font-size: 20px;
  line-height: 1;
  font-weight: 900;
  transition: transform 0.16s ease;
}

.nav-group.collapsed .nav-group-arrow {
  transform: rotate(-90deg);
}

.nav-group.collapsed .nav-group-items {
  display: none;
}

.workspace {
  min-width: 0;
}

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

.topbar h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.select-label,
.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

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

input[type="date"],
input[type="month"] {
  cursor: pointer;
  min-height: 42px;
}

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

.content {
  padding: 22px 24px 36px;
}

.site-footer {
  padding: 0 24px 24px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.site-footer a {
  color: var(--primary-strong);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.grid {
  display: grid;
  gap: 14px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

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

.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card.pad {
  padding: 18px;
}

.stat {
  padding: 18px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
}

.stat em {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 {
  margin: 0;
  font-size: 17px;
}

.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.danger-button {
  border: 0;
  border-radius: 7px;
  padding: 10px 13px;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

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

.primary-button:hover {
  background: var(--primary-strong);
}

.ghost-button {
  background: #eef3f7;
  color: #263349;
}

.danger-button {
  background: #ffe8e8;
  color: #a83232;
}

.icon-button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.mobile-menu {
  display: none;
}

.mobile-menu span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  margin: 2px 0;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 850px;
}

th,
td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 14px;
}

th {
  background: #f3f6fa;
  color: #48546a;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  background: #edf2f7;
  color: #405066;
}

.tag.green {
  background: #e4f6ed;
  color: var(--green);
}

.tag.red {
  background: #ffe9e9;
  color: var(--red);
}

.tag.amber {
  background: #fff4df;
  color: var(--amber);
}

.tag.blue {
  background: #e8f1fc;
  color: var(--blue);
}

.permission-editor {
  display: grid;
  gap: 12px;
}

.permission-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.permission-role {
  display: grid;
  gap: 7px;
  align-content: start;
}

.permission-role span {
  color: var(--muted);
  font-size: 12px;
}

.permission-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
  user-select: none;
}

.checkbox-pill input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--primary);
}

.permission-actions {
  display: flex;
  justify-content: flex-end;
}

.basic-data-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 12px;
}

.settings-card {
  margin-bottom: 14px;
}

.settings-section {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.module-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
  padding: 2px 2px 0;
}

.module-heading h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.module-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.basic-data-list {
  display: grid;
  gap: 8px;
}

.basic-data-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.basic-data-row strong {
  overflow-wrap: anywhere;
}

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

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

.flow-list {
  display: grid;
  gap: 10px;
}

.flow-item {
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.flow-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--primary);
  margin-top: 6px;
}

.flow-item strong {
  display: block;
}

.flow-item span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 150px 170px auto;
  gap: 8px;
  margin-bottom: 14px;
}

.cell-note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.funnel-list {
  display: grid;
  gap: 11px;
}

.funnel-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) 32px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.funnel-row > div {
  height: 9px;
  overflow: hidden;
  border-radius: 6px;
  background: #e8edf3;
}

.funnel-row i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.profile-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.profile-summary > div,
.detail-grid > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.profile-summary span,
.detail-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.record-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.record-block h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.record-block p {
  margin: 6px 0;
  line-height: 1.7;
}

.timeline {
  display: grid;
  gap: 0;
}

.timeline-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 10px;
  padding-bottom: 16px;
}

.timeline-item i {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--primary);
}

.timeline-item p {
  margin: 5px 0;
}

.timeline-item span {
  color: var(--muted);
  font-size: 12px;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 120px));
  gap: 8px;
  margin-top: 9px;
}

.attachment-grid img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow: auto;
}

.tabs button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 9px 12px;
  cursor: pointer;
  white-space: nowrap;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  background: #172033;
  color: #fff;
  padding: 11px 14px;
  border-radius: 8px;
  pointer-events: none;
  transition: 180ms ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

.import-tip {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.template-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfe;
}

.template-box pre {
  margin: 0 0 12px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: #263349;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 13px;
  line-height: 1.7;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal {
  width: min(1080px, 100%);
  max-height: min(88vh, 900px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(23, 32, 51, 0.28);
  overflow: hidden;
}

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

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

.modal-body {
  overflow: auto;
  padding: 18px;
}

.modal input,
.modal textarea {
  user-select: text;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: #f7f9fc;
}

.line-editor {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfe;
}

.line-editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.line-list {
  display: grid;
  gap: 10px;
}

.line-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 140px auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.line-product select {
  width: 100%;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
}

.compact-table table {
  min-width: 760px;
}

.compact-table input {
  width: 100%;
}

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

  .sidebar {
    position: fixed;
    z-index: 10;
    transform: translateX(-102%);
    transition: 180ms ease;
    width: 256px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: grid;
  }

  .topbar {
    align-items: flex-start;
  }

  .stats-grid,
  .two-col,
  .three-col,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .line-row {
    grid-template-columns: 1fr;
  }

  .permission-row {
    grid-template-columns: 1fr;
  }

  .basic-data-entry,
  .basic-data-row,
  .filter-bar,
  .profile-summary,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    max-height: 94vh;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 14px;
    flex-wrap: wrap;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .content {
    padding: 14px;
  }

  .topbar-actions {
    width: 100%;
  }

  .select-label,
  .topbar-actions select,
  .topbar-actions button {
    width: 100%;
  }

  .stat strong {
    font-size: 25px;
  }

  .modal-backdrop {
    padding: 8px;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions button {
    width: 100%;
  }
}

[hidden] {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef7f1, #f8fbf9 48%, #e5f1ea);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(24, 75, 50, 0.14);
}

.login-card .brand-mark {
  width: 58px;
  height: 58px;
}

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

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

.form-error {
  min-height: 20px;
  color: #b42318 !important;
}

.user-session {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
