/*
 * Emailer admin styles. No build step: edit and reload.
 * Colours are set once as variables, with a dark set further down.
 */

:root {
  --paper:   #f3f4f1;
  --surface: #ffffff;
  --ink:     #17212b;
  --muted:   #5b6670;
  --line:    #d9dcd7;
  --field:   #ffffff;

  --blue:    #1c4f82;   /* links, primary action */
  --blue-on: #ffffff;
  --red:     #b3261e;   /* failures, the airmail stripe */
  --green:   #1d6a45;   /* sent, the send button */
  --amber:   #8a5a00;

  --tint-blue:  #e6eef6;
  --tint-red:   #fbe9e7;
  --tint-green: #e3f1e9;
  --tint-amber: #fbf0d9;
  --tint-grey:  #e9ebe8;

  --radius: 5px;
  --font: "Ubuntu", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "Ubuntu Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:   #14191e;
    --surface: #1c232a;
    --ink:     #e8ebee;
    --muted:   #9aa5af;
    --line:    #313b45;
    --field:   #141a20;

    --blue:    #8fbbe8;
    --blue-on: #0e1a26;
    --red:     #f0958c;
    --green:   #7fcfa2;
    --amber:   #e3b75e;

    --tint-blue:  #1d2e40;
    --tint-red:   #3b2020;
    --tint-green: #1b3327;
    --tint-amber: #3a2e14;
    --tint-grey:  #283039;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}

a { color: var(--blue); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

h1, h2 { margin: 0; line-height: 1.2; font-weight: 700; }
h1 { font-size: 1.75rem; letter-spacing: -0.01em; }
h2 { font-size: 1.0625rem; margin-bottom: 12px; }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }
code { font: 0.9em var(--mono); background: var(--tint-grey); padding: 1px 5px; border-radius: 3px; }

:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.main { padding-top: 28px; padding-bottom: 64px; }

.visually-hidden, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip:focus { position: absolute; left: 8px; top: 8px; z-index: 10; background: var(--surface); padding: 8px 12px; }

.quiet { color: var(--muted); }
.small { font-size: 0.8125rem; }
.break { overflow-wrap: break-word; }
.nowrap { white-space: nowrap; }

/* ---------- Masthead: the one flourish is the airmail edge ---------- */

.masthead {
  border-bottom: 1px solid var(--line);
  padding-top: 5px;
  background:
    repeating-linear-gradient(-45deg,
      var(--red) 0 12px, transparent 12px 20px,
      var(--blue) 20px 32px, transparent 32px 40px) top / 100% 5px no-repeat,
    var(--surface);
}
.masthead-inner { display: flex; align-items: center; gap: 28px; min-height: 56px; flex-wrap: wrap; }

.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.125rem; color: var(--ink); text-decoration: none; }
.brand-mark { width: 24px; height: 17px; flex: none; }

.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; padding: 17px 10px 14px; border-bottom: 3px solid transparent; margin-bottom: -1px; font-weight: 500; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }

.logout { margin: 0; }
@media (max-width: 620px) {
  .masthead-inner { gap: 0 16px; padding-top: 8px; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; margin: 4px -10px 0; }
  .nav a { padding: 10px 10px 9px; }
}
.link-button { font: inherit; color: var(--muted); background: none; border: 0; padding: 6px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-button:hover { color: var(--ink); }

/* ---------- Page furniture ---------- */

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.crumb { margin: 0 0 6px; font-size: 0.875rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.panel-plain { background: none; border-style: dashed; }
.panel-live { border-left: 4px solid var(--green); }
.empty { text-align: left; padding: 28px 24px; }

.lead { font-size: 1.125rem; font-weight: 500; }
.figure { font-size: 2.75rem; line-height: 1; font-weight: 700; margin-bottom: 4px; font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 20px; margin-bottom: 20px; }
.grid > .panel { margin-bottom: 0; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: minmax(0, 1fr); } }

progress { width: 100%; height: 10px; margin: 2px 0 10px; accent-color: var(--green); }

/* ---------- Messages ---------- */

.flash { border: 1px solid; border-radius: var(--radius); padding: 11px 14px; margin-bottom: 16px; }
.flash-success { background: var(--tint-green); border-color: var(--green); }
.flash-error   { background: var(--tint-red);   border-color: var(--red); }
.flash-warning { background: var(--tint-amber); border-color: var(--amber); }
.flash-info    { background: var(--tint-blue);  border-color: var(--blue); }

.notice { background: var(--tint-amber); border: 1px solid var(--amber); border-radius: var(--radius); padding: 12px 14px; }
.notice p { margin-bottom: 8px; font-size: 0.9375rem; }

.checklist { list-style: none; margin: 0 0 16px; padding: 0; }
.checklist li { padding: 7px 0 7px 26px; position: relative; border-top: 1px solid var(--line); }
.checklist li::before { position: absolute; left: 2px; font-weight: 700; }
.check-ok::before  { content: "\2713"; color: var(--green); }
.check-bad::before { content: "\2717"; color: var(--red); }
.check-bad { color: var(--red); }

/* ---------- Tables ---------- */

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; margin-bottom: 20px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 16px; vertical-align: top; }
.table th { font-size: 0.8125rem; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table tbody tr + tr td { border-top: 1px solid var(--line); }
.table tbody tr:hover td { background: color-mix(in srgb, var(--tint-grey) 45%, transparent); }
.row-current td { background: var(--tint-blue) !important; }
.cell-action { text-align: right !important; white-space: nowrap; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 0.8125rem; font-weight: 500; white-space: nowrap; background: var(--tint-grey); color: var(--ink); }
.pill-active, .pill-sent        { background: var(--tint-green); color: var(--green); }
.pill-failed, .pill-unsubscribed { background: var(--tint-red);   color: var(--red); }
.pill-scheduled, .pill-sending  { background: var(--tint-blue);  color: var(--blue); }
.pill-pending, .pill-skipped    { background: var(--tint-amber); color: var(--amber); }
.lead .pill { vertical-align: 2px; margin-right: 6px; }

/* ---------- Forms ---------- */

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack > .button { width: 100%; }
.field { display: flex; flex-direction: column; gap: 5px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-label { font-size: 0.875rem; font-weight: 500; padding: 0; }
.hint { font-size: 0.8125rem; color: var(--muted); margin: 0; }
.panel > .hint { margin-top: 12px; }
.panel > h2 + .hint { margin-top: -6px; margin-bottom: 14px; }

input[type="text"], input[type="email"], input[type="password"], input[type="datetime-local"], select, textarea {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 4px; padding: 9px 11px; width: 100%; min-width: 0;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--blue); }

.checks { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; }
.checks-indent { margin: 2px 0 0 26px; }
.checks[disabled] { opacity: 0.5; }
.check { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; cursor: pointer; }
.check input { accent-color: var(--blue); width: 16px; height: 16px; margin: 0; flex: none; transform: translateY(2px); }

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

.button {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-weight: 500; line-height: 1.2; text-decoration: none; cursor: pointer; white-space: nowrap;
  color: var(--ink); background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--ink) 35%, var(--line)); border-radius: 4px; padding: 10px 16px;
}
.button:hover { border-color: var(--ink); }
.button:active { transform: translateY(1px); }
.button-primary { color: var(--blue-on); background: var(--blue); border-color: var(--blue); }
.button-primary:hover { border-color: var(--blue); filter: brightness(1.1); }
.button-send { color: var(--blue-on); background: var(--green); border-color: var(--green); }
.button-send:hover { border-color: var(--green); filter: brightness(1.1); }
.button-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 55%, var(--line)); }
.button-danger:hover { border-color: var(--red); }
.button-quiet { border-color: transparent; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.button-quiet:hover { border-color: transparent; color: var(--ink); }
.button-small { padding: 6px 10px; font-size: 0.875rem; }
.button[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ---------- Tags panel ---------- */

.tag-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.tag-row { display: flex; gap: 6px; align-items: center; margin: 0; }
.tag-row input[type="text"] { padding: 6px 9px; }
.tag-list .small { display: block; margin-top: 3px; }

/* ---------- Login ---------- */

.login-page .main { display: grid; place-items: start center; padding-top: 12vh; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.login-title { display: flex; align-items: center; gap: 10px; font-size: 1.375rem; margin-bottom: 20px; }

/* ---------- Compose: the editor column is the width of the email ---------- */

.compose { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.compose-main { min-width: 0; }
.compose-side .panel { padding: 16px; margin-bottom: 14px; }
@media (max-width: 980px) { .compose { grid-template-columns: minmax(0, 1fr); } }

.letter { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; max-width: 760px; }
.letter-line { display: grid; grid-template-columns: 112px minmax(0, 1fr); align-items: center; border-bottom: 1px solid var(--line); }
.letter-label { padding: 0 0 0 16px; font-size: 0.875rem; color: var(--muted); }
.letter-line input { border: 0; border-radius: 0; padding: 13px 14px 13px 4px; background: transparent; }
.letter-line input:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }
.letter-line:first-child input { font-size: 1.1875rem; font-weight: 500; }
.letter textarea { border: 0; border-radius: 0; display: block; min-height: 420px; font: 0.875rem/1.5 var(--mono); }
.letter .tox-tinymce { border: 0; border-radius: 0; }
.compose-main > .hint { max-width: 760px; }
@media (max-width: 560px) {
  .letter-line { grid-template-columns: minmax(0, 1fr); }
  .letter-label { padding: 10px 14px 0; }
  .letter-line input { padding: 4px 14px 11px; }
}

/* ---------- Preview and review ---------- */

.envelope { margin: 0 0 20px; display: grid; gap: 6px; }
.envelope > div { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 8px; }
.envelope dt { color: var(--muted); font-size: 0.875rem; padding-top: 2px; }
.envelope dd { margin: 0; overflow-wrap: anywhere; }
.panel > .envelope { margin-bottom: 0; }

.previews { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 20px; }
.preview { margin: 0; max-width: 100%; }
.preview figcaption { font-size: 0.875rem; color: var(--muted); margin-bottom: 6px; }
.preview iframe { display: block; border: 1px solid var(--line); border-radius: var(--radius); background: #f1f3f5; height: 760px; max-width: 100%; }
.preview-desktop iframe { width: 660px; }
.preview-phone iframe { width: 360px; }

.plain { font: 0.875rem/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; margin: 14px 0 0; }
details.panel > summary { cursor: pointer; font-weight: 500; }

.recipients { margin: 12px 0 0; padding-left: 28px; columns: 2 280px; column-gap: 32px; }
.recipients li { padding: 2px 0; break-inside: avoid; overflow-wrap: anywhere; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
