:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --line: #d8e0e8;
  --text: #17212b;
  --muted: #5d6b7a;
  --blue: #155eef;
  --blue-dark: #0f46b8;
  --red: #c2410c;
  --green: #047857;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
  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;
}

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

button {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--text);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #9fb0c5;
}

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

button.primary:hover {
  background: var(--blue-dark);
}

button.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
}

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

.topbar h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.status-pill {
  min-width: 108px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
}

.status-pill.dry {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fed7aa;
}

.status-pill.live {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.15fr) minmax(320px, 0.8fr);
  gap: 14px;
  align-items: start;
}

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

.compose-panel {
  grid-row: span 2;
}

.preview-panel {
  grid-row: span 2;
}

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

.panel-heading h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.panel-heading-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.draft-status {
  color: var(--muted);
  font-size: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}

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

.app-nav {
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.app-nav button {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-weight: 700;
  min-height: 44px;
  white-space: nowrap;
}

.app-nav button.active {
  border-bottom-color: var(--blue);
  color: var(--blue-dark);
}

.view-panel[hidden] {
  display: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(21, 94, 239, 0.12);
}

textarea {
  min-height: 120px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}

#html {
  min-height: 360px;
}

#csv {
  min-height: 220px;
}

#subscriberCsv,
#suppressionCsv {
  min-height: 86px;
}

.two-cols,
.upload-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
}

.asset-output {
  min-height: 38px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 10px;
  color: var(--muted);
  overflow-wrap: anywhere;
  background: #f8fafc;
}

.hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

#previewFrame {
  width: 100%;
  min-height: 760px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.metric-row div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f8fafc;
}

.metric-row span {
  display: block;
  font-size: 24px;
  font-weight: 800;
}

.metric-row small {
  color: var(--muted);
}

.notice {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  margin: 12px 0;
  color: var(--muted);
  background: #f8fafc;
}

.notice.ok {
  border-color: #a7f3d0;
  background: #ecfdf5;
  color: var(--green);
}

.notice.error {
  border-color: #fed7aa;
  background: #fff7ed;
  color: var(--red);
}

.toast-notice {
  box-shadow: var(--shadow);
  margin: 0;
  max-width: min(480px, calc(100vw - 24px));
  position: fixed;
  right: 18px;
  top: 18px;
  width: max-content;
  z-index: 1000;
}

.toast-notice[hidden] {
  display: none;
}

.profile-summary {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  display: grid;
  gap: 4px;
  line-height: 1.45;
  margin: -4px 0 12px;
  padding: 10px;
}

.profile-summary strong {
  color: var(--text);
}

.profile-summary small {
  color: var(--muted);
}

.jobs {
  display: grid;
  gap: 10px;
}

.job,
.empty {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f8fafc;
}

.job-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.job-head span {
  color: var(--blue);
  font-weight: 700;
}

.job-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}

.button-link:hover {
  border-color: #9fb0c5;
}

.job ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.login-page {
  min-height: 100vh;
}

.login-shell {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-width: 420px;
  padding: 24px;
  width: 100%;
}

.login-panel h1 {
  font-size: 24px;
  letter-spacing: 0;
  margin: 0;
}

.login-panel p {
  color: var(--muted);
  margin: 0;
}

.login-panel button {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.login-notice {
  color: var(--red);
  min-height: 20px;
}

.health-records + .health-records {
  margin-top: 12px;
}

.subscriber-manager {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 14px 0;
  padding: 12px;
}

.subscriber-manager h3 {
  font-size: 16px;
  letter-spacing: 0;
  margin: 0 0 10px;
}

.health-records ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.health-records li {
  margin: 6px 0;
}

.health-records small {
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

.record-status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  margin-right: 6px;
  padding: 4px 7px;
}

.record-status.ok {
  background: #dff7e7;
  color: #166534;
}

.record-status.warn {
  background: #fff0d6;
  color: #9a3412;
}

.report-panel {
  grid-column: 1 / -1;
}

.health-panel,
.history-panel {
  grid-column: 1 / -1;
}

.history-toolbar {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.history-toolbar label {
  margin: 0;
  min-width: 220px;
}

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

.history-table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 940px;
  width: 100%;
}

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

.history-table th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
}

.history-table td small {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

.history-status {
  color: var(--blue-dark);
  font-weight: 700;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.confirm-dialog {
  background: transparent;
  border: 0;
  max-width: 620px;
  padding: 14px;
  width: 100%;
}

.confirm-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.confirm-dialog-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.24);
  padding: 18px;
}

.server-html-import {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin: -2px 0 14px;
}

.server-html-source {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.server-html-dialog {
  background: transparent;
  border: 0;
  max-width: 980px;
  padding: 14px;
  width: calc(100% - 24px);
}

.server-html-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.server-html-dialog-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.24);
  max-height: calc(100vh - 40px);
  overflow: hidden;
  padding: 18px;
}

.server-html-toolbar {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(260px, 1fr) auto;
}

.server-html-toolbar label {
  margin-bottom: 0;
}

.server-html-list {
  margin-top: 12px;
  max-height: 52vh;
  overflow: auto;
}

.server-html-table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 700px;
  table-layout: fixed;
  width: 100%;
}

.server-html-table th,
.server-html-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: middle;
}

.server-html-table th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.server-html-table th:nth-child(1) { width: 38%; }
.server-html-table th:nth-child(2) { width: 27%; }
.server-html-table th:nth-child(3) { width: 15%; }
.server-html-table th:nth-child(4) { width: 20%; }

.server-html-table code {
  overflow-wrap: anywhere;
  white-space: normal;
}

.confirm-mode {
  border: 1px solid var(--line);
  border-radius: 6px;
  font-weight: 700;
  padding: 10px;
}

.confirm-mode.live {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #9a3412;
}

.confirm-mode.dry {
  background: #f8fafc;
  color: var(--muted);
}

.confirm-summary {
  margin: 14px 0;
}

.confirm-summary > div {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: 130px 1fr;
  padding: 9px 0;
}

.confirm-summary dt {
  color: var(--muted);
}

.confirm-summary dd {
  font-weight: 700;
  margin: 0;
  overflow-wrap: anywhere;
}

.confirm-check {
  align-items: start;
  color: var(--text);
  display: grid;
  gap: 8px;
  grid-template-columns: 18px 1fr;
}

.confirm-check input {
  height: 18px;
  margin: 0;
  padding: 0;
  width: 18px;
}

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

.report-panel[hidden],
.report-content[hidden] {
  display: none;
}

.report-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 5px 0 0;
}

.report-metrics {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(9, minmax(100px, 1fr));
}

.report-metrics > div {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 3px;
  min-height: 88px;
  padding: 10px;
}

.report-metrics span {
  font-size: 22px;
  font-weight: 800;
}

.report-metrics strong {
  font-size: 12px;
}

.report-metrics small {
  color: var(--muted);
}

.report-note {
  margin-top: 10px;
}

.report-toolbar {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.report-toolbar label {
  margin: 0;
  min-width: 190px;
}

.report-toolbar select,
.report-toolbar input {
  min-height: 36px;
}

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

#reportContentFrame {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 620px;
  width: 100%;
}

.report-section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.report-section + .report-section {
  margin-top: 18px;
}

.report-section h3 {
  font-size: 15px;
  letter-spacing: 0;
  margin: 0 0 10px;
}

.report-section-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.report-section-head span {
  color: var(--muted);
  font-size: 13px;
}

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

.report-table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 720px;
  width: 100%;
}

.report-table th,
.report-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

.report-table th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
}

.report-table td {
  overflow-wrap: anywhere;
}

.report-table td small {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

.report-table td > a {
  display: block;
  margin-top: 3px;
}

.interaction-line + .interaction-line {
  border-top: 1px dashed var(--line);
  margin-top: 6px;
  padding-top: 6px;
}

.interaction-line small {
  overflow-wrap: anywhere;
}

.interaction-error {
  color: var(--red);
  margin-top: 6px;
}

.report-table a {
  color: var(--blue-dark);
}

.accounts-panel {
  grid-column: 1 / -1;
}

.account-form {
  display: grid;
  gap: 14px;
}

.account-form h3,
.account-admin-tools h3 {
  font-size: 16px;
  letter-spacing: 0;
  margin: 0;
}

.account-form-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.account-admin-tools {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 18px;
  margin-top: 24px;
  padding-top: 20px;
}

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

.account-table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 820px;
  width: 100%;
}

.account-table th,
.account-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
}

.account-table th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
}

.account-table td small {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.account-actions button {
  font-size: 12px;
  min-height: 34px;
  padding: 6px 10px;
}

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

  .preview-panel {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  .report-metrics {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .workspace,
  .two-cols,
  .upload-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar {
    align-items: stretch;
  }

  #previewFrame {
    min-height: 520px;
  }

  .metric-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-heading-actions {
    justify-content: flex-start;
  }

  .confirm-summary > div {
    gap: 4px;
    grid-template-columns: 1fr;
  }

  .report-metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .report-toolbar {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
  }

  .server-html-toolbar {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .server-html-dialog-panel {
    padding: 14px;
  }

  .account-form-grid {
    grid-template-columns: 1fr;
  }
}
