:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #dfe5ef;
  --accent: #f97316;
  --accent-dark: #ea580c;
  --accent-soft: #fff3e7;
  --nav: #263063;
  --nav-dark: #202850;
  --nav-text: #eef3ff;
  --nav-muted: #aeb9dc;
  --nav-active: #ffc633;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

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

.erp-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--nav) 0%, var(--nav-dark) 100%);
  color: var(--nav-text);
  padding: 18px 12px;
  box-shadow: 12px 0 28px rgba(20, 32, 72, 0.16);
}

.erp-brand {
  display: grid;
  gap: 3px;
  padding: 4px 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 12px;
}

.erp-brand strong {
  font-size: 17px;
  line-height: 1.2;
}

.erp-brand span {
  color: var(--nav-muted);
  font-size: 12px;
}

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

.erp-nav-item {
  justify-content: start;
  width: 100%;
  height: 42px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 4px;
  padding: 0 12px 0 10px;
  background: transparent;
  color: var(--nav-text);
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 600;
}

.erp-nav-item:hover {
  border-color: rgba(255, 198, 51, 0.45);
  background: rgba(255, 255, 255, 0.08);
}

.erp-nav-item.is-active {
  border-left-color: var(--nav-active);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav-mark {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.11);
  color: var(--nav-active);
  font-size: 12px;
}

.shell {
  width: 100%;
  margin: 0;
  padding: 18px 22px 34px;
}

.erp-main {
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(23, 32, 51, 0.05);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.3;
}

h2 {
  margin-bottom: 12px;
  font-size: 16px;
}

h3 {
  margin: 16px 0 10px;
  font-size: 14px;
}

p,
.hint,
td,
th,
input,
textarea,
select,
button,
.button,
li {
  font-size: 13px;
}

.topbar p,
.hint,
.section-head span {
  color: var(--muted);
}

.erp-view {
  display: none !important;
}

.erp-view.is-active {
  display: block !important;
}

.settings-grid.erp-view.is-active,
.grid.erp-view.is-active {
  display: grid !important;
}

.stack-view.is-active {
  display: grid !important;
  gap: 12px;
}

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

.config-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
}

.config-fields label {
  margin-bottom: 0;
}

.screening-actions {
  margin-bottom: 8px;
}

.workflow-board {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(360px, 1.35fr) minmax(240px, 0.85fr);
  gap: 12px;
  margin-bottom: 10px;
}

.workflow-card {
  border: 1px solid #e5ebf4;
  border-radius: 8px;
  padding: 12px;
  background: #fbfcff;
  min-width: 0;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.workflow-card-main {
  background: #fffdf8;
  border-color: #f6c47d;
}

.workflow-card-head {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: start;
  margin-bottom: 10px;
}

.workflow-card h3 {
  margin: 0 0 3px;
  font-size: 14px;
}

.workflow-card p {
  color: var(--muted);
  line-height: 1.45;
}

.flow-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 8px;
  margin: 10px 0 12px;
}

.flow-stats span {
  display: grid;
  gap: 2px;
  min-height: 56px;
  padding: 9px 10px;
  border: 1px solid #e5ebf4;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
}

.flow-stats b {
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}

.table-flow-map {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px;
  margin: 10px 0 12px;
}

.table-flow-map div {
  border: 1px solid #e5ebf4;
  border-radius: 8px;
  background: #f8fafc;
  padding: 10px 12px;
}

.table-flow-map b,
.table-flow-map span {
  display: block;
}

.table-flow-map b {
  margin-bottom: 4px;
  color: var(--text);
  font-size: 13px;
}

.table-flow-map span {
  color: var(--muted);
  line-height: 1.45;
}

.auto-runner {
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 10px;
  margin: 0 0 10px;
  background: #fff7ed;
}

.compact-switch {
  margin-bottom: 8px;
}

.auto-runner-controls {
  display: grid;
  grid-template-columns: minmax(120px, 180px) auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.auto-runner-controls .inline-field {
  grid-template-columns: auto 1fr;
}

.auto-runner-controls input {
  height: 34px;
}

.step-pill {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.inline-details {
  margin-top: 10px;
}

.inline-details summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.inline-field {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 8px;
  align-items: center;
  margin: 0;
}

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

.select-col {
  width: 72px;
}

.row-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  white-space: nowrap;
}

.row-check input,
.screening-check {
  width: 16px;
  height: 16px;
  padding: 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

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

.card {
  min-height: 84px;
  padding: 13px 14px;
  box-shadow: 0 8px 20px rgba(23, 32, 51, 0.04);
}

.card strong {
  display: block;
  margin-top: 4px;
  color: #05244d;
  font-size: 24px;
}

.panel {
  margin-bottom: 12px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.04);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
  align-items: start;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.settings-grid > .panel {
  margin-bottom: 0;
}

.feishu-settings-panel {
  grid-column: 1 / -1;
}

.compact-panel {
  min-width: 0;
}

.settings-head {
  align-items: flex-start;
}

.settings-toolbar {
  justify-content: flex-end;
}

.settings-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.settings-form-grid label {
  min-width: 0;
  margin-bottom: 0;
}

.settings-form-grid .check {
  min-height: 34px;
  align-self: end;
}

.credentials-grid {
  margin-top: 12px;
}

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

.settings-group {
  margin-top: 12px;
  border: 1px solid #e6ebf4;
  border-radius: 8px;
  background: #fbfcff;
}

.settings-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  gap: 12px;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}

.settings-group summary::-webkit-details-marker {
  display: none;
}

.settings-group summary::after {
  content: "+";
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.settings-group[open] summary::after {
  content: "-";
}

.settings-group-title {
  color: var(--text);
  font-weight: 700;
}

.settings-group small {
  display: block;
  margin-left: auto;
  color: var(--muted);
  font-weight: 400;
}

.settings-group-body {
  padding: 0 12px 12px;
}

.settings-subgroup {
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  padding: 0;
}

.settings-subgroup summary {
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  list-style: none;
}

.settings-subgroup summary::-webkit-details-marker {
  display: none;
}

.settings-subgroup .settings-form-grid {
  padding: 0 12px 12px;
}

.prompt-group textarea {
  min-height: 220px;
}

.flow ol {
  display: grid;
  gap: 6px;
  padding-left: 20px;
  color: var(--muted);
}

label {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
  color: var(--muted);
}

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

.switch-field {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}

.switch-field input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-ui {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #e5e7eb;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(17, 24, 39, 0.2);
  transition: transform 0.16s ease;
}

.switch-field input:checked + .switch-ui {
  border-color: var(--accent);
  background: var(--accent);
}

.switch-field input:checked + .switch-ui::after {
  transform: translateX(18px);
}

.switch-field b {
  display: block;
  color: var(--text);
}

.switch-field small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  line-height: 1.35;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fbfcff;
  color: var(--text);
  font: inherit;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(249, 115, 22, 0.16);
  border-color: var(--accent);
  background: #fff;
}

textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.45;
}

button,
.button {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-grid;
  place-items: center;
}

button:hover,
.button:hover {
  border-color: var(--accent);
}

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

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

button:disabled,
.button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  min-height: 34px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #edf1f7;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid #e6ebf4;
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 9px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafd;
  color: var(--muted);
  font-weight: 600;
}

tbody tr:hover {
  background: #fffaf5;
}

td.title {
  max-width: 360px;
  white-space: normal;
}

.record-id {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-row {
  padding: 28px 12px;
  text-align: center;
  white-space: normal;
  color: var(--muted);
  background: #f9fafb;
}

.screening-thumb {
  display: block;
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #f9fafb;
}

.status {
  display: inline-flex;
  align-items: center;
  height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #eef2f7;
  color: var(--muted);
  font-weight: 600;
}

.status.done,
.status.ok {
  background: #dcfce7;
  color: var(--ok);
}

.status.error {
  background: #fee2e2;
  color: var(--bad);
}

.status.running,
.status.pending {
  background: #fff7ed;
  color: var(--warn);
}

.logs {
  display: grid;
  gap: 7px;
  max-height: 310px;
  overflow: auto;
}

.log-line {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fbfcff;
}

.log-line b {
  margin-right: 8px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  background: #111827;
  color: #fff;
  box-shadow: 0 12px 40px rgba(17, 24, 39, 0.22);
}

.erp-sidebar .erp-nav-item {
  display: flex;
  place-items: initial;
  justify-content: flex-start;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
}

.erp-sidebar .erp-nav-item:hover {
  border-color: rgba(255, 198, 51, 0.45);
}

.erp-sidebar .erp-nav-item.is-active {
  border-left-color: var(--nav-active);
}

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

  .erp-sidebar {
    position: static;
    height: auto;
    padding: 10px;
  }

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

  .erp-main {
    height: auto;
    overflow: visible;
  }

  .topbar,
  .grid,
  .workflow-board,
  .table-flow-map,
  .settings-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

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

@media (max-width: 640px) {
  .shell {
    width: 100%;
    padding: 10px;
  }

  .erp-nav {
    grid-template-columns: 1fr;
  }

  .section-head,
  .settings-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .settings-toolbar,
  .top-actions {
    width: 100%;
  }

  .settings-toolbar button,
  .top-actions button {
    flex: 1 1 140px;
  }

  .settings-form-grid {
    grid-template-columns: 1fr;
  }

  .auto-runner-controls {
    grid-template-columns: 1fr;
  }
}
