:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --line: #d8dee8;
  --text: #17202c;
  --muted: #697586;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --accent: #b45309;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: #101828;
  color: #ffffff;
  border-bottom: 4px solid #d6a548;
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.app-header p {
  margin: 5px 0 0;
  color: #cbd5e1;
  font-size: 13px;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.header-button {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #ffffff;
  cursor: pointer;
}

.status-pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: #e5edf7;
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.ok {
  color: #c8f4dc;
}

.status-pill.warn {
  color: #f8df9c;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 20px 22px 36px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(116px, 1fr));
  min-height: 38px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segment {
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.segment.is-active {
  color: #ffffff;
  background: var(--primary);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  min-width: 0;
  flex: 1;
}

.toolbar-actions select {
  width: min(360px, 42vw);
}

.event-id-input {
  width: 130px;
}

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

textarea {
  resize: vertical;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.primary,
.secondary,
.text-action,
.icon-button {
  min-height: 38px;
  border-radius: 6px;
  cursor: pointer;
}

.primary {
  padding: 8px 15px;
  color: #ffffff;
  background: var(--primary);
}

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

.secondary {
  padding: 8px 13px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line);
}

.secondary:hover {
  border-color: var(--primary);
  color: var(--primary-strong);
}

.text-action {
  padding: 6px 8px;
  color: var(--primary-strong);
  background: transparent;
}

.text-action:hover {
  background: rgba(15, 118, 110, 0.08);
}

.icon-button {
  width: 36px;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.work-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.form-panel,
.summary-panel,
.history-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-panel {
  overflow: hidden;
}

.form-section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.form-section:last-child {
  border-bottom: 0;
}

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

.section-heading h2,
.summary-header h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.field-grid.compact {
  grid-template-columns: repeat(4, minmax(130px, 1fr));
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

.edit-table,
.preview-table {
  width: 100%;
  border-collapse: collapse;
}

.edit-table th,
.edit-table td,
.preview-table th,
.preview-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

.edit-table th,
.preview-table th {
  background: #f1f5f9;
  color: #475467;
  font-weight: 650;
  white-space: nowrap;
}

.edit-table tr:last-child td,
.preview-table tr:last-child td {
  border-bottom: 0;
}

.edit-table input,
.edit-table select {
  min-width: 92px;
}

.edit-table .narrow {
  min-width: 66px;
}

.remove-row {
  width: 32px;
  min-height: 32px;
  border-radius: 6px;
  color: var(--danger);
  background: #fff7f7;
  cursor: pointer;
}

.summary-panel {
  position: sticky;
  top: 16px;
  padding: 16px;
}

.summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.summary-header span {
  padding: 5px 8px;
  border-radius: 8px;
  background: #eef6f5;
  color: var(--primary-strong);
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0 0 14px;
}

.metric-grid div {
  padding: 11px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-grid dt {
  color: var(--muted);
  font-size: 12px;
}

.metric-grid dd {
  margin: 4px 0 0;
  font-size: 21px;
  font-weight: 750;
}

.last-result {
  margin-top: 14px;
  padding: 10px;
  min-height: 42px;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
}

.last-result a {
  color: var(--primary-strong);
}

.history-section {
  margin-top: 18px;
  padding: 16px;
}

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

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

.history-title {
  margin: 0 0 4px;
  font-weight: 700;
}

.history-meta {
  color: var(--muted);
  font-size: 12px;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

dialog {
  width: min(560px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
}

#settingsDialog {
  width: min(1180px, calc(100% - 28px));
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-form {
  padding: 18px;
}

.dialog-form label {
  display: block;
  margin-bottom: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

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

.settings-grid h3 {
  margin: 0 0 12px;
  font-size: 14px;
}

.logo-preview {
  min-height: 54px;
  display: flex;
  align-items: center;
  margin: -4px 0 12px;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.logo-preview img {
  max-width: 160px;
  max-height: 42px;
  object-fit: contain;
}

.two-field {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
}

.wide-timezone {
  grid-template-columns: minmax(132px, 0.8fr) minmax(168px, 1.2fr);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 62px;
  padding-top: 20px;
}

.inline-check {
  min-height: 38px;
  padding-top: 0;
}

.full-width {
  width: 100%;
}

.checkbox-label input {
  width: auto;
  min-height: auto;
}

.checkbox-label span {
  margin: 0;
}

.settings-hint {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
}

.captcha-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 78px;
  margin-bottom: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.captcha-box img {
  max-width: 240px;
  max-height: 90px;
  object-fit: contain;
}

.hidden {
  display: none !important;
}

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

  .summary-panel {
    position: static;
  }

  .field-grid,
  .field-grid.compact {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

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

@media (max-width: 760px) {
  .app-header,
  .toolbar,
  .toolbar-actions,
  .history-item {
    align-items: stretch;
    flex-direction: column;
  }

  .header-tools {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-header {
    padding: 16px;
  }

  .app-shell {
    padding: 14px;
  }

  .toolbar {
    display: grid;
  }

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

  .toolbar-actions select {
    width: 100%;
  }

  .event-id-input {
    width: 100%;
  }

  .field-grid,
  .field-grid.compact,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .history-item {
    display: grid;
    grid-template-columns: 1fr;
  }

  .history-actions {
    justify-content: flex-start;
  }

  .settings-grid,
  .two-field {
    grid-template-columns: 1fr;
  }
}
