
:root {
  --bg: #eef2f7; --card: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --input: #f8fafc; --accent: #2563eb; --accent-text: #ffffff;
  --ok: #15803d; --warn: #b45309; --err: #b91c1c;
  --phone-frame: #111827; --phone-screen: #ffffff; --phone-bar: #f8fafc;
  --bubble-in: #e9e9eb; --bubble-in-text: #111827;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --card: #172033; --text: #f1f5f9; --muted: #94a3b8; --line: #2b3a55;
          --input: #0f172a; --ok: #4ade80; --warn: #fbbf24; --err: #f87171;
          --phone-frame: #000000; --phone-screen: #000000; --phone-bar: #111111;
          --bubble-in: #262629; --bubble-in-text: #f5f5f7; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text);
       padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
header { display: flex; align-items: center; justify-content: space-between;
         max-width: 1040px; margin: 0 auto; padding: 16px; }
header h1 { font-size: 20px; margin: 0; }

.layout { max-width: 1040px; margin: 0 auto; padding: 0 16px 40px;
          display: grid; grid-template-columns: minmax(0, 1fr) 340px; column-gap: 24px; align-items: start;
          grid-template-areas: "form preview" "history preview"; }
.form-area { grid-area: form; }
.history-area { grid-area: history; }
.preview-col { grid-area: preview; }
@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "form" "preview" "history"; }
  .preview-col { position: static; margin-bottom: 18px; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin-bottom: 18px; }
label { display: block; font-size: 14px; font-weight: 600; margin: 0 0 6px; }
.field { margin-bottom: 16px; }
select, textarea, input { width: 100%; font: inherit; color: var(--text); background: var(--input);
         border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
select:focus, textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
#recipients { min-height: 150px; font-variant-numeric: tabular-nums; line-height: 1.7; }
#body { min-height: 140px; }
button { font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer; }
.primary { background: var(--accent); color: var(--accent-text); width: 100%; padding: 15px; font-size: 17px; }
.primary:disabled { opacity: .5; }
.ghost { background: transparent; color: var(--accent); padding: 6px 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.muted { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.chip { display: inline-block; font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.warn { color: var(--warn); }
.error-text { color: var(--err); }
.hidden { display: none !important; }

/* ---------- Phone preview ---------- */
.preview-col { position: sticky; top: 16px; }
.preview-title { font-size: 14px; font-weight: 600; color: var(--muted); text-align: center; margin: 0 0 10px; }
.phone { width: 320px; height: 640px; margin: 0 auto; background: var(--phone-frame);
         border-radius: 52px; padding: 12px; box-shadow: 0 20px 50px rgba(15, 23, 42, .25), inset 0 0 0 2px #374151; }
.screen { position: relative; height: 100%; background: var(--phone-screen); border-radius: 42px;
          overflow: hidden; display: flex; flex-direction: column; }
.island { position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
          width: 96px; height: 28px; background: #000; border-radius: 20px; z-index: 2; }
.status-bar { display: flex; justify-content: space-between; align-items: center;
              padding: 14px 26px 0; height: 46px; font-size: 14px; font-weight: 600; color: var(--text); }
.status-icons { display: flex; gap: 5px; align-items: center; }
.status-icons svg { display: block; }
.chat-header { text-align: center; padding: 8px 12px 10px; background: var(--phone-bar);
               border-bottom: 1px solid var(--line); }
.avatar { width: 46px; height: 46px; border-radius: 50%; margin: 0 auto 4px;
          background: linear-gradient(180deg, #a5b4c8, #7d8ea8); color: #fff;
          display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; }
.chat-name { font-size: 13px; font-weight: 600; color: var(--text); word-break: break-all; }
.chat-body { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; }
.chat-meta { text-align: center; font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.chat-meta strong { font-weight: 600; }
.bubble { align-self: flex-start; max-width: 82%; background: var(--bubble-in); color: var(--bubble-in-text);
          padding: 8px 12px; border-radius: 18px; border-bottom-left-radius: 6px;
          font-size: 15px; line-height: 1.35; white-space: pre-wrap; word-break: break-word; }
.bubble.empty { color: var(--muted); font-style: italic; }
.chat-input { display: flex; align-items: center; gap: 8px; padding: 8px 12px 26px; }
.chat-input div { flex: 1; height: 32px; border: 1px solid var(--line); border-radius: 16px;
                  font-size: 13px; color: var(--muted); display: flex; align-items: center; padding: 0 12px; }
.preview-stats { text-align: center; font-size: 13px; color: var(--muted); margin-top: 12px; }
@media (max-width: 380px) { .phone { width: 290px; height: 590px; } }

/* ---------- Toast and history ---------- */
#toast { position: fixed; left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom));
         max-width: 520px; margin: 0 auto; padding: 14px 16px; border-radius: 12px; color: #fff;
         font-weight: 600; z-index: 10; }
#toast.ok { background: #15803d; } #toast.err { background: #b91c1c; }
.history-item { border-top: 1px solid var(--line); padding: 10px 0; }
.history-item:first-child { border-top: 0; }
.history-body { white-space: pre-wrap; word-break: break-word; margin: 4px 0; }
.history-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.history-meta { color: var(--muted); font-size: 13px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600;
         padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge.delivered { background: rgba(21, 128, 61, .12); color: var(--ok); }
.badge.pending { background: rgba(180, 83, 9, .12); color: var(--warn); }
.badge.failed { background: rgba(185, 28, 28, .12); color: var(--err); }
.recipient-list { list-style: none; margin: 6px 0 0; padding: 0; }
.recipient-list li { display: flex; justify-content: space-between; align-items: center;
                     padding: 4px 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.history-error { color: var(--err); font-size: 13px; margin-top: 4px; }
.legend { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.banner { background: var(--warn); color: #fff; text-align: center; font-size: 13px; padding: 6px; }
#loginView { max-width: 420px; margin: 0 auto; padding: 0 16px; }

/* ---------- Tabs ---------- */
.tabs { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.tabs button { background: transparent; color: var(--muted); padding: 7px 18px; border-radius: 9px; font-size: 15px; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }
.header-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
@media (max-width: 520px) {
  header { flex-wrap: wrap; gap: 10px; }
  header h1 { display: none; }
}

/* ---------- Email ---------- */
.inline-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.secondary { background: transparent; color: var(--accent); border: 1px solid var(--line); padding: 9px 14px; font-size: 14px; }
.secondary:disabled { opacity: .5; }
#emailRecipients { min-height: 170px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; line-height: 1.7; }
#emailBody { min-height: 220px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.hint code { background: var(--input); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; font-size: 12px; }
.test-result { font-size: 13px; margin: 6px 0 0; }
.test-result.ok { color: var(--ok); } .test-result.err { color: var(--err); }

.progress { height: 8px; background: var(--input); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

/* Mail app inside the phone */
.mail-top { display: flex; justify-content: space-between; align-items: center; padding: 6px 14px 8px;
            color: var(--accent); font-size: 14px; border-bottom: 1px solid var(--line); }
.mail-scroll { flex: 1; overflow-y: auto; padding: 12px 14px 20px; }
.mail-subject { font-size: 19px; font-weight: 700; line-height: 1.25; color: var(--text); margin: 0 0 12px; word-break: break-word; }
.mail-from { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.mail-from .avatar { width: 36px; height: 36px; font-size: 15px; margin: 0; flex: none; }
.mail-from-name { font-size: 14px; font-weight: 600; color: var(--text); }
.mail-from-sub { font-size: 12px; color: var(--muted); word-break: break-all; }
.mail-body { font-size: 14px; line-height: 1.5; color: var(--text); word-break: break-word; }
.mail-body p { margin: 0 0 12px; }
.mail-body a { color: var(--accent); }
.mail-body.empty { color: var(--muted); font-style: italic; }

.job-failures { margin: 6px 0 0; padding: 0; list-style: none; }
.job-failures li { font-size: 13px; padding: 3px 0; }
.job-failures .addr { font-variant-numeric: tabular-nums; }
.job-failures .why { color: var(--err); display: block; }
details summary { cursor: pointer; font-size: 13px; color: var(--accent); margin-top: 6px; }

/* ---------- Forms (shared) ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.two-col.tight { gap: 8px; }
@media (max-width: 560px) { .two-col:not(.tight) { grid-template-columns: 1fr; } }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; font-size: 14px; padding-top: 26px; cursor: pointer; }
.check input { width: auto; margin-top: 3px; }
@media (max-width: 560px) { .check { padding-top: 0; } }
.danger { color: var(--err) !important; border-color: var(--err) !important; }
.ghost.inline { padding: 0; font-size: inherit; }
.notice { background: rgba(37, 99, 235, .08); border: 1px solid rgba(37, 99, 235, .25); border-radius: 12px;
          padding: 12px 14px; font-size: 14px; margin-bottom: 16px; }
details > summary { font-weight: 600; font-size: 14px; }

/* Email footer inside the phone preview */
.mail-footer { margin-top: 18px; padding-top: 10px; border-top: 1px solid var(--line);
               font-size: 11px; line-height: 1.45; color: var(--muted); white-space: pre-wrap; word-break: break-word; }

/* ---------- Accounts ---------- */
.accounts-layout { max-width: 760px; margin: 0 auto; padding: 0 16px 40px; }
.acc-list { margin-top: 8px; }
.acc-item { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-top: 10px; }
.acc-item .acc-name { font-weight: 600; }
.acc-item .acc-sub { font-size: 13px; color: var(--muted); word-break: break-all; }
.acc-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.acc-actions button { padding: 7px 12px; font-size: 13px; }
.acc-test { font-size: 13px; margin-top: 6px; }
.acc-test.ok { color: var(--ok); } .acc-test.err { color: var(--err); }

.dns-row { display: grid; grid-template-columns: 28px 1fr; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
.dns-row:first-child { border-top: 0; }
.dns-icon { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
            font-size: 13px; font-weight: 700; color: #fff; }
.dns-icon.ok { background: #16a34a; } .dns-icon.warn { background: #d97706; } .dns-icon.fail { background: #dc2626; }
.dns-title { font-weight: 600; }
.dns-detail { font-size: 13px; color: var(--muted); word-break: break-word; margin-top: 2px; }
.dns-fix { margin-top: 8px; font-size: 13px; background: var(--input); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.dns-fix code { display: block; word-break: break-all; font-size: 12px; margin-top: 2px; }
.dns-summary { font-size: 14px; margin: 6px 0 4px; }
.dns-tips { font-size: 13px; color: var(--muted); margin: 12px 0 0; padding-left: 18px; }
.dns-tips li { margin-bottom: 4px; }
.badge.queued { background: rgba(100, 116, 139, .14); color: var(--muted); }
