:root {
  --bg: #f0fdf4;
  --surface: #ffffff;
  --sidebar-bg: #14532d;
  --sidebar-fg: #dcfce7;
  --accent: #16a34a;
  --text: #1f2937;
  --muted: #4b6355;
  --border: #d1fae5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 83, 45, .06), 0 8px 24px rgba(20, 83, 45, .06);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

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

#sidebar {
  width: 248px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 16px;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.brand-sub {
  margin-top: 4px;
  font-size: 12px;
  color: #a7d7b5;
}

#nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#nav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: #c6e7d0;
  font-size: 14px;
  text-decoration: none;
}

#nav a:hover {
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

#nav a[aria-current="page"] {
  background: var(--accent);
  color: #fff;
}

.sidebar-foot {
  margin-top: auto;
  font-size: 12px;
  line-height: 1.6;
  color: #a7d7b5;
}

#main {
  flex: 1;
  min-width: 0;
  padding: 32px clamp(16px, 4vw, 48px);
}

.page-title {
  margin: 0 0 8px;
  font-size: 26px;
}

.page-lead {
  margin: 0 0 28px;
  color: var(--muted);
  line-height: 1.7;
}

.card {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.card p,
.card li {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.9;
}

.card ul,
.card ol {
  margin: 0;
  padding-left: 20px;
}

code {
  padding: 2px 6px;
  border-radius: 6px;
  background: #e8f7ee;
  color: #166534;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .9em;
}

a {
  color: var(--accent);
}

.btn {
  padding: 8px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
}

.btn:hover {
  background: #15803d;
}

.error-card {
  border-color: #fecaca;
  background: #fef2f2;
}

.error-card .btn {
  margin-right: 8px;
}

@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }

  #sidebar {
    width: auto;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
  }

  .brand-sub,
  .sidebar-foot {
    display: none;
  }

  #nav {
    flex-direction: row;
    margin-left: auto;
  }

  #main {
    padding: 20px 16px;
  }
}

.hidden {
  display: none !important;
}

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

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.tab.active {
  border-color: var(--accent);
  background: #ecfdf5;
  color: var(--accent);
  font-weight: 600;
}

.tab-count {
  padding: 1px 7px;
  border-radius: 999px;
  background: #e3f6ea;
  color: var(--muted);
  font-size: 12px;
}

.toolbar-card {
  margin-bottom: 16px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

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

.summary-line {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.input,
.select {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.input:focus,
.select:focus {
  outline: 2px solid #bbf7d0;
  outline-offset: 1px;
  border-color: var(--accent);
}

.input:disabled,
.select:disabled {
  background: #f3faf5;
  color: var(--muted);
  cursor: not-allowed;
}

.btn-secondary {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.btn-secondary:hover {
  background: #f3faf5;
}

.btn-danger {
  background: #b91c1c;
}

.btn-danger:hover {
  background: #991b1b;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.link-button.danger {
  color: #b91c1c;
  margin-left: 10px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.actions a {
  font-size: 14px;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  align-self: end;
  padding-bottom: 10px;
  color: var(--text);
}

.condition-editor {
  margin: 12px 0;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.condition-head,
.condition-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.condition-head {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.condition-row + .condition-row {
  margin-top: 8px;
}

.hint {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f3faf5;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  background: #f7fdf9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

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

.cell-title {
  font-weight: 600;
}

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

.condition-cell {
  max-width: 360px;
  color: var(--muted);
}

.actions-cell {
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.6;
  white-space: nowrap;
}

.badge-success {
  background: #dcfce7;
  color: #166534;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-info {
  background: #ccfbf1;
  color: #115e59;
}

.badge-neutral {
  background: #f3faf5;
  color: #4b6355;
}

.panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7fdf9;
}

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

.panel-success {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.panel-warning {
  border-color: #fde68a;
  background: #fffbeb;
}

.error-list {
  margin: 8px 0 0;
  padding-left: 20px;
  color: #b91c1c;
  font-size: 13px;
}

.empty {
  margin: 8px 0;
  color: var(--muted);
}

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

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 14px;
}

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

.module-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7fdf9;
}

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

.notice {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(520px, calc(100vw - 48px));
  padding: 12px 16px;
  border-radius: 10px;
  background: #14532d;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 20;
}

.notice.error {
  background: #b91c1c;
}

.notice.success {
  background: #166534;
}

@media (max-width: 768px) {
  .condition-head,
  .condition-row {
    grid-template-columns: 1fr;
  }

  .notice {
    right: 16px;
    bottom: 16px;
  }
}

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

.section-head h2 {
  margin: 0;
}

.static-value {
  display: flex;
  align-items: center;
  min-height: 38px;
  color: var(--text);
  font-size: 14px;
}

.mapping-editor {
  margin-top: 14px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.mapping-row {
  display: grid;
  grid-template-columns: 1.2fr 2fr .8fr;
  gap: 10px;
  align-items: center;
}

.mapping-row + .mapping-row {
  margin-top: 8px;
}

.mapping-head {
  color: var(--muted);
  font-size: 12px;
}

.mapping-label {
  color: var(--text);
  font-size: 14px;
}

.mapping-status {
  font-size: 13px;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

.error-text {
  color: #b91c1c;
  font-size: 13px;
}

.warning-text {
  color: #92400e;
}

@media (max-width: 768px) {
  .mapping-row {
    grid-template-columns: 1fr;
  }
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.upload-card {
  display: flex;
  flex-direction: column;
}

.result-card {
  margin-top: 16px;
}
