/* Dashboard styling. Deliberately dependency-free: no Tailwind, no build step,
   so deploying the dashboard is still just `git pull` + `pm2 restart`. */

:root {
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f7f9;
  --card: #ffffff;
  --accent: #822d3f;
  --accent-soft: #fbf2f4;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --err: #b91c1c;
  --err-soft: #fef2f2;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f3f4f6;
    --ink-2: #d1d5db;
    --muted: #9ca3af;
    --line: #303845;
    --bg: #0f1319;
    --card: #171c24;
    --accent: #d98a9c;
    --accent-soft: #2a1a20;
    --ok: #4ade80;
    --ok-soft: #10241a;
    --warn: #fbbf24;
    --warn-soft: #2a2110;
    --err: #f87171;
    --err-soft: #2a1516;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* --- top bar --- */

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  margin-bottom: 28px;
}
.topbar .wrap { display: flex; align-items: center; gap: 28px; height: 58px; }
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; text-decoration: none; color: var(--ink); letter-spacing: -0.01em;
}
.brand span { color: var(--accent); }
.brand img { display: block; width: 26px; height: 26px; }
.topbar nav { display: flex; gap: 20px; margin-right: auto; }
.topbar nav a {
  text-decoration: none; color: var(--muted); font-weight: 500; font-size: 14px;
  padding: 4px 0; border-bottom: 2px solid transparent;
}
.topbar nav a:hover { color: var(--ink); }
.topbar nav a.on { color: var(--ink); border-bottom-color: var(--accent); }
.who { color: var(--muted); font-size: 13px; margin-right: 10px; }
form.inline { display: flex; align-items: center; margin: 0; }

/* --- type --- */

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head > div:first-child { flex: 1; }
code, .mono { font-family: var(--mono); font-size: 13px; }

/* --- cards + tables --- */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.tile {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.tile:hover { border-color: var(--accent); }
.tile .name { font-weight: 600; margin-bottom: 2px; }
.tile .meta { color: var(--muted); font-size: 13px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; padding: 0 12px 8px; white-space: nowrap;
}
td { padding: 11px 12px; border-top: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: var(--accent-soft); }
td a { color: var(--ink); font-weight: 500; }
.empty { color: var(--muted); padding: 28px 0; text-align: center; }

/* --- badges --- */

.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 999px;
}
.badge.sent { background: var(--ok-soft); color: var(--ok); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.sending { background: var(--accent-soft); color: var(--accent); }
.badge.failed { background: var(--err-soft); color: var(--err); }

/* --- forms --- */

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--card); color: var(--ink);
  font: inherit;
}
textarea { font-family: var(--mono); font-size: 13px; line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1; min-width: 160px; margin-bottom: 0; }

button, .btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--ink); color: var(--bg); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { opacity: .88; }
.btn-ghost, button.ghost {
  background: var(--card); color: var(--ink); border-color: var(--line);
}
.btn-danger, button.danger { background: var(--err); color: #fff; }
button.link {
  background: none; border: none; color: var(--muted); padding: 0;
  font-weight: 500; font-size: 13px; text-decoration: underline;
}
button.link:hover { color: var(--ink); }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* --- flash --- */

.flash {
  padding: 11px 14px; border-radius: 8px; margin-bottom: 18px;
  font-size: 14px; border: 1px solid transparent;
}
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: currentColor; }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: currentColor; }
.flash.error { background: var(--err-soft); color: var(--err); border-color: currentColor; }

/* --- editor --- */

.editor-layout { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 980px) { .editor-layout { grid-template-columns: minmax(0, 1fr); } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button {
  background: none; color: var(--muted); border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 8px 12px; font-size: 14px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.pane[hidden] { display: none; }

.CodeMirror {
  height: 460px; border: 1px solid var(--line); border-radius: 8px;
  font-family: var(--mono); font-size: 13px;
}
.editor-pane textarea { height: 460px; }

.preview-frame {
  width: 100%; height: 520px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff;
}
.preview-subject {
  font-weight: 600; padding: 10px 12px; background: var(--accent-soft);
  border-radius: 8px; margin-bottom: 12px; font-size: 14px; word-break: break-word;
}
pre.plain {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px;
  white-space: pre-wrap; word-break: break-word; margin: 0;
}
.sticky { position: sticky; top: 18px; }

/* --- login --- */

.login-wrap { max-width: 360px; margin: 12vh auto; padding: 0 20px; }
.login-wrap h1 { text-align: center; margin-bottom: 22px; }
.login-mark { text-align: center; margin-bottom: 14px; }
.login-mark img { display: inline-block; width: 76px; height: 76px; }

/* --- misc --- */

details.danger-zone { margin-top: 8px; }
details.danger-zone summary { cursor: pointer; color: var(--err); font-size: 13px; font-weight: 600; }
details.danger-zone > div { margin-top: 12px; }
.diff-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 860px) { .diff-cols { grid-template-columns: 1fr; } }
.ins { background: var(--ok-soft); color: var(--ok); display: block; }
.del { background: var(--err-soft); color: var(--err); display: block; }
