:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --line: #d7dde5;
  --line-strong: #b8c2ce;
  --text: #18202a;
  --muted: #657181;
  --brand: #0f6b5f;
  --brand-strong: #0a4f47;
  --accent: #a64610;
  --warn: #a86a00;
  --danger: #b42318;
  --ok: #13795b;
  --shadow: 0 10px 24px rgba(16, 24, 40, 0.08);
  --radius: 8px;
  --font-main: "Inter", "MiSans", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-main);
}

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

button,
.ghost-button,
.file-button {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.ghost-button:hover,
.file-button:hover {
  border-color: #8ea0b4;
  background: #f8fafc;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

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

.workbench {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.topbar {
  min-height: 112px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 18px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.brand-block h1 {
  margin: 2px 0 6px;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand-block p {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  margin: 0;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
}

.top-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 520px;
}

.status-chip,
.status-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 10px;
}

.status-chip.ok,
.status-pill.ok {
  border-color: #9bd2c0;
  background: #edf9f5;
  color: var(--ok);
}

.status-chip.warn,
.status-pill.warn,
.status-pill.missing {
  border-color: #f1cc82;
  background: #fff8e8;
  color: var(--warn);
}

.status-chip.error,
.status-pill.error {
  border-color: #f4b6af;
  background: #fff3f1;
  color: var(--danger);
}

.status-pill.small {
  min-height: 24px;
  padding: 3px 8px;
  font-size: 11px;
}

.ops-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.metric {
  background: #fff;
  padding: 12px 20px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  line-height: 1.1;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  align-items: start;
}

.left-rail,
.main-stage {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.module,
.main-stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.module {
  padding: 14px;
}

.main-stage {
  padding: 16px;
}

.module-head,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.module-head h2,
.section-head h2 {
  margin: 0 0 4px;
  font-size: 16px;
  line-height: 1.2;
}

.module-head p,
.section-head p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.field {
  margin-top: 12px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select,
.rule-panel input,
.rule-panel select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 7px 10px;
}

.inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.drop-zone {
  min-height: 106px;
  margin-top: 12px;
  border: 1px dashed #99a8ba;
  border-radius: var(--radius);
  background: var(--panel-soft);
  position: relative;
  display: grid;
  place-items: center;
  padding: 18px;
  text-align: center;
  cursor: pointer;
}

.drop-zone.dragover {
  border-color: var(--brand);
  background: #eef8f5;
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-copy strong {
  display: block;
  font-size: 14px;
}

.drop-copy span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.file-list {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.file-list.compact {
  margin-top: 8px;
}

.file-item {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.file-item span,
.file-item strong {
  overflow-wrap: anywhere;
}

.rule-upload,
.rule-actions,
.template-actions,
.actions,
.group-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rule-upload {
  margin-top: 12px;
}

.rule-compare-result {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  padding: 10px;
}

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

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

.compare-summary div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 8px;
}

.compare-summary span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.compare-summary strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
}

.compare-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 5px;
  color: #344054;
  font-size: 12px;
}

.compare-list li {
  border-left: 3px solid var(--line-strong);
  padding-left: 8px;
  overflow-wrap: anywhere;
}

.compare-list li.warn {
  border-color: var(--warn);
}

.compare-list li.ok {
  border-color: var(--ok);
}

.rule-actions {
  margin-top: 10px;
}

.stack-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.stack-list div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  padding: 10px;
}

.stack-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stack-list strong {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.template-status {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.template-drop {
  min-height: 82px;
  margin-top: 0;
}

.template-manage {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}

.template-manage > summary,
.template-upload > summary {
  cursor: pointer;
  color: #344054;
  font-weight: 800;
  user-select: none;
}

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

.template-grid label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sync-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 8px;
}

.helper {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

#ruleSyncStatus.sync-ok {
  color: var(--ok);
}

#ruleSyncStatus.sync-syncing {
  color: var(--warn);
}

#ruleSyncStatus.sync-error {
  color: var(--danger);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.tab-btn {
  min-height: 32px;
  border-radius: 7px;
  background: #f8fafc;
}

.tab-btn.active {
  border-color: var(--brand);
  background: #eef8f5;
  color: var(--brand-strong);
}

.tab-panels {
  margin-top: 12px;
}

.tab-panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

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

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

.overview-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  padding: 10px;
}

.overview-card h4 {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.overview-card p {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.rule-panel {
  margin-bottom: 12px;
  border: 1px solid #b9d5ce;
  border-radius: var(--radius);
  background: #f3faf7;
  padding: 12px;
}

.rule-panel h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.rule-panel p {
  margin: 3px 0;
  color: var(--muted);
  font-size: 12px;
}

.rule-panel .rule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.rule-panel label {
  display: block;
  margin-bottom: 4px;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
}

.rule-panel .rule-actions {
  margin-top: 10px;
}

.group-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
  align-items: start;
}

.group-table-area {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.group-table-area .overview,
.group-table-area .rule-panel {
  margin-bottom: 0;
}

.group-delivery-rail {
  min-width: 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.data-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: normal;
  word-break: break-word;
}

.data-table th {
  background: #f1f5f9;
  color: #475467;
  font-size: 11px;
  font-weight: 800;
}

.data-table input {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 5px 7px;
  font-size: 12px;
}

.remark-cell {
  display: flex;
  gap: 6px;
  align-items: center;
}

.urgent-btn {
  min-height: 28px;
  padding: 4px 8px;
  border-color: #e3ae79;
  background: #fff6ed;
  color: var(--accent);
  font-size: 12px;
}

.remark-input.urgent {
  color: var(--danger);
  font-weight: 800;
}

.group-actions {
  margin: 0;
  display: grid;
  gap: 8px;
}

.group-delivery-rail .group-actions {
  position: sticky;
  top: 12px;
}

.group-delivery-rail .group-actions-row {
  display: grid;
  grid-template-columns: 1fr;
}

.group-delivery-rail .group-actions-row button {
  width: 100%;
}

.email-preview {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  padding: 10px;
}

.email-preview-title {
  margin-bottom: 6px;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
}

.email-preview-text {
  width: 100%;
  min-height: 240px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 10px;
  resize: vertical;
  font: 12px/1.6 var(--font-mono);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: 360px;
  border-radius: 8px;
  background: #18202a;
  color: #fff;
  padding: 11px 14px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .workspace-grid {
    grid-template-columns: 320px minmax(0, 1fr);
  }

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

  .group-delivery-rail .group-actions {
    position: static;
  }
}

@media (max-width: 920px) {
  .topbar {
    flex-direction: column;
  }

  .top-status {
    justify-content: flex-start;
  }

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

  .workspace-grid {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .sync-inline,
  .inline {
    grid-template-columns: 1fr;
  }
}
