/* ============================================================
   BossMailer — design system v5 "amethyst"
   Dark-first violet dashboard: left rail, composition card,
   live-preview column. Light variant kept for
   prefers-color-scheme: light. No external assets, CSP-safe.
   All JS hooks (ids, data-attrs, form names) preserved.
   ============================================================ */

:root {
  color-scheme: dark light;

  /* Neutrals — violet-black */
  --bg: #0d0a13;
  --bg-accent: #131019;
  --rail-bg: #0f0c16;
  --surface: #141019;
  --surface-raised: #1a1521;
  --input-bg: #1a1522;
  --border: #251f31;
  --border-strong: #3a3149;
  --surface-edge: rgba(255, 255, 255, 0.05);

  /* Text */
  --text: #ece9f4;
  --text-muted: #a49cb8;
  --text-subtle: #867e9d;

  /* Brand — amethyst */
  --accent: #a78bfa;
  --accent-hover: #c4b5fd;
  --accent-soft: #241d3a;
  --accent-ring: rgba(167, 139, 250, 0.35);

  /* Button gradient stops tuned to carry white text ≥4.5:1. */
  --btn-top: #7c4ff2;
  --btn-bg: #6d28d9;
  --btn-bg-hover: #7c3aed;
  --tag-text: #c9b8ff;
  --tag-bg: #2a2144;

  --brand-1: #a78bfa;
  --brand-2: #7c3aed;
  --brand-3: #38bdf8;
  --brand-glow: rgba(124, 58, 237, 0.45);

  /* Aurora glows — decorative only */
  --glow-1: rgba(139, 92, 246, 0.13);
  --glow-2: rgba(56, 189, 248, 0.05);
  --glow-3: rgba(192, 132, 252, 0.09);

  /* Status */
  --danger: #f28b82;
  --danger-bg: #2c1719;
  --danger-border: #5a2a2c;
  --success: #7ddaa6;
  --success-bg: #12281e;
  --success-border: #27523e;

  --warn-text: #f2c66b;
  --warn-bg: #2b2214;
  --warn-border: #574722;
  --warn-solid: #caa63f;

  --radius-sm: 9px;
  --radius: 11px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 14px 36px -14px rgba(0, 0, 0, 0.7),
    0 5px 14px -7px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.4), 0 36px 80px -28px rgba(0, 0, 0, 0.85),
    0 14px 34px -16px rgba(0, 0, 0, 0.6);

  --glass: rgba(19, 15, 26, 0.72);
  --rail-shadow: 16px 0 40px -28px rgba(0, 0, 0, 0.6);

  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f0f8;
    --bg-accent: #eae7f3;
    --rail-bg: #edeaf5;
    --surface: #ffffff;
    --surface-raised: #f8f6fc;
    --input-bg: #f4f2fa;
    --border: #e2ddef;
    --border-strong: #c8c0dd;
    --surface-edge: rgba(255, 255, 255, 0);

    --text: #171321;
    --text-muted: #5d5574;
    --text-subtle: #5f5876;

    --accent: #6d28d9;
    --accent-hover: #5b21b6;
    --accent-soft: #f1ebfe;
    --accent-ring: rgba(109, 40, 217, 0.24);

    --btn-top: #7c4ff2;
    --btn-bg: #6d28d9;
    --btn-bg-hover: #5b21b6;
    --tag-text: #5b21b6;
    --tag-bg: #ede9fe;

    --brand-1: #a78bfa;
    --brand-2: #7c3aed;
    --brand-3: #38bdf8;
    --brand-glow: rgba(124, 58, 237, 0.35);

    --glow-1: rgba(139, 92, 246, 0.1);
    --glow-2: rgba(56, 189, 248, 0.07);
    --glow-3: rgba(192, 132, 252, 0.09);

    --danger: #c0392f;
    --danger-bg: #fdeceb;
    --danger-border: #f5c4c0;
    --success: #10794a;
    --success-bg: #e7f6ee;
    --success-border: #b6e3ca;

    --warn-text: #8a5300;
    --warn-bg: #fbf3e0;
    --warn-border: #eed8a4;
    --warn-solid: #b07714;

    --shadow-sm: 0 1px 2px rgba(31, 21, 60, 0.07);
    --shadow: 0 1px 2px rgba(31, 21, 60, 0.05), 0 10px 30px -12px rgba(31, 21, 60, 0.16),
      0 4px 12px -6px rgba(31, 21, 60, 0.07);
    --shadow-lg: 0 1px 2px rgba(31, 21, 60, 0.06), 0 32px 70px -24px rgba(31, 21, 60, 0.26),
      0 12px 30px -14px rgba(31, 21, 60, 0.13);

    --glass: rgba(255, 255, 255, 0.8);
    --rail-shadow: 16px 0 40px -30px rgba(31, 21, 60, 0.12);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Faint violet aurora behind everything. */
body::before {
  content: "";
  position: fixed;
  inset: -12%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(46% 38% at 16% -6%, var(--glow-1), transparent 65%),
    radial-gradient(38% 32% at 92% 0%, var(--glow-2), transparent 65%),
    radial-gradient(54% 42% at 55% 110%, var(--glow-3), transparent 66%);
  animation: aurora 28s ease-in-out infinite alternate;
}

@keyframes aurora {
  to { transform: translate3d(2%, 1.5%, 0) scale(1.05); }
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* The hidden attribute always wins, even on elements with display rules. */
[hidden] {
  display: none !important;
}

/* Thin themed scrollbars */
.pane,
.pvtext,
textarea {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.pane::-webkit-scrollbar,
.pvtext::-webkit-scrollbar,
textarea::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.pane::-webkit-scrollbar-thumb,
.pvtext::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
.pane::-webkit-scrollbar-track,
.pvtext::-webkit-scrollbar-track,
textarea::-webkit-scrollbar-track {
  background: transparent;
}

/* Motion */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================================
   App shell: rail + content, full viewport, no page scroll
   ============================================================ */

.appshell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 226px minmax(0, 1fr);
  overflow: hidden;
}

/* ---------- Left rail ---------- */

.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 20px 14px 16px;
  background: var(--rail-bg);
  border-right: 1px solid var(--border);
  box-shadow: var(--rail-shadow);
  z-index: 2;
  animation: fade-in 0.5s ease both;
}

@keyframes rail-in {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

.rail .brand { animation: rail-in 0.45s ease 0.05s both; }
.rail__nav { animation: rail-in 0.45s ease 0.12s both; }
.rail__logout { animation: rail-in 0.45s ease 0.2s both; }

.rail .brand {
  margin: 0 8px 26px;
}

.rail__label {
  padding: 0 12px;
  margin-bottom: 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.rail__nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rail__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.rail__item svg {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--text-subtle);
  transition: color 0.15s ease, transform 0.18s ease;
}

.rail__item:hover {
  color: var(--text);
  background: var(--surface-raised);
}
.rail__item:hover svg { color: var(--text-muted); transform: translateX(1.5px); }

.rail__item.is-active {
  color: var(--text);
  background: var(--surface-raised);
  border-color: var(--border);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow-sm);
}

.rail__item.is-active svg {
  color: var(--accent);
}

/* Violet indicator bar on the active nav item. */
.rail__item.is-active::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 0 10px var(--brand-glow);
}

.rail__item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.rail__logout {
  margin-top: auto;
}

/* ---------- Content column ---------- */

.screen {
  min-height: 0;
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 24px 16px;
  gap: 12px;
}

/* Dotted texture fading out under the header, like the reference. */
.screen::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 190px;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(rgba(167, 139, 250, 0.16) 1px, transparent 1.4px);
  background-size: 18px 18px;
  -webkit-mask-image: linear-gradient(180deg, #000 20%, transparent);
  mask-image: linear-gradient(180deg, #000 20%, transparent);
}

.crumbs {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-subtle);
  letter-spacing: 0.02em;
  animation: fade-in 0.45s ease both;
}
.crumbs span {
  margin: 0 6px;
  color: var(--border-strong);
}
.crumbs b {
  font-weight: 600;
  color: var(--text-muted);
}

.pagehead {
  flex: none;
  animation: rise-in 0.5s cubic-bezier(0.2, 0.7, 0.25, 1) both;
}

.pagehead__title {
  margin: 0;
  font-size: 25px;
  font-weight: 750;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

/* Subtle violet sheen on the heading where supported. */
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .pagehead__title {
    background: linear-gradient(94deg, var(--text) 55%, var(--accent) 130%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}

.pagehead__sub {
  margin: 3px 0 0;
  font-size: 13.5px;
  color: var(--text-muted);
  text-wrap: pretty;
}

.screen__alert { flex: none; }
.screen__alert .alert { margin-bottom: 0; }

.appform {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(0, 1fr);
  gap: 16px;
}

.pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 18px;
  background: var(--surface);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 120px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow);
  overflow-y: auto;
  animation: rise-in 0.55s cubic-bezier(0.2, 0.7, 0.25, 1) both;
}

.pane.side { animation-delay: 0.08s; }

/* Staggered entrance for the sections inside each pane. */
.editor > *,
.side > * {
  animation: rise-in 0.45s cubic-bezier(0.2, 0.7, 0.25, 1) both;
}
.editor > :nth-child(1) { animation-delay: 0.08s; }
.editor > :nth-child(2) { animation-delay: 0.12s; }
.editor > :nth-child(3) { animation-delay: 0.16s; }
.editor > :nth-child(4) { animation-delay: 0.2s; }
.editor > :nth-child(5) { animation-delay: 0.24s; }
.editor > :nth-child(6) { animation-delay: 0.28s; }
.editor > :nth-child(7) { animation-delay: 0.32s; }
.side > :nth-child(1) { animation-delay: 0.16s; }
.side > :nth-child(2) { animation-delay: 0.22s; }
.side > :nth-child(3) { animation-delay: 0.28s; }
.side > :nth-child(4) { animation-delay: 0.34s; }
.side > :nth-child(5) { animation-delay: 0.4s; }

/* Label lights up while its field is focused. */
.fld__label { transition: color 0.15s ease; }
.fld:focus-within > .fld__label { color: var(--accent); }

.seclabel {
  flex: none;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* ---------- Fields (labeled stacks, screenshot-style) ---------- */

.fld {
  flex: none;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fld--grow {
  flex: 1;
  min-height: 128px; /* label + textarea minimum — never collapses */
}

.fld__label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.lbl__opt {
  font-weight: 500;
  font-size: 11px;
  color: var(--text-subtle);
}

.fgrid {
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.input,
.textarea,
.select {
  width: 100%;
  padding: 11px 13px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.2s ease, background 0.15s ease;
  appearance: none;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-subtle);
  opacity: 1; /* the 0.8 multiplier dropped --text-subtle below AA contrast */
}

.input:hover:not(:disabled):not(:focus):not([readonly]),
.textarea:hover:not(:disabled):not(:focus),
.select:hover:not(:disabled):not(:focus) {
  border-color: var(--border-strong);
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.input:disabled,
.textarea:disabled {
  color: var(--text-muted);
  background: var(--bg-accent);
  cursor: not-allowed;
}

.input[readonly] { color: var(--text-muted); }

.input--mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

.input--sm {
  padding: 9px 12px;
  font-size: 13.5px;
}

.textarea {
  min-height: 190px;
  resize: vertical;
}

.textarea--grow {
  flex: 1;
  min-height: 90px;
  resize: none;
  font-family: inherit;
  line-height: 1.6;
  font-size: 14.5px;
}

/* Native select chevron */
.select {
  padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% + 1px), calc(100% - 13px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

/* The sender identity group reads as one tinted unit. */
.editor .fld:has(.fromtools) {
  padding: 12px;
  background: var(--surface-raised);
  background: color-mix(in srgb, var(--accent-soft) 34%, var(--surface));
  border: 1px solid var(--border);
  border-radius: 12px;
}

/* From row helpers */
.fromids {
  display: flex;
  gap: 9px;
}
#fromName { flex: 0 0 36%; min-width: 0; }
#fromEmail { flex: 1; min-width: 0; }

.fromtools {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.fromtools .linkbtn { margin-left: auto; }

.select--tiny {
  width: auto;
  max-width: 250px;
  padding: 5px 28px 5px 10px;
  font-size: 12px;
  border-radius: 7px;
}

.btn--tiny {
  padding: 5px 11px;
  font-size: 12px;
  border-radius: 7px;
}

#templateHint {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#templateHint:empty { display: none; }

/* Violet pill badge (format tag etc.) */
.field__tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--tag-text);
  background: var(--tag-bg);
  border-radius: 999px;
}
.field__tag:empty { display: none; }

/* Collapsible (placeholders / technical details) */
.mini { flex: none; }

.editor .mini {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.mini__summary {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 2px 0;
  transition: color 0.15s ease;
  list-style: none;
  user-select: none;
}
.mini__summary:hover { color: var(--text-muted); }
.mini__summary::-webkit-details-marker { display: none; }

.mini__summary::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 9px 1px 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
  vertical-align: 1.5px;
}
details[open] > .mini__summary::before {
  transform: rotate(45deg);
}
.mini__summary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
  border-radius: 6px;
}

.mini__hint {
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0;
  text-transform: none;
}

.mini__box {
  margin-top: 9px;
  min-height: 64px;
  resize: vertical;
}

.mini__rows { padding-top: 9px; }

.techrow {
  display: flex;
  gap: 10px;
  font-size: 12px;
  line-height: 1.85;
}
.techrow span {
  flex: none;
  width: 80px;
  color: var(--text-subtle);
  font-family: var(--font-mono);
  font-size: 11px;
}
.techrow b { font-weight: 550; overflow-wrap: anywhere; }
.techrow em { font-style: normal; font-size: 11px; color: var(--text-subtle); }

/* ---------- Live preview column ---------- */

.side__head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 10px;
  min-height: 26px;
}

.side__title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* Realtime pill (filled by app.js via #previewStatus). */
.block__sub {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.block__sub:empty { display: none; }
.block__sub::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-pulse-violet 2.4s ease-out infinite;
}

@keyframes dot-pulse-violet {
  0% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(167, 139, 250, 0); }
  100% { box-shadow: 0 0 0 0 rgba(167, 139, 250, 0); }
}

/* ---------- Email preview card ---------- */

/* One continuous email card: sender row + subject + body. */
.mailcard {
  flex: 1;
  /* Explicit content floor: with overflow:hidden the flex auto-minimum is 0,
     so the card would still collapse — pin it and let the side pane scroll. */
  min-height: 290px;
  min-height: fit-content;
  display: flex;
  flex-direction: column;
  /* The simulated inbox always renders light, like a real mail client window. */
  background: #ffffff;
  font-family: Roboto, "Helvetica Neue", Arial, sans-serif;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow), 0 28px 70px -34px var(--brand-glow);
  overflow: hidden;
}

.gmail {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 10px 16px 12px;
  border-bottom: 1px solid #f0f1f3;
  background: #fff;
}

.gmail__avatar {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(150deg, var(--brand-1), var(--brand-2));
  transition: background 0.25s ease, border-radius 0.25s ease;
}

.gmail__meta { min-width: 0; flex: 1; }

.gmail__line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}

.gmail__name {
  font-size: 13.5px;
  font-weight: 700;
  color: #202124;
  overflow-wrap: anywhere;
}

.gmail__addr {
  font-size: 12px;
  color: #5f6368;
  overflow-wrap: anywhere;
}

#dvGmailVia { color: #5f6368; } /* match .gmail__addr — #80868b was ~3.7:1 on white (below AA) */

.pvsubject {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  padding: 13px 16px 5px;
  background: #fff;
}
.pvsubject b {
  font-weight: 600;
  color: #1f1f1f;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.pvbody {
  flex: 1;
  /* Floor so the preview never crushes on short windows — the side pane
     scrolls instead (it has overflow-y: auto). */
  min-height: 150px;
  background: #fff;
}

.pvframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  display: block;
}

.pvtext {
  margin: 0;
  padding: 14px 16px;
  height: 100%;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: #202124;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #fff;
}

/* Deliverability verdict pill */
.status {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-raised);
}

.status[data-aligned="true"] {
  background: var(--success-bg);
  border-color: var(--success-border);
}

.status[data-aligned="false"] {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

.status__dot {
  flex: none;
  width: 8px;
  height: 8px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--warn-solid);
}

.status[data-aligned="true"] .status__dot {
  background: var(--success);
  animation: dot-pulse-green 2.6s ease-out infinite;
}

@keyframes dot-pulse-green {
  0% { box-shadow: 0 0 0 0 rgba(125, 218, 166, 0.35); }
  70% { box-shadow: 0 0 0 7px rgba(125, 218, 166, 0); }
  100% { box-shadow: 0 0 0 0 rgba(125, 218, 166, 0); }
}

.status__text { color: var(--text-muted); text-wrap: pretty; }
.status[data-aligned="true"] .status__text { color: var(--success); }
.status[data-aligned="false"] .status__text { color: var(--warn-text); }

/* ---------- Segmented toggle ---------- */

.toggle {
  display: inline-flex;
  flex: none;
  padding: 2.5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
}

.toggle__btn {
  padding: 4px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 6.5px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.toggle__btn:hover { color: var(--text); background: var(--surface-raised); }
.toggle__btn:active { transform: scale(0.97); }

.toggle__btn.is-active {
  color: var(--text);
  background: var(--surface-raised);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow-sm);
}

.toggle__btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ---------- Send bar ---------- */

.sendbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 0;
  padding: 0 4px;
  animation: rise-in 0.55s cubic-bezier(0.2, 0.7, 0.25, 1) 0.12s both;
}

.sendbar__note {
  margin-right: auto;
  font-size: 12px;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

/* ---------- Buttons ---------- */

.btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    box-shadow 0.2s ease, transform 0.12s ease;
}

.btn svg { transition: transform 0.2s ease; }

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4.5px var(--accent);
}

.btn:active { transform: translateY(1px); }

.btn--primary {
  background: linear-gradient(180deg, var(--btn-top), var(--btn-bg));
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.3),
    0 6px 18px -5px var(--brand-glow);
}

.btn--primary::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -70%;
  width: 55%;
  background: linear-gradient(105deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  transform: skewX(-18deg);
}

.btn--primary:hover {
  background: linear-gradient(180deg, var(--btn-bg), var(--btn-bg-hover));
  transform: translateY(-1px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 3px 7px rgba(0, 0, 0, 0.25),
    0 10px 28px -8px var(--brand-glow);
}

.btn--primary:hover::after { animation: shine 0.65s ease; }

@keyframes shine {
  from { left: -70%; }
  to { left: 125%; }
}

.btn--primary:hover svg { transform: translate(1px, -1px); }
.btn--primary:active { transform: translateY(0) scale(0.99); }

.btn--primary:disabled {
  opacity: 0.6;
  cursor: progress;
  transform: none;
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-strong);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
}

.btn--ghost:hover {
  color: var(--text);
  background: var(--surface-raised);
  border-color: var(--text-subtle);
}

.btn--soft {
  background: var(--surface-raised);
  color: var(--text-muted);
  border-color: var(--border);
  white-space: nowrap;
}
.btn--soft:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.btn--danger { color: var(--danger); }
.btn--danger:hover { border-color: var(--danger-border); background: var(--danger-bg); }

.btn--lg {
  padding: 12px 26px;
  font-size: 14.5px;
  border-radius: 12px;
}

.btn--block {
  width: 100%;
  padding: 12px 18px;
}

.linkbtn {
  padding: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  text-underline-offset: 3px;
  transition: color 0.15s ease;
}

.linkbtn:hover { text-decoration: underline; color: var(--accent-hover); }

.linkbtn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
  border-radius: 4px;
}

/* ---------- Alerts ---------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 13.5px;
  border: 1px solid;
  border-radius: var(--radius);
  animation: alert-in 0.35s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

@keyframes alert-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.alert svg {
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 1px;
}

.alert--error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.alert--success {
  color: var(--success);
  background: var(--success-bg);
  border-color: var(--success-border);
}

.alert__text {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ============================================================
   Centered pages (login / error)
   ============================================================ */

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px 56px;
}

.page--centered {
  justify-content: center;
  padding-bottom: 88px;
}

.shell {
  width: 100%;
  max-width: 640px;
}

.shell--narrow {
  max-width: 408px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 20px;
}

.brand__mark {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  background: linear-gradient(150deg, var(--brand-1), var(--brand-2));
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 3px 10px -2px var(--brand-glow);
}

.brand__mark svg {
  width: 18px;
  height: 18px;
  display: block;
}

.brand__text {
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: -0.015em;
}

.hero {
  text-align: center;
  margin-bottom: 26px;
  animation: rise-in 0.55s cubic-bezier(0.2, 0.7, 0.25, 1) both;
}

.hero__mark {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 66px;
  height: 66px;
  margin-bottom: 18px;
  border-radius: 20px;
  background: linear-gradient(150deg, var(--brand-1), var(--brand-2));
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 14px 34px -10px var(--brand-glow);
}

.hero__mark::before {
  content: "";
  position: absolute;
  inset: -8px;
  z-index: -1;
  border-radius: 26px;
  background: conic-gradient(from 0deg, var(--brand-1), var(--brand-3), var(--brand-2), var(--brand-1));
  filter: blur(16px);
  opacity: 0.5;
  animation: halo-spin 7s linear infinite;
}

@keyframes halo-spin {
  to { transform: rotate(360deg); }
}

.hero__mark svg {
  width: 31px;
  height: 31px;
}

.hero__title {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 750;
  letter-spacing: -0.03em;
}

.hero__tagline {
  margin: 8px 0 0;
  font-size: 0.95rem;
  color: var(--text-muted);
  text-wrap: pretty;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow);
  overflow: hidden;
}

.card__header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-raised);
}

.card__title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.card__subtitle {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.card__body {
  padding: 22px 24px 24px;
}

.card--login {
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow-lg);
  animation: rise-in 0.6s cubic-bezier(0.2, 0.7, 0.25, 1) 0.08s both;
}

.card--login .card__body {
  padding: 28px 28px 30px;
}

.field + .field { margin-top: 18px; }

.field__label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
}

.field__hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-subtle);
  text-wrap: pretty;
}

.stack-top { margin-top: 22px; }

.footnote {
  margin: 20px auto 0;
  width: fit-content;
  padding: 7px 15px;
  text-align: center;
  font-size: 12px;
  color: var(--text-subtle);
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 999px;
  animation: fade-in 0.7s ease 0.18s both;
}

.link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 550;
}
.link:hover { text-decoration: underline; color: var(--accent-hover); }
.link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

code {
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-accent);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .appshell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  /* Rail becomes a top bar: brand left, log out right. */
  .rail {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .rail .brand { margin: 0; }
  /* The nav must survive as a horizontal strip now that there are three destinations
     (it used to be display:none, which deleted navigation entirely on tablet/phone). */
  /* min-width:0 + flex-shrink are what actually let the strip scroll instead of forcing
     the rail (a grid item, so min-width:auto by default) wider than the viewport. */
  .rail { min-width: 0; }
  .rail__nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    min-width: 0;
    flex: 1 1 auto;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .rail .brand { flex: none; min-width: 0; }
  .rail__logout { flex: none; }
  .rail__nav::-webkit-scrollbar { display: none; }
  .rail__label { display: none; }
  .rail__nav .rail__item { width: auto; padding: 8px 11px; white-space: nowrap; }
  .rail__nav .rail__item.is-active::before {
    left: 10px; right: 10px; top: auto; bottom: -1px;
    width: auto; height: 2.5px; border-radius: 3px;
  }
  .rail__logout { margin: 0 0 0 auto; }
  .rail__logout .rail__item { width: auto; padding: 8px 12px; border: 1px solid var(--border-strong); }

  .screen {
    overflow: visible;
    padding: 18px 16px;
  }
  .workspace { grid-template-columns: 1fr; }
  .pane { overflow-y: visible; }
  .textarea--grow { min-height: 200px; }
  .pvbody { min-height: 320px; }
}

@media (max-width: 560px) {
  .page { padding: 20px 14px 40px; }

  .card__header { padding: 16px 17px 14px; }
  .card__body { padding: 18px 17px 20px; }
  .card--login .card__body { padding: 22px 18px 24px; }

  .btn {
    width: 100%;
    /* Comfortable touch target on phones (WCAG 2.5.5). */
    min-height: 44px;
  }
  .rail__logout .rail__item { width: auto; min-height: 40px; }
  .fromtools .btn { width: auto; min-height: 36px; }

  .fgrid { grid-template-columns: 1fr; }
  .fromids { flex-direction: column; }
  #fromName { flex: none; }

  .sendbar { flex-direction: column-reverse; align-items: stretch; }
  .sendbar__note { margin-right: 0; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ============================================================================
   Template gallery, browse dialog, and activity dashboard.
   Every colour is an existing token, so light mode comes free. The only hardcoded
   value is the ::backdrop scrim — custom properties are not reliably readable there
   across engines (same documented exception class as .mailcard).
   ============================================================================ */

/* --- shell + shared ------------------------------------------------------- */
/* .rail__item is now used on <a> as well as <span>/<button>. */
.rail__item { text-decoration: none; }

/* Full-page scrolling screens (gallery, activity). .screen is flex/overflow:hidden. */
.screen--scroll { overflow-y: auto; padding-bottom: 28px; }
/* A pane that is a page section rather than a .workspace grid cell. flex:none so the
   PAGE scrolls and panes size to content — no nested scroll container to trap the wheel. */
.pane--flat { flex: none; min-height: 0; overflow-y: visible; gap: 14px; }
.pane__foot { margin: 4px 0 0; font-size: 11.5px; color: var(--text-subtle); }

/* Pane headers get a defined band instead of floating text. */
.pane > .seclabel,
.pane .side__head { padding-bottom: 11px; border-bottom: 1px solid var(--border); }

a.linkbtn { text-decoration: none; }
a.linkbtn:hover { text-decoration: underline; }

/* --- template cards ------------------------------------------------------- */
.tplrow { display: flex; align-items: center; gap: 8px; }
.tplrow .select { flex: 1; min-width: 0; }
#templateHint { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--text-subtle); text-wrap: pretty; }
#templateHint:empty { display: none; }

.tplgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(224px, 1fr)); gap: 12px; }

.tplcard {
  position: relative; display: flex; flex-direction: column; gap: 7px; padding: 12px;
  font: inherit; text-align: left; color: var(--text); text-decoration: none; cursor: pointer;
  background: var(--surface);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 100px);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow-sm);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.2s ease, transform 0.12s ease;
}
@media (hover: hover) {
  .tplcard:hover {
    transform: translateY(-2px); border-color: var(--border-strong);
    box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow), 0 16px 38px -22px var(--brand-glow);
  }
}
.tplcard:active { transform: translateY(0); }
.tplcard:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.tplcard.is-current { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 40%, var(--surface)); }
.tplcard.is-current .tplcard__name { color: var(--accent); }
.tplcard.is-current .tplcard__check { opacity: 1; transform: scale(1); }

/* CSS-drawn wireframe, deliberately NOT an iframe render: 8 sandboxed frames plus the
   live preview on the hottest page is far too costly, and template HTML is table-based
   with absolute widths that fight a 224px card. */
.tplcard__thumb {
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
  height: 76px; padding: 11px 12px; overflow: hidden;
  background: var(--bg-accent); border: 1px solid var(--border); border-radius: 8px;
}
.tplcard__bar { height: 8px; border-radius: 2px; background: linear-gradient(90deg, var(--brand-1), var(--brand-2)); opacity: 0.8; }
.tplcard__ln { height: 4px; border-radius: 2px; background: var(--border-strong); opacity: 0.8; }
.tplcard__cta { width: 52px; height: 10px; margin-top: 2px; border-radius: 3px; background: linear-gradient(180deg, var(--btn-top), var(--btn-bg)); opacity: 0.9; }

.tplcard__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.tplcard__name { font-size: 13.5px; font-weight: 700; letter-spacing: -0.01em; }
.tplcard__subject { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tplcard__desc { font-size: 11.5px; line-height: 1.45; color: var(--text-subtle); text-wrap: pretty; }
.tplcard__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: auto; padding-top: 6px; }
.tplcard__ph { padding: 2px 6px; font-family: var(--font-mono); font-size: 10px; color: var(--text-subtle); background: var(--bg-accent); border: 1px solid var(--border); border-radius: 5px; }
.tplcard__more { font-size: 10.5px; font-weight: 600; color: var(--text-subtle); }
.tplcard__check {
  position: absolute; top: 9px; right: 9px; display: grid; place-items: center;
  width: 19px; height: 19px; color: #fff; border-radius: 50%;
  background: linear-gradient(150deg, var(--brand-1), var(--brand-2));
  opacity: 0; transform: scale(0.7); transition: opacity 0.15s ease, transform 0.15s ease;
}

/* --- browse dialog -------------------------------------------------------- */
.tplmodal {
  width: min(880px, calc(100vw - 32px)); max-height: min(74vh, 700px); padding: 0;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow-lg);
  animation: rise-in 0.3s cubic-bezier(0.2, 0.7, 0.25, 1) both;
}
.tplmodal::backdrop { background: rgba(9, 6, 14, 0.62); backdrop-filter: blur(2px); }
.tplmodal__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; background: var(--surface-raised);
  border-bottom: 1px solid var(--border); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.tplmodal__act { display: flex; align-items: center; gap: 12px; }
.tplmodal__body { padding: 16px 18px 20px; overflow-y: auto; }

/* --- activity: stat strip ------------------------------------------------- */
/* Four stats sharing one object; hairline seams come from the 1px gap over --border. */
.statstrip {
  flex: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px; padding: 1px; overflow: hidden;
  background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow);
  animation: rise-in 0.5s cubic-bezier(0.2, 0.7, 0.25, 1) 0.04s both;
}
.stat {
  display: flex; flex-direction: column; gap: 3px; padding: 15px 18px 16px;
  background: var(--surface);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 90px);
}
.stat__label { font-size: 11px; font-weight: 750; letter-spacing: 0.13em; text-transform: uppercase; color: var(--text-subtle); }
.stat__value { font-size: 30px; font-weight: 750; line-height: 1.08; letter-spacing: -0.03em; color: var(--text); font-variant-numeric: tabular-nums; }
.stat__foot { font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.actgrid { flex: none; display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.chartpane { animation-delay: 0.1s; }
.sendspane { animation-delay: 0.16s; }

/* --- activity: 7-day chart (bar heights are precomputed server-side) ------- */
.spark { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; padding-top: 2px; }
.spark__col { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.spark__n { font-size: 11.5px; font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.spark__track { width: 100%; height: 108px; display: flex; align-items: flex-end; background: var(--bg-accent); border-radius: 7px; overflow: hidden; }
.spark__bar {
  width: 100%; border-radius: 7px 7px 0 0; transform-origin: bottom;
  background: linear-gradient(180deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 0 14px -4px var(--brand-glow);
  animation: spark-grow 0.55s cubic-bezier(0.2, 0.7, 0.25, 1) both;
}
.spark__col.is-empty .spark__bar { height: 3px; background: var(--border-strong); box-shadow: none; border-radius: 2px; }
.spark__col.is-empty .spark__n { color: var(--text-subtle); }
.spark__lbl { font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-subtle); }
@keyframes spark-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }

/* --- activity: recent sends table ----------------------------------------- */
.sends__scroll { overflow-x: auto; }
.sends { width: 100%; border-collapse: collapse; font-size: 13px; }
.sends th {
  padding: 0 10px 8px; text-align: left; white-space: nowrap;
  font-size: 10.5px; font-weight: 750; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-subtle); border-bottom: 1px solid var(--border);
}
.sends td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.sends tbody tr { transition: background 0.15s ease; }
.sends tbody tr:hover { background: var(--surface-raised); }
.sends tbody tr:last-child td { border-bottom: none; }
.sends__c { width: 1%; text-align: center; white-space: nowrap; }
.sends__time { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-subtle); white-space: nowrap; font-variant-numeric: tabular-nums; }
/* max-width:0 with a % width is what makes text-overflow work under table-layout:auto. */
.sends__subject { width: 38%; max-width: 0; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sends__to, .sends__from { width: 22%; max-width: 0; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sends__addr { font-family: var(--font-mono); font-size: 11.5px; }
.sends__plus { margin-left: 5px; padding: 1px 5px; font-size: 10px; font-weight: 700; color: var(--tag-text); background: var(--tag-bg); border-radius: 999px; }

/* Alignment state is text + dot + colour + title, never colour alone. */
.dotstate { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: var(--warn-text); }
.dotstate::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--warn-solid); }
.dotstate[data-aligned="true"] { color: var(--success); }
.dotstate[data-aligned="true"]::before { background: var(--success); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 9px; padding: 42px 20px 46px; text-align: center; }
.empty__mark { display: grid; place-items: center; width: 46px; height: 46px; color: #fff; border-radius: 14px; background: linear-gradient(150deg, var(--brand-1), var(--brand-2)); box-shadow: 0 12px 30px -12px var(--brand-glow); }
.empty__title { margin: 4px 0 0; font-size: 15px; font-weight: 700; }
.empty__sub { margin: 0 0 8px; font-size: 13px; color: var(--text-muted); }

/* --- compose polish ------------------------------------------------------- */
/* .sendbar__note originally carried margin-right:auto; that role moves to the group.
   The original rule stays because activity reuses .sendbar__note standalone. */
.sendbar__notes { margin-right: auto; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; }
.sendbar__note { margin-right: 0; }
.sendbar__note b { color: var(--text-muted); font-weight: 700; }
.sendbar__note--limit { font-size: 11px; }

.fld__count { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.fld__count.is-near { color: var(--warn-text); }

/* Sending state: keep the icon, spin it, swap only the word. */
.btn.is-busy svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- responsive for the new components -------------------------------------
   These MUST live after the base rules above. Media queries add no specificity,
   so an equally-specific base rule later in the file would otherwise win and the
   breakpoints would silently do nothing.
   --------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .screen--scroll { overflow: visible; padding-bottom: 24px; }
  .actgrid { grid-template-columns: 1fr; }
  .statstrip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .statstrip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 13px 14px 14px; }
  .stat__value { font-size: 25px; }
  .spark { gap: 5px; }
  .spark__track { height: 84px; }
  .spark__lbl { font-size: 9.5px; letter-spacing: 0.03em; }

  /* Table collapses to stacked rows. thead is clipped rather than display:none so it
     stays in the accessibility tree. The td.* prefixes are required: `.sends td` (0,1,1)
     beats a bare `.sends__from` (0,1,0) and would force display:block back on. */
  .sends thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .sends, .sends tbody, .sends tr, .sends td { display: block; width: auto; }
  .sends tr { padding: 11px 2px; border-bottom: 1px solid var(--border); }
  .sends td { padding: 1px 0; border: none; max-width: none; width: auto; white-space: normal; }
  td.sends__subject { font-size: 13.5px; white-space: normal; }
  td.sends__from { display: none; }
  td.sends__c { display: inline-block; width: auto; margin: 5px 8px 0 0; text-align: left; }

  .tplgrid { grid-template-columns: 1fr; }
  .tplcard__thumb { height: 62px; }
  .tplmodal {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
    margin: 0; border: none; border-radius: 0;
  }
  .tplmodal__head { position: sticky; top: 0; z-index: 1; border-radius: 0; }
  .tplrow { flex-wrap: wrap; }
  .tplrow .select { flex: 1 1 100%; }
  /* Opt out of the blanket .btn { width:100% } at this width. */
  .tplrow .btn, .tplmodal__act .btn, .empty .btn { width: auto; min-height: 36px; }
  .empty { padding: 32px 16px 36px; }
  .sendbar__notes { margin-right: 0; justify-content: center; }
}

/* ============================================================================
   Template manager: brand groups, per-card actions, and the inline editor.
   ============================================================================ */

/* Group headers span the whole grid, so one .tplgrid renders every group and the
   card columns stay aligned across groups. */
.tplgrid__gh {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 6px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
}
.tplgrid__gh:first-child { margin-top: 0; }
.tplgrid__gname {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* The card and its action cluster are siblings; the cell is the positioning context. */
.tplcell { position: relative; display: flex; }
.tplcell > .tplcard { flex: 1; min-width: 0; }

.tplcell__act {
  position: absolute;
  top: 9px;
  left: 9px;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
/* Always visible on touch/keyboard; hover-reveal is a pointer nicety only. */
.tplcell:focus-within .tplcell__act,
.tplcell:hover .tplcell__act { opacity: 1; }
@media (hover: none) {
  .tplcell__act { opacity: 1; }
}
.tplcell__del { display: flex; margin: 0; }

.iconbtn {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--text-muted);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.iconbtn:hover { color: var(--text); background: var(--bg-accent); border-color: var(--border-strong); }
.iconbtn:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.iconbtn--danger:hover { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }

.tplcell__lock {
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.pagehead__act { margin-top: 12px; }
.pagehead__act .btn { width: auto; }

/* Segmented control built from real radios — works with JS off. Mirrors .toggle__btn. */
.toggle--radio { position: relative; }
.toggle__in {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.toggle--radio .toggle__btn { display: inline-block; user-select: none; }
.toggle__in:checked + .toggle__btn {
  color: var(--text);
  background: var(--surface-raised);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow-sm);
}
.toggle__in:focus-visible + .toggle__btn {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* The editor reuses .workspace, but on a SCROLLING page it must size to content rather
   than fill a fixed-height .screen. */
.tpledit {
  flex: none;
  margin-bottom: 18px;
  min-height: 520px;
}
.tpledit .pane { overflow-y: visible; }
.tpledit .textarea--grow { min-height: 240px; }
#tplEditorForm { flex: none; display: flex; flex-direction: column; gap: 14px; }
#tplEditorForm .sendbar { margin-bottom: 20px; }
#tplPh:empty::after {
  content: "none yet — add {{tokens}} to the subject or body";
  font-size: 11.5px;
  color: var(--text-subtle);
}

@media (max-width: 900px) {
  .tpledit { min-height: 0; }
}

/* ============================================================================
   .pick — styled dropdown replacing the native <select> look, open list included.
   The native select stays in the DOM (form value + no-JS fallback), just hidden.
   ============================================================================ */
.pick { position: relative; display: block; min-width: 0; }
.pick__native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
}

.pick__btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.pick__btn:hover { border-color: var(--border-strong); }
.pick__btn:focus-visible,
.pick__btn[aria-expanded="true"] {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.pick--tiny .pick__btn { padding: 6px 9px; font-size: 12.5px; }

.pick__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick__label.is-placeholder { color: var(--text-subtle); }
.pick__caret { display: grid; place-items: center; color: var(--text-subtle); transition: transform 0.18s ease; }
.pick__btn[aria-expanded="true"] .pick__caret { transform: rotate(180deg); color: var(--accent); }

/* Appended to <body> and fixed, so .screen / .workspace / .pane overflow can't clip it. */
.pick__pop {
  position: fixed;
  z-index: 60;
  padding: 5px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow-lg);
  animation: pick-in 0.14s cubic-bezier(0.2, 0.7, 0.25, 1) both;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
@keyframes pick-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.pick__group {
  padding: 9px 9px 5px;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-subtle);
}
.pick__group:first-child { padding-top: 4px; }

.pick__opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  font-size: 13.5px;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
}
.pick__optlabel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick__opt.is-active { color: var(--text); background: var(--surface-raised); }
.pick__opt.is-selected { color: var(--accent); font-weight: 650; }
.pick__opt.is-selected.is-active { background: var(--accent-soft); }

@media (max-width: 560px) {
  .pick__pop { max-height: 52vh; }
  .pick__opt { padding: 10px 9px; }
}

/* ============================================================================
   Public donation page. Uses the centred .page/.hero archetype (no rail — it is
   reachable logged out). QR codes are inline SVG inheriting currentColor, so they
   work in light and dark with no image request.
   ============================================================================ */
.page--wide .shell { max-width: 980px; }

.tg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 7px;
  font-weight: 650;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.tg:hover { color: var(--accent-hover); border-color: var(--accent); }
.tg:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.donate__intro {
  margin: 10px 0 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

.coins {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 22px;
}

.coin {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 16px;
  background: var(--surface);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 110px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow);
  animation: rise-in 0.5s cubic-bezier(0.2, 0.7, 0.25, 1) both;
}
.coin:nth-child(2) { animation-delay: 0.05s; }
.coin:nth-child(3) { animation-delay: 0.1s; }
.coin:nth-child(4) { animation-delay: 0.15s; }

.coin__head { display: flex; align-items: center; gap: 10px; }
.coin__ticker {
  display: grid;
  place-items: center;
  min-width: 46px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fff;
  border-radius: 8px;
  /* Each coin gets its own hue so two addresses can never be visually confused. */
  background: linear-gradient(150deg, #f7931a, #d97b0d);
}
.coin__ticker--eth { background: linear-gradient(150deg, #8a92b2, #5b6484); }
.coin__ticker--xrp { background: linear-gradient(150deg, #4a5568, #23292f); }
.coin__ticker--xmr { background: linear-gradient(150deg, #ff8f4a, #f26822); }

.coin__meta { display: flex; flex-direction: column; min-width: 0; }
.coin__name { font-size: 14.5px; font-weight: 700; letter-spacing: -0.01em; }
.coin__net { font-size: 11px; color: var(--text-subtle); }

/* Deliberately NOT themed. A QR must be dark modules on a light background: following
   the dark theme inverts it (light-on-dark), which a good number of scanners refuse to
   read. A donation QR that will not scan is worse than an ugly one, so this stays white
   in both themes and `color` drives the SVG's currentColor modules. */
.coin__qr {
  display: grid;
  place-items: center;
  padding: 12px;
  color: #0b0a0f;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
}
/* The QR is one inline <svg>; sizing it here keeps the markup free of style attrs. */
.coin__qr svg { width: 100%; max-width: 168px; height: auto; display: block; }

.coin__addrlabel {
  font-size: 10.5px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-subtle);
}
.coin__addrrow { display: flex; align-items: center; gap: 7px; }
.coin__addr {
  flex: 1;
  min-width: 0;
  font-size: 11.5px;
  padding: 8px 9px;
  /* Readonly, but selectable — the no-JS copy path. */
  cursor: text;
}
.coin__addrrow .btn { flex: none; }
.copybtn.is-copied { color: var(--success); border-color: var(--success-border); }

@media (max-width: 560px) {
  .coins { grid-template-columns: 1fr; }
  .coin__addrrow { flex-wrap: wrap; }
  .coin__addr { flex: 1 1 100%; }
  .coin__addrrow .btn { width: auto; min-height: 36px; }
}

/* ============================================================================
   Custom background + glass panels.

   The whole feature is driven by three custom properties that partials/head.ejs
   only defines when a background image exists (--app-bg, --app-dim, --panel-bg,
   --panel-blur). Every rule below falls back to the existing solid value, so with
   no background the UI renders exactly as before and no view needs a body class.
   ============================================================================ */

/* The image sits on a fixed layer behind everything, with a scrim over it. Text has to
   stay readable over an arbitrary photo, so the scrim is not optional — its strength is
   the "dim" setting. body::before already paints the aurora; this is a second layer. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background-image: var(--app-bg, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* The scrim. Sits between the photo and the UI. */
body::before {
  background-color: color-mix(in srgb, var(--bg) calc(var(--app-dim, 0) * 100%), transparent);
}

/* --- glass surfaces ------------------------------------------------------- */
/* Each of these already had a solid background; the var() fallback keeps it. */
.pane,
.card,
.statstrip,
.stat,
.coin,
.tplcard,
.tplmodal,
.sendbar,
.mini,
.pick__pop {
  background-color: var(--panel-bg, var(--surface));
  backdrop-filter: var(--panel-blur, none);
  -webkit-backdrop-filter: var(--panel-blur, none);
}

/* The rail and the alert strip get the same treatment but keep their own tints. */
.rail {
  background-color: var(--panel-bg, var(--rail-bg));
  backdrop-filter: var(--panel-blur, none);
  -webkit-backdrop-filter: var(--panel-blur, none);
}

/* Inputs stay more opaque than panels: a translucent field over a busy photo is where
   legibility actually breaks down first. */
.input,
.select,
.pick__btn {
  background-color: color-mix(in srgb, var(--input-bg) 92%, transparent);
}


/* --- the appearance settings page ----------------------------------------- */
.bgpreview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 190px;
  padding: 18px;
  overflow: hidden;
  background-color: var(--bg-accent);
  background-image: var(--app-bg, none);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.bgpreview__card {
  padding: 14px 18px;
  text-align: center;
  background-color: var(--panel-bg, var(--surface));
  backdrop-filter: var(--panel-blur, none);
  -webkit-backdrop-filter: var(--panel-blur, none);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.bgpreview__title { font-size: 14px; font-weight: 700; }
.bgpreview__sub { font-size: 11.5px; color: var(--text-muted); }
.bgpreview__empty { font-size: 13px; color: var(--text-subtle); }

.bgmeta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 11.5px;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

.filefield {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}
.filefield input[type="file"] {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--input-bg);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}
.filefield input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  cursor: pointer;
}

.range { display: flex; align-items: center; gap: 10px; }
.range input[type="range"] { flex: 1; accent-color: var(--accent); }
.range__val {
  min-width: 44px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

@media (max-width: 560px) {
  .filefield input[type="file"] { flex: 1 1 100%; }
  .filefield .btn { width: auto; }
}

/* A failed send: marked by text + colour + a tooltip carrying the SMTP error, never
   colour alone. Reuses the existing danger token so light mode comes free. */
.dotstate--bad { color: var(--danger); }
.dotstate--bad::before { background: var(--danger); }
.sends tbody tr.is-failed .sends__subject { color: var(--text-muted); text-decoration: line-through; text-decoration-thickness: 1px; }

/* =========================================================================
   Compose enhancements: file upload, over-cap warnings, draft bar,
   placeholders editor. All progressive — hidden/unused when JS is off.
   ========================================================================= */

/* label row that carries an action (upload .html) on the right */
.fld__label--row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.fld__actions { display: inline-flex; align-items: center; gap: 12px; }

/* the "upload .html" trigger is a <label for> a hidden file input */
.filein { cursor: pointer; }
.filein::before {
  content: "";
  display: inline-block;
  width: 12px; height: 12px;
  margin-right: 5px;
  vertical-align: -1px;
  background: currentColor;
  -webkit-mask: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v12'/%3E%3Cpath d='m7 8 5-5 5 5'/%3E%3Cpath d='M5 21h14'/%3E%3C/svg%3E");
  mask: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v12'/%3E%3Cpath d='m7 8 5-5 5 5'/%3E%3Cpath d='M5 21h14'/%3E%3C/svg%3E");
}

/* inline over-cap warning under a field */
.fld__warn {
  margin: 7px 0 0;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: 8px;
}

/* the Send button's blocked state + the short label beside it */
.btn.is-blocked { opacity: 0.5; cursor: not-allowed; }
.sendbar__block {
  font-size: 12px;
  font-weight: 700;
  color: var(--danger);
  white-space: nowrap;
}

/* unsaved-draft restore bar */
.draftbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--accent-soft);
  border: 1px solid var(--surface-edge);
  border-radius: 10px;
}
.draftbar__act { display: inline-flex; align-items: center; gap: 12px; flex: none; }

/* placeholders editor */
.phed { display: flex; flex-direction: column; gap: 7px; padding-top: 9px; }
.phed__row { display: grid; grid-template-columns: minmax(90px, 0.4fr) 1fr auto; gap: 8px; align-items: center; }
.phed__row .phed__key { color: var(--text-muted); }
.phed__row .phed__key[readonly] { opacity: 0.75; cursor: default; }
.phed__rm {
  flex: none;
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; line-height: 1;
  color: var(--text-subtle);
  background: transparent;
  border: 1px solid var(--surface-edge);
  border-radius: 7px;
  cursor: pointer;
}
.phed__rm:hover { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
.phed__add { align-self: flex-start; margin-top: 2px; }

@media (max-width: 560px) {
  .phed__row { grid-template-columns: 1fr auto; }
  .phed__row .phed__key { grid-column: 1 / -1; }
}
