:root {
  --bg: #f6f7f9;
  --text: #17202a;
  --muted: #657182;
  --line: #d9dee7;
  --panel: #ffffff;
  --accent: #1b6f5f;
  --accent-strong: #15584c;
  --error: #b42318;
  --success: #157347;
  --warning-bg: #fff7df;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  height: 56px;
  justify-content: space-between;
  padding: 0 24px;
}

.brand {
  color: var(--text);
  font-weight: 700;
}

.nav {
  align-items: center;
  display: flex;
  gap: 18px;
}

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

.page {
  margin: 0;
  max-width: none;
  padding: 24px 18px 48px;
  width: 100%;
}

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

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

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

p {
  color: var(--muted);
  margin: 6px 0 0;
}

.panel,
.section-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 22px;
  padding: 18px;
}

.upload-form,
.auth-panel {
  display: grid;
  gap: 14px;
}

.upload-form {
  align-items: end;
  grid-template-columns: minmax(260px, 1fr) auto;
}

label {
  color: var(--muted);
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
}

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

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

button,
.secondary-action {
  align-items: center;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 700;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
}

button:hover,
.secondary-action:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.danger-button {
  background: #ffffff;
  border-color: #d92d20;
  color: #b42318;
}

.danger-button:hover {
  background: #b42318;
  border-color: #b42318;
  color: #ffffff;
}

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

button.is-loading {
  gap: 8px;
  opacity: 0.85;
}

.spinner {
  animation: spin 0.8s linear infinite;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  height: 16px;
  width: 16px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.secondary-action {
  background: #ffffff;
  color: var(--accent);
}

.secondary-action:hover {
  color: #ffffff;
}

.auth-shell {
  display: grid;
  min-height: calc(100vh - 140px);
  place-items: center;
}

.auth-panel {
  max-width: 380px;
  width: 100%;
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.message {
  border-radius: 6px;
  padding: 11px 12px;
}

.message.error {
  background: #fff0ee;
  color: var(--error);
}

.message.success {
  background: #eaf7ef;
  color: var(--success);
}

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

table {
  border-collapse: collapse;
  min-width: 100%;
  table-layout: auto;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  white-space: normal;
  word-break: normal;
}

td {
  color: #26313f;
}

th {
  background: #f1f4f8;
  color: #475569;
  font-size: 12px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.preview-table {
  max-height: calc(100vh - 300px);
}

.preview-table table {
  table-layout: fixed;
}

.preview-table th,
.preview-table td {
  min-width: 180px;
  white-space: normal;
}

.mapping-grid {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 0;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  margin-bottom: 18px;
}

.mapping-row {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding: 14px;
}

.mapping-row:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.mapping-row b {
  color: var(--error);
}

.actions {
  margin-bottom: 24px;
}

.head-actions,
.inline-delete {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.compact-check {
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 6px;
  white-space: nowrap;
}

.compact-check input {
  min-height: 0;
  width: auto;
}

.metrics {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  margin-bottom: 22px;
}

.metrics div {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metrics span {
  display: block;
  font-size: 26px;
  font-weight: 800;
}

.status {
  background: #eef2f6;
  border-radius: 999px;
  color: #364152;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
}

.status.ready,
.status.imported,
.status.scheduled,
.status.sent {
  background: #eaf7ef;
  color: var(--success);
}

.status.error,
.status.failed,
.status.send_failed,
.status.generation_failed {
  background: #fff0ee;
  color: var(--error);
}

.status.sending {
  background: var(--warning-bg);
  color: #8a5a00;
}

.mapping-summary {
  display: grid;
  grid-template-columns: max-content 1fr;
  margin: 0 0 16px;
}

.mapping-summary dt,
.mapping-summary dd {
  border-bottom: 1px solid var(--line);
  margin: 0;
  padding: 8px 0;
}

.mapping-summary dt {
  color: var(--muted);
  font-weight: 700;
  padding-right: 24px;
}

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

.error-text {
  color: var(--error);
}

.warning-text {
  color: #8a5a00;
}

.env-block {
  background: #101828;
  border-radius: 6px;
  color: #f8fafc;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.small-text {
  font-size: 12px;
  margin-top: 4px;
}

.contacts-table th,
.contacts-table td {
  min-width: 130px;
}

.contacts-controls {
  display: grid;
  gap: 18px;
}

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

.field-picker {
  display: grid;
  gap: 8px;
}

.field-picker-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field-picker-grid {
  display: grid;
  gap: 8px 14px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.contacts-controls-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.campaign-create-form,
.campaign-content-form,
.draft-form {
  display: grid;
  gap: 14px;
}

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

.generation-progress {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
}

.generation-progress[hidden] {
  display: none;
}

.generation-progress-head,
.generation-progress-meta {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.generation-progress-head span,
.generation-progress-meta {
  color: var(--muted);
  font-size: 13px;
}

.generation-progress progress {
  appearance: none;
  background: #eef2f6;
  border: 0;
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
  width: 100%;
}

.generation-progress progress::-webkit-progress-bar {
  background: #eef2f6;
  border-radius: 999px;
}

.generation-progress progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 999px;
}

.generation-progress progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 999px;
}

.queue-metrics {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

.queue-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.queue-filter {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  gap: 8px;
  min-height: 34px;
  padding: 7px 11px;
}

.queue-filter span {
  color: var(--muted);
  font-weight: 700;
}

.queue-filter.active {
  background: #eaf7ef;
  border-color: #b7ddc8;
  color: var(--success);
}

.queue-warning {
  background: #fff7df;
  border: 1px solid #f2d184;
  border-radius: 8px;
  color: #6f4900;
  display: grid;
  gap: 4px;
  margin-top: 14px;
  padding: 12px;
}

.queue-warning span {
  font-size: 13px;
  line-height: 1.45;
}

.queue-reschedule-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 260px) 1fr;
}

.queue-test-recipient-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(240px, 420px) auto;
  margin-top: 14px;
}

.status.test-recipient {
  background: #eef2ff;
  color: #3730a3;
  margin-top: 6px;
}

.queue-reschedule-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.queue-table table {
  table-layout: fixed;
}

.queue-table th:first-child,
.queue-table td:first-child {
  width: 120px;
}

.queue-table th:nth-child(2),
.queue-table td:nth-child(2) {
  width: 260px;
}

.queue-table th:nth-child(3),
.queue-table td:nth-child(3),
.queue-table th:nth-child(4),
.queue-table td:nth-child(4) {
  width: 170px;
}

.queue-table th:nth-child(5),
.queue-table td:nth-child(5) {
  width: 260px;
}

.queue-table th:nth-child(6),
.queue-table td:nth-child(6) {
  width: 320px;
}

.queue-table th:nth-child(7),
.queue-table td:nth-child(7) {
  width: 220px;
}

.queue-table th:nth-child(8),
.queue-table td:nth-child(8) {
  width: 170px;
}

.queue-email {
  font-weight: 700;
  margin-top: 8px;
}

.queue-code {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  margin-top: 4px;
}

.queue-message-body {
  margin-top: 8px;
}

.queue-message-body summary {
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.queue-message-body pre {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #26313f;
  font: inherit;
  line-height: 1.45;
  margin: 8px 0 0;
  max-height: 260px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.small-action {
  font-size: 13px;
  min-height: 34px;
  padding: 6px 10px;
  width: 100%;
}

.queue-actions {
  display: grid;
  gap: 8px;
}

.campaign-create-form {
  align-items: end;
  grid-template-columns: minmax(280px, 1fr) auto;
}

.attachment-list {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 6px;
  padding: 12px;
}

.campaign-table th:first-child,
.campaign-table td:first-child {
  min-width: 280px;
}

.campaign-table th:nth-child(2),
.campaign-table td:nth-child(2) {
  min-width: 220px;
}

.campaign-table th:nth-child(4),
.campaign-table td:nth-child(4) {
  min-width: 520px;
  width: 50%;
}

.campaign-table th:nth-child(5),
.campaign-table td:nth-child(5) {
  min-width: 180px;
}

.task-row {
  scroll-margin-top: 84px;
}

.task-row:target td {
  background: #fff7df;
}

.task-row.is-generating td {
  background: #eef7f4;
}

.contacts-table th:nth-child(2),
.contacts-table td:nth-child(2) {
  min-width: 260px;
}

.contacts-table th:nth-child(3),
.contacts-table td:nth-child(3),
.contacts-table th:nth-child(7),
.contacts-table td:nth-child(7) {
  min-width: 220px;
}

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

@media (max-width: 820px) {
  .page {
    padding: 18px 10px 36px;
  }

  .section-head,
  .topbar {
    align-items: stretch;
    flex-direction: column;
    height: auto;
    padding-bottom: 14px;
    padding-top: 14px;
  }

  .upload-form,
  .mapping-grid,
  .contacts-controls,
  .metrics,
  .campaign-create-form,
  .queue-test-recipient-form,
  .queue-reschedule-form {
    grid-template-columns: 1fr;
  }

  .mapping-row:nth-child(odd) {
    border-right: 0;
  }
}
