:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --line: #d9e0ea;
  --text: #172033;
  --muted: #667085;
  --primary: #1769e0;
  --primary-soft: #e8f1ff;
  --green: #14804a;
  --amber: #a15c00;
  --red: #c0362c;
  --shadow: 0 12px 36px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

.page-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 28px 96px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  margin-bottom: 20px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.list-toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 180px;
  gap: 12px;
  margin-bottom: 18px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.template-table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  table-layout: fixed;
}

.template-table th,
.template-table td {
  border-bottom: 1px solid var(--line);
  padding: 13px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

.template-table th {
  color: var(--muted);
  background: #f8fafc;
  font-weight: 600;
}

.template-table tr:hover td {
  background: #fbfcff;
}

.template-table th:nth-child(4),
.template-table td:nth-child(4) {
  width: 150px;
  max-width: 150px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.45;
}

.row-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.row-actions button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--primary);
  padding: 7px 9px;
  cursor: pointer;
}

.state {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  font-size: 12px;
}

.state-draft {
  color: var(--muted);
  background: #f8fafc;
}

.state-enabled {
  color: var(--green);
  background: #eaf7ef;
  border-color: #a8dfbd;
}

.state-paused {
  color: var(--amber);
  background: #fff7e8;
  border-color: #f0c36a;
}

.state-expired {
  color: #596579;
  background: #eef2f6;
}

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

.business-tag-col {
  width: 260px;
  max-width: 260px;
}

.tag-cell,
.selected-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.selected-tags {
  min-height: 42px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  background: #fff;
}

.tag-select-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.tag-placeholder {
  color: var(--muted);
  padding-left: 6px;
}

.tag-chip,
.tag-more {
  display: inline-block;
  max-width: 100%;
  border: 1px solid #b8cdf2;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-chip.compact {
  max-width: 220px;
}

.tag-more {
  color: var(--muted);
  background: #f8fafc;
  border-color: var(--line);
}

.main-column,
.side-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.sticky {
  position: sticky;
  top: 18px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

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

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

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

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

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.inline-unit {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.inline-unit span {
  color: var(--text);
  white-space: nowrap;
}

.switch,
.checkbox-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch input {
  display: none;
}

.switch span {
  width: 42px;
  height: 24px;
  background: #cfd7e3;
  border-radius: 999px;
  position: relative;
}

.switch span::after {
  content: "";
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  left: 3px;
  top: 3px;
  transition: transform 0.2s ease;
}

.switch input:checked + span {
  background: var(--primary);
}

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

.checkbox-line {
  margin-top: 18px;
  align-items: flex-start;
}

.checkbox-line input,
.check-grid input,
.radio-card input {
  width: auto;
}

.checkbox-line small {
  color: var(--muted);
  line-height: 1.5;
}

.match-dimensions {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.match-dimensions-title {
  display: grid;
  gap: 4px;
}

.match-dimensions-title small {
  color: var(--muted);
  line-height: 1.5;
}

.strong span {
  font-weight: 700;
}

.hint-box {
  margin-top: 14px;
  padding: 12px;
  background: #f3f7fc;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #40506a;
  line-height: 1.6;
}

.segmented,
.variable-row,
.check-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.variable-row {
  margin: 12px 0 18px;
}

.cron-examples {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.cron-examples > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
}

.cron-examples code {
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f9fc;
  color: #40506a;
  font-family: inherit;
}

.badge,
.radio-card,
.segmented button,
.variable {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
}

.segmented .selected,
.radio-card:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.amber {
  color: var(--amber);
  background: #fff7e8;
  border-color: #f0c36a;
}

.badge {
  font-size: 12px;
  padding: 5px 9px;
}

.danger {
  color: var(--red);
  background: #fff1f0;
  border-color: #ffc9c5;
}

.period-fields {
  margin-top: 16px;
}

.secondary,
.ghost,
.primary,
.error-box button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 16px;
  background: #fff;
  cursor: pointer;
}

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

.secondary {
  color: var(--primary);
  border-color: #9cc0f6;
  background: var(--primary-soft);
}

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

.check-grid label {
  min-width: 110px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
}

.variable {
  font-size: 12px;
  cursor: pointer;
  color: #40506a;
  background: #fff;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variable:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-soft);
}

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

.preview-card h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.preview-card p {
  color: #40506a;
  line-height: 1.7;
}

dl {
  margin: 16px 0 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

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

dd {
  margin: 0;
  text-align: right;
}

.error-box,
.form-errors {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #ffc9c5;
  border-radius: 6px;
  background: #fff1f0;
  color: var(--red);
}

.error-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.error-box p,
.form-errors p {
  margin: 4px 0 0;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(23, 32, 51, 0.38);
}

.modal-panel {
  width: min(1080px, 100%);
  max-height: min(760px, calc(100vh - 56px));
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 24px 64px rgba(23, 32, 51, 0.22);
  overflow: hidden;
}

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

.modal-footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-footer > div {
  display: flex;
  gap: 10px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.modal-body {
  min-height: 0;
  overflow: hidden;
}

.business-modal {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}

.business-tree {
  border-right: 1px solid var(--line);
  background: #fbfcff;
  min-height: 520px;
  overflow: auto;
}

.tree-search {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.tree-list {
  display: flex;
  flex-direction: column;
  padding: 10px;
}

.tree-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 6px;
  padding: 9px 10px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-item.root {
  font-weight: 700;
}

.tree-item.child {
  padding-left: 28px;
  color: #40506a;
}

.tree-item.active,
.tree-item:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.business-table-panel {
  min-width: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.table-search {
  display: grid;
  grid-template-columns: auto minmax(0, 320px);
  align-items: center;
  justify-content: end;
  gap: 10px;
  color: var(--muted);
}

.modal-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
}

.modal-table {
  min-width: 680px;
  table-layout: auto;
}

.records-panel {
  width: min(1180px, 100%);
}

.records-modal-body {
  padding: 16px;
}

.records-table {
  min-width: 1500px;
  table-layout: auto;
}

.long-text {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alert-content {
  max-width: 320px;
}

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

.modal-table th:first-child,
.modal-table td:first-child {
  width: 52px;
  text-align: center;
}

.records-table th:first-child,
.records-table td:first-child {
  width: 170px;
  min-width: 170px;
  text-align: left;
  white-space: nowrap;
}

.modal-table input[type="checkbox"] {
  width: auto;
}

.path-text {
  display: block;
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #40506a;
}

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sticky {
    position: static;
  }
}

@media (max-width: 720px) {
  .page-shell {
    padding: 20px 14px 120px;
  }

  .page-header,
  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .two,
  .three,
  .four {
    grid-template-columns: 1fr;
  }

  .tag-select-line,
  .business-modal,
  .table-search {
    grid-template-columns: 1fr;
  }

  .business-tree {
    min-height: 220px;
    max-height: 260px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .action-bar {
    flex-wrap: wrap;
    justify-content: stretch;
  }

  .action-bar button {
    flex: 1 1 42%;
  }
}
