* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #f4f4f3;
  --panel: #ffffff;
  --panel-soft: #fafafa;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #d9dee7;
  --line-strong: #b9c2d0;
  --accent: #30343b;
  --accent-dark: #17191d;
  --danger: #b42318;
  --success: #0f7a45;
}

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

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

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

button:hover {
  border-color: var(--accent);
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

button.active,
button[type="submit"] {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

button[type="submit"]:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
}

h2 {
  font-size: 15px;
  line-height: 1.35;
}

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 650;
  color: #344054;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(48, 52, 59, .2);
  border-color: var(--accent);
}

textarea {
  resize: vertical;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  table-layout: fixed;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid #edf0f5;
  padding: 10px 12px;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  color: #475467;
  font-size: 12px;
  font-weight: 700;
  background: #f8fafc;
}

tbody tr:hover {
  background: #f5f5f4;
}

tbody tr.selected {
  background: #ededec;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.login form {
  width: 380px;
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  background: #ffffff;
  box-shadow: 0 16px 40px rgba(31, 41, 51, .08);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 184px minmax(916px, 1fr);
}

.sidebar {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 22px;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 0 6px 18px;
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  font-size: 22px;
}

.brand span,
.section-title span,
.subhead span,
.hint {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

nav {
  display: grid;
  align-content: start;
  gap: 8px;
}

nav button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  border-color: transparent;
  background: transparent;
}

nav button.active {
  background: #ededec;
  color: var(--text);
  border-color: var(--line-strong);
}

.secondary {
  background: #ffffff;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

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

.statusline {
  min-width: 280px;
  display: grid;
  justify-items: end;
  gap: 4px;
  font-size: 13px;
  line-height: 1.35;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(31, 41, 51, .04);
}

.panel-soft,
.table-panel,
.editor-panel,
.preview-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel-soft);
}

.section-title,
.subhead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

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

.grid.tight {
  gap: 10px;
}

.stack {
  display: grid;
  gap: 14px;
}

.wide {
  grid-column: 1 / -1;
}

.split {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 16px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check input {
  width: auto;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin: 12px 0 0;
}

.toolbar input[type="file"] {
  max-width: 320px;
  background: #ffffff;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metrics article {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfe;
}

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

.metrics strong {
  font-size: 28px;
  line-height: 1;
}


.import-box {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.editor-panel {
  background: #ffffff;
}

#template-html {
  min-height: 390px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
}

iframe {
  width: 100%;
  min-height: 420px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
}

pre {
  min-height: 118px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #ffffff;
  color: #344054;
  font-size: 13px;
}

.preview-panel h2 {
  margin: 16px 0 8px;
}

.link-button {
  min-height: auto;
  max-width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  text-align: left;
  overflow-wrap: anywhere;
}

.link-button:hover {
  text-decoration: underline;
}

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

.ok {
  color: var(--success);
}

.hint {
  margin: 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
}

/* Desktop workspaces: a stable navigation rail and grouped work areas. */
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 12px; }
.workspace { width: 100%; max-width: 1660px; margin: 0 auto; }
.topbar { min-height: 60px; }
.section-title .hint { margin-top: 5px; }
.toolbar { margin-bottom: 16px; }
button.primary { color: white; background: var(--accent); border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.send-controls { display: grid; grid-template-columns: minmax(300px, 1fr) auto; gap: 32px; align-items: center; padding: 20px; border: 1px solid var(--line); background: var(--panel-soft); }
.send-controls .toolbar { margin: 0; }
.send-controls .hint { margin-top: 8px; }
.run-hint { margin: 10px 0 28px; }
#tab-dashboard table th { width: 180px; }
.collection-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; width: 100%; min-width: 0; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; text-align: left; }
.collection-row:hover { background: var(--panel-soft); }
.collection-row.selected { background: #ededec; box-shadow: inset 3px 0 var(--accent); }
.row-title, .row-subtitle { grid-column: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-title { font-size: 13px; font-weight: 650; }
.row-subtitle { font-size: 12px; color: var(--muted); }
.empty-state { padding: 24px 16px; border: 1px dashed var(--line-strong); color: var(--muted); line-height: 1.6; }
fieldset { min-width: 0; margin: 0; padding: 18px 0 4px; border: 0; border-top: 1px solid var(--line); }
legend { padding: 0 10px 0 0; font-size: 12px; font-weight: 650; color: var(--muted); }
.connection-grid { display: grid; grid-template-columns: minmax(0, 1fr) 85px 150px; gap: 12px; }
.form-actions { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 18px; }
.form-actions .danger-button { margin-left: auto; }
button.danger-button { color: #fff; background: var(--danger); border-color: var(--danger); }
button.danger-button:hover:not(:disabled) { background: #8e1c13; border-color: #8e1c13; }
.preview-panel .subhead h2 { margin: 0; }
#attachments-table { margin-top: 18px; font-size: 12px; }
#attachments-table th, #attachments-table td { padding: 8px 5px; }

.import-box summary { cursor: pointer; font-size: 13px; font-weight: 650; }
.import-box[open] summary { margin-bottom: 16px; }

.row-badge { grid-column: 2; grid-row: 1 / 3; align-self: center; justify-self: end; color: var(--success); font-size: 12px; font-weight: 650; }

#smtp-test-result.ok { color: #fff; background: var(--success); padding: 12px 14px; border-radius: 6px; }

.collection-library .subhead { margin-bottom: 8px; }
.library-hint { margin-bottom: 16px; font-size: 12px; }
.template-row { display: grid; grid-template-columns: 16px minmax(0, 1fr); align-items: center; gap: 10px; padding: 0 12px; border-bottom: 1px solid var(--line); }
.template-row:hover { background: var(--panel-soft); }
.template-row.selected { background: #ededec; box-shadow: inset 3px 0 var(--accent); }
.template-row > input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }
.template-open { display: grid; gap: 4px; min-width: 0; min-height: 58px; padding: 10px 0; border: 0; border-radius: 0; background: transparent; text-align: left; }
.collection-library .import-box { display: block; margin-top: 20px; }
.collection-library .import-box input[type="file"] { font-size: 12px; }
.detail-panel { min-width: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: white; }
.detail-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 20px 24px; }
.detail-header h2 { font-size: 17px; overflow-wrap: anywhere; }
.detail-header .hint { margin-top: 5px; }
.header-actions { display: flex; gap: 10px; flex-shrink: 0; }
.view-tabs { display: flex; gap: 24px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.view-tabs button { padding: 12px 0; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); font-size: 13px; }
.view-tabs button.active { border-bottom-color: var(--accent); color: var(--text); font-weight: 650; background: transparent; }
.view-tabs button:hover { color: var(--text); }
.detail-body { padding: 24px; }
.detail-body #template-html { min-height: 330px; background: #fcfcfc; }
.template-headers-details { padding: 14px 0; border-top: 1px solid var(--line); }
.template-headers-details summary, .preview-details summary { cursor: pointer; font-size: 13px; font-weight: 650; }
.template-headers-details[open] summary { margin-bottom: 16px; }
.template-editor-footer { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.template-editor-actions { display: flex; gap: 10px; flex-shrink: 0; }
.detail-body iframe { min-height: 480px; }
.preview-details { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
#attachments-form > button { justify-self: start; }
#attachments-table-layout { margin-top: 24px; }

/* Shared collection and detail layout across all pages. */
.collection-workbench { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 24px; align-items: start; }
.collection-library { min-width: 0; position: sticky; top: 24px; }
.collection-list { display: grid; gap: 0; max-height: calc(100vh - 350px); min-height: 60px; overflow-y: auto; border-top: 1px solid var(--line); }
.collection-row { min-height: 58px; align-content: center; }
.collection-library .subhead { margin-bottom: 12px; }
.collection-library .subhead > span { white-space: nowrap; font-variant-numeric: tabular-nums; }
.search-label { margin-bottom: 14px; font-size: 12px; font-weight: 500; color: var(--muted); }
.search-label input { font-size: 13px; }
.detail-header { border-bottom: 1px solid var(--line); }
.detail-header > div:first-child { min-width: 0; }
.header-actions { flex-wrap: wrap; justify-content: flex-end; }
.record-details { margin: 0 0 24px; display: grid; grid-template-columns: 130px minmax(0, 1fr); }
.record-details dt, .record-details dd { margin: 0; padding: 16px 0; border-bottom: 1px solid var(--line); font-size: 14px; overflow-wrap: anywhere; }
.record-details dt { color: var(--muted); padding-right: 16px; }
.record-details dd { font-weight: 500; }
.table-empty { text-align: center; color: var(--muted); padding: 24px; }
.empty-state { font-size: 13px; font-weight: 400; }
.dashboard-progress { margin-top: 20px; }
.send-controls { padding: 0; border: 0; background: transparent; }
.run-hint { margin-bottom: 0; }
#settings-form { min-height: 180px; align-content: start; }
.statusline { max-width: 440px; }
.statusline > :empty, #login-error:empty, #smtp-test-result:empty { display: none; }
.statusline .ok, #smtp-test-result.ok { background: var(--success); color: #fff; padding: 10px 14px; border-radius: 6px; }
.statusline .error, #smtp-test-result.error, #login-error:not(:empty) { background: var(--danger); color: #fff; padding: 10px 14px; border-radius: 6px; }
button[aria-busy="true"] { cursor: progress; }
