/*
  app.css — component styling and motion for Postio, built entirely on the
  Pelton tokens. Restraint from Pelton (hairline borders, 5px radii, subtle
  surfaces, Familjen Grotesk / Spline Sans Mono) plus the tasteful animation the
  brief asked for. Every animation is gated by base.css's reduce-motion rules.
*/

/* ------------------------------------------------------------------ motion */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in-down {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pop-in {
  /* no overshoot past 1.0 — an overshoot briefly scales a full-width card past
     the viewport and flashes a scrollbar. */
  0% { opacity: 0; transform: scale(0.975); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes grow-bar {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}
@keyframes frame-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes row-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes shimmer {
  100% { transform: translateX(100%); }
}
@keyframes dot-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  70% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 0%, transparent); }
}
@keyframes accent-breathe {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 34%, transparent); }
  50% { box-shadow: 0 0 22px 2px color-mix(in srgb, var(--accent) 26%, transparent); }
}
@keyframes check-draw {
  from { stroke-dashoffset: 32; }
  to { stroke-dashoffset: 0; }
}

/* --------------------------------------------------------------- app root */
.app {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* view fade used when the SPA swaps top-level scenes. */
.view-enter { animation: view-in 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both; }

/* ------------------------------------------------------------- primitives */
.muted { color: var(--text-tertiary); }
.mono { font-family: var(--font-mono); }
.grow { flex: 1; min-width: 0; }
.rowflex { display: flex; align-items: center; gap: var(--space-3); }
.stack { display: flex; flex-direction: column; gap: var(--stack-gap); }
.center { display: flex; align-items: center; justify-content: center; }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }

hr.divider {
  border: none;
  border-top: var(--hairline) solid var(--border-subtle);
  margin: var(--space-4) 0;
}

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-height);
  padding: 0 var(--space-4);
  border-radius: var(--radius-control);
  border: var(--hairline) solid var(--border-default);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-size: var(--fz-body);
  font-weight: var(--fw-medium);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:active { transform: translateY(0.5px) scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
}
.btn.primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, black);
  box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--accent) 60%, transparent);
}
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border-default)); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-hover); }
.btn.subtle { background: var(--surface-sunken); border-color: transparent; }
.btn.block { width: 100%; }
.btn.sm { height: 26px; padding: 0 var(--space-3); font-size: var(--fz-label); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  border-radius: var(--radius-control);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.08s ease;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn.on { color: var(--accent); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-bg); }

/* --------------------------------------------------------------- form bits */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field > label {
  font-size: var(--fz-label);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}
.hint { font-size: var(--fz-meta); color: var(--text-tertiary); line-height: 1.4; }

.input, .select, .textarea {
  width: 100%;
  height: var(--control-height);
  padding: 0 var(--space-3);
  background: var(--surface-sunken);
  border: var(--hairline) solid var(--border-default);
  border-radius: var(--radius-control);
  color: var(--text-primary);
  font-size: var(--fz-body);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.textarea { height: auto; min-height: 120px; padding: var(--space-3); resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-raised);
  box-shadow: 0 0 0 3px var(--selection-bg);
}
.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); }
.select { appearance: none; cursor: pointer; padding-right: var(--space-6); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.row-host { display: grid; grid-template-columns: 1fr 92px 96px; gap: var(--space-3); align-items: end; }
@media (max-width: 560px) { .row2, .row-host { grid-template-columns: 1fr; } }

/* toggle switch */
.switch { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 22px; border-radius: 999px;
  background: var(--surface-hover);
  border: var(--hairline) solid var(--border-default);
  position: relative; flex-shrink: 0;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 999px;
  background: var(--text-inverse);
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.switch input:checked + .track { background: var(--accent); border-color: transparent; }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--selection-bg); }
.switch .switch-label { display: flex; flex-direction: column; gap: 1px; }
.switch .switch-label b { font-weight: var(--fw-medium); font-size: var(--fz-body); }

/* segmented control */
.seg { display: inline-flex; background: var(--surface-sunken); border: var(--hairline) solid var(--border-default); border-radius: var(--radius-control); padding: 2px; gap: 2px; }
.seg button {
  border: none; background: transparent; color: var(--text-secondary);
  padding: 4px 12px; border-radius: calc(var(--radius-control) - 1px);
  font-size: var(--fz-label); font-weight: var(--fw-medium); cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg button:hover { color: var(--text-primary); }
.seg button.on { background: var(--surface-raised); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }

/* accent swatches */
.swatches { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.swatch {
  width: 26px; height: 26px; border-radius: 999px; cursor: pointer;
  border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
  transition: transform 0.12s ease;
}
.swatch:hover { transform: scale(1.12); }
.swatch.on { border-color: var(--text-primary); }

/* tag / badge */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fz-meta); font-weight: var(--fw-medium);
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-sunken); color: var(--text-secondary);
  border: var(--hairline) solid var(--border-subtle);
}
.tag.accent { background: var(--selection-bg); color: var(--link); border-color: transparent; }
.tag.ok { background: var(--success-bg); color: var(--success); border-color: transparent; }
.tag.warn { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.tag.err { background: var(--danger-bg); color: var(--danger); border-color: transparent; }

/* inline alert */
.alert {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-card);
  font-size: var(--fz-label); line-height: 1.5;
  animation: fade-in-down 0.2s ease both;
}
.alert.err { background: var(--danger-bg); color: var(--danger); }
.alert.ok { background: var(--success-bg); color: var(--success); }
.alert.warn { background: var(--warning-bg); color: var(--warning); }
.alert.info { background: var(--selection-bg); color: var(--link); }
.alert .icon { margin-top: 1px; }

/* spinner */
.ring {
  width: 22px; height: 22px; border-radius: 999px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
.ring.lg { width: 34px; height: 34px; border-width: 3px; }

/* skeleton shimmer */
.skeleton {
  position: relative; overflow: hidden;
  background: var(--surface-sunken); border-radius: var(--radius-control);
}
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text-tertiary) 12%, transparent), transparent);
  animation: shimmer 1.3s infinite;
}

/* ============================================================ AUTH / SETUP */
.scene {
  flex: 1; min-height: 0; overflow: auto;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-6);
  background:
    radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 60%),
    var(--surface-base);
}

.brand { display: inline-flex; align-items: center; gap: var(--space-3); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-fg);
  animation: accent-breathe 4s ease-in-out infinite;
}
.brand-name { font-size: var(--fz-title); font-weight: var(--fw-bold); letter-spacing: -0.01em; }

.auth {
  width: 100%; max-width: 440px;
  background: var(--surface-raised);
  border: var(--hairline) solid var(--border-default);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-overlay);
  overflow: hidden;
  animation: pop-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.auth-head { padding: var(--space-6) var(--space-6) var(--space-4); }
.auth-head h1 { margin: var(--space-4) 0 var(--space-1); font-size: var(--fz-title); font-weight: var(--fw-bold); }
.auth-head p { margin: 0; color: var(--text-tertiary); font-size: var(--fz-label); }
.auth-body { padding: 0 var(--space-6) var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }

/* login tabs */
.tabs { display: flex; gap: var(--space-2); padding: 3px; background: var(--surface-sunken); border-radius: var(--radius-control); margin: 0 var(--space-6) var(--space-5); }
.tab {
  flex: 1; text-align: center; padding: 7px; border-radius: calc(var(--radius-control) - 1px);
  font-size: var(--fz-label); font-weight: var(--fw-semibold); color: var(--text-tertiary);
  cursor: pointer; border: none; background: transparent;
  transition: background 0.18s ease, color 0.18s ease;
}
.tab.on { background: var(--surface-raised); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,0.1); }

/* ----------------------------------------------------------------- wizard */
.wizard {
  width: 100%; max-width: 720px;
  background: var(--surface-raised);
  border: var(--hairline) solid var(--border-default);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-overlay);
  overflow: hidden;
  display: grid; grid-template-columns: 232px 1fr;
  animation: pop-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@media (max-width: 640px) { .wizard { grid-template-columns: 1fr; } }

.wizard-rail {
  background: var(--surface-sunken);
  border-right: var(--hairline) solid var(--border-subtle);
  padding: var(--space-6) var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-5);
}
@media (max-width: 640px) { .wizard-rail { flex-direction: row; overflow-x: auto; padding: var(--space-4); gap: var(--space-4); } }
.wizard-rail .brand { margin-bottom: var(--space-4); }
@media (max-width: 640px) { .wizard-rail .brand { display: none; } }

.wiz-steps { display: flex; flex-direction: column; gap: var(--space-1); }
@media (max-width: 640px) { .wiz-steps { flex-direction: row; gap: var(--space-4); } }
.wiz-step {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-2);
  color: var(--text-tertiary); font-size: var(--fz-label); font-weight: var(--fw-medium);
  border-radius: var(--radius-control);
  transition: color 0.2s ease;
}
.wiz-step .dot {
  width: 22px; height: 22px; border-radius: 999px; flex-shrink: 0;
  display: grid; place-items: center; font-size: var(--fz-meta); font-weight: var(--fw-semibold);
  background: var(--surface-hover); color: var(--text-tertiary);
  border: var(--hairline) solid var(--border-default);
  transition: background 0.25s ease, color 0.25s ease, transform 0.25s ease;
}
.wiz-step.active { color: var(--text-primary); }
.wiz-step.active .dot { background: var(--accent); color: var(--accent-fg); border-color: transparent; transform: scale(1.06); }
.wiz-step.done .dot { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--link); border-color: transparent; }

.wizard-main { display: flex; flex-direction: column; min-width: 0; }
.wizard-head { padding: var(--space-6) var(--space-6) var(--space-3); }
.wizard-title { font-size: var(--fz-heading); font-weight: var(--fw-bold); margin: 0 0 var(--space-1); }
.wizard-sub { color: var(--text-tertiary); font-size: var(--fz-label); margin: 0; line-height: 1.5; }
.wizard-content {
  padding: var(--space-4) var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-4);
  min-height: 260px;
  animation: fade-in-up 0.32s ease both;
}
.wizard-foot {
  margin-top: auto;
  padding: var(--space-4) var(--space-6) var(--space-6);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  border-top: var(--hairline) solid var(--border-subtle);
}

/* review list on the last step */
.review { display: flex; flex-direction: column; gap: 0; border: var(--hairline) solid var(--border-subtle); border-radius: var(--radius-card); overflow: hidden; }
.review .kv { display: flex; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) var(--space-4); }
.review .kv:nth-child(odd) { background: var(--surface-sunken); }
.review .kv b { font-weight: var(--fw-medium); color: var(--text-secondary); font-size: var(--fz-label); }
.review .kv span { color: var(--text-primary); font-size: var(--fz-label); text-align: right; }

/* success check */
.done-check { width: 56px; height: 56px; }
.done-check circle { fill: none; stroke: var(--success); stroke-width: 2; opacity: 0.25; }
.done-check path { fill: none; stroke: var(--success); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 32; animation: check-draw 0.5s ease 0.15s both; }

/* ============================================================= MAIL SHELL */
.mail { flex: 1; min-height: 0; display: grid; grid-template-columns: 248px 380px 1fr; grid-template-rows: minmax(0, 1fr); }
@media (max-width: 1080px) { .mail { grid-template-columns: 220px 340px 1fr; } }
@media (max-width: 860px) { .mail.reading { grid-template-columns: 0 0 1fr; } .mail:not(.reading) { grid-template-columns: 64px 1fr 0; } }

/* ---- sidebar ---- */
.sidebar {
  background: var(--surface-base);
  border-right: var(--hairline) solid var(--border-default);
  display: flex; flex-direction: column; min-width: 0;
  padding: var(--space-4) var(--space-3);
  gap: var(--space-4);
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--space-2); }
.side-brand { display: flex; align-items: center; gap: var(--space-3); font-weight: var(--fw-bold); font-size: var(--fz-heading); }
.side-brand .brand-mark { width: 26px; height: 26px; border-radius: 7px; animation: none; }

.compose-btn { width: 100%; }

.folders { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; min-height: 0; }
.folder {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--row-pad-y) var(--space-3);
  border-radius: var(--radius-control);
  color: var(--text-secondary); cursor: pointer;
  font-size: var(--fz-body); font-weight: var(--fw-medium);
  position: relative;
  transition: background 0.14s ease, color 0.14s ease;
  animation: fade-in 0.3s ease both;
}
.folder:hover { background: var(--surface-hover); color: var(--text-primary); }
.folder.active { background: var(--selection-bg); color: var(--link); }
.folder.active::before {
  content: ""; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; border-radius: 3px; background: var(--accent);
  transform-origin: center; animation: grow-bar 0.22s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.folder .icon { color: currentColor; }
.folder .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { font-size: var(--fz-meta); color: var(--text-tertiary); font-variant-numeric: tabular-nums; }

.side-account {
  border-top: var(--hairline) solid var(--border-subtle);
  padding-top: var(--space-3);
  display: flex; align-items: center; gap: var(--space-3);
}
.side-account .avatar { width: 28px; height: 28px; font-size: var(--fz-label); }
.side-account .who { flex: 1; min-width: 0; }
.side-account .who b { display: block; font-size: var(--fz-label); font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-account .who span { font-size: var(--fz-meta); color: var(--text-tertiary); }

/* ---- message list column ---- */
.listcol {
  background: var(--surface-raised);
  border-right: var(--hairline) solid var(--border-default);
  display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0;
}
.list-head { padding: var(--space-3); border-bottom: var(--hairline) solid var(--border-subtle); display: flex; flex-direction: column; gap: var(--space-3); }
.list-head-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.list-title { font-size: var(--fz-heading); font-weight: var(--fw-bold); display: flex; align-items: center; gap: var(--space-2); }
.list-title .count { font-size: var(--fz-meta); color: var(--text-tertiary); font-weight: var(--fw-regular); }
.searchbar { position: relative; display: flex; align-items: center; }
.searchbar .icon { position: absolute; left: var(--space-3); color: var(--text-tertiary); pointer-events: none; }
.searchbar input { padding-left: 32px; height: 32px; }

.msglist { overflow-y: auto; min-height: 0; }
.msg {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: var(--space-3); row-gap: 2px;
  padding: var(--row-pad-y) var(--row-pad-x);
  border-bottom: var(--hairline) solid var(--border-subtle);
  cursor: pointer; position: relative;
  transition: background 0.13s ease;
  animation: row-in 0.28s ease both;
  animation-delay: calc(var(--i, 0) * 22ms);
}
.msg:hover { background: var(--surface-hover); }
.msg.active { background: var(--selection-bg); }
.msg.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.msg-dot {
  grid-row: 1 / 3; align-self: center;
  width: 8px; height: 8px; border-radius: 999px; background: transparent;
}
.msg.unread .msg-dot { background: var(--accent); animation: dot-pulse 2.4s ease-out infinite; }
.msg-from { grid-column: 2; font-size: var(--fz-list); color: var(--text-secondary); font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .msg-from { color: var(--text-primary); font-weight: var(--fw-semibold); }
.msg-date { grid-column: 3; grid-row: 1; font-size: var(--fz-meta); color: var(--text-tertiary); white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg-subject { grid-column: 2; grid-row: 2; font-size: var(--fz-list); color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .msg-subject { font-weight: var(--fw-semibold); }
.msg-meta { grid-column: 3; grid-row: 2; display: flex; align-items: center; gap: 6px; justify-content: flex-end; color: var(--text-tertiary); }
.msg-star { color: var(--text-tertiary); display: inline-flex; }
.msg-star.on { color: var(--warning); }
.msg-star.on .icon { fill: var(--warning); }

/* empty & loading states in list */
.list-empty { padding: var(--space-6); text-align: center; color: var(--text-tertiary); display: flex; flex-direction: column; align-items: center; gap: var(--space-3); animation: fade-in 0.3s ease both; }
.sk-row { display: flex; flex-direction: column; gap: 6px; padding: var(--row-pad-y) var(--row-pad-x); border-bottom: var(--hairline) solid var(--border-subtle); }
.sk-row .a { height: 11px; width: 40%; }
.sk-row .b { height: 11px; width: 80%; }

/* ---- detail column ---- */
.detailcol { background: var(--surface-base); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.detail-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); color: var(--text-tertiary); animation: fade-in 0.4s ease both; }
.detail-empty .brand-mark { width: 46px; height: 46px; border-radius: 12px; opacity: 0.9; }

.detail { flex: 1; display: flex; flex-direction: column; min-height: 0; animation: fade-in-up 0.3s ease both; }
.detail-bar {
  display: flex; align-items: center; gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--hairline) solid var(--border-subtle);
}
.detail-bar .grow { display: flex; }
.detail-head { padding: var(--pane-pad) var(--pane-pad) var(--space-4); border-bottom: var(--hairline) solid var(--border-subtle); }
.detail-subject { font-size: var(--fz-title); font-weight: var(--fw-bold); line-height: 1.25; margin: 0 0 var(--space-4); letter-spacing: -0.01em; }
.detail-meta { display: flex; align-items: center; gap: var(--space-3); }
.avatar {
  width: 36px; height: 36px; border-radius: 999px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: var(--fw-semibold); font-size: var(--fz-body);
  color: var(--accent-fg); background: var(--accent);
}
.detail-who { flex: 1; min-width: 0; }
.detail-who .name { font-weight: var(--fw-semibold); font-size: var(--fz-body); }
.detail-who .addr { font-size: var(--fz-label); color: var(--text-tertiary); }
.detail-who .to { font-size: var(--fz-meta); color: var(--text-tertiary); margin-top: 2px; }
.detail-when { font-size: var(--fz-label); color: var(--text-tertiary); white-space: nowrap; }

.detail-body { flex: 1; overflow: auto; min-height: 0; }
.remote-bar {
  /* a centered pill banner with room above and below, not glued to the email. */
  display: flex; align-items: center; gap: var(--space-3);
  width: fit-content; max-width: calc(100% - 2 * var(--pane-pad));
  margin: var(--space-5) auto var(--space-4);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  background: var(--warning-bg); color: var(--warning);
  border: var(--hairline) solid color-mix(in srgb, var(--warning) 35%, transparent);
  border-radius: var(--radius-card); font-size: var(--fz-label);
  box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--warning) 55%, transparent);
  animation: fade-in-down 0.34s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.remote-bar .grow { flex: 0 1 auto; }
.mail-frame { width: 100%; border: none; display: block; background: transparent; }
.mail-text { padding: var(--pane-pad); white-space: pre-wrap; word-break: break-word; font-size: var(--fz-body); line-height: 1.6; color: var(--text-primary); }

.attachments { padding: var(--space-4) var(--pane-pad); display: flex; flex-wrap: wrap; gap: var(--space-3); border-top: var(--hairline) solid var(--border-subtle); animation: fade-in-up 0.3s ease both; }
.attach {
  display: inline-flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-raised); border: var(--hairline) solid var(--border-default);
  border-radius: var(--radius-control); cursor: pointer; text-decoration: none; color: var(--text-primary);
  font-size: var(--fz-label);
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.1s ease;
}
.attach:hover { background: var(--surface-hover); border-color: var(--border-strong); transform: translateY(-1px); text-decoration: none; }
.attach .icon { color: var(--text-tertiary); }
.attach .sz { color: var(--text-tertiary); font-size: var(--fz-meta); }

/* ============================================================== COMPOSE */
/* Gmail-style dock: each compose is its own small window pinned bottom-right;
   several can be open side by side. A window can minimise to its title bar or
   expand to full screen. */
.compose-dock {
  position: fixed; right: var(--space-5); bottom: 0; z-index: 60;
  display: flex; flex-direction: row-reverse; align-items: flex-end; gap: var(--space-4);
  max-width: 100vw; pointer-events: none;
}
.compose-dock > * { pointer-events: auto; }

.compose-window {
  width: 468px; max-width: calc(100vw - var(--space-6));
  height: 592px; max-height: calc(100vh - 20px);
  background: var(--surface-base);
  border: var(--hairline) solid var(--border-default); border-bottom: none;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  box-shadow: 0 -10px 44px -14px rgba(0, 0, 0, 0.55);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  animation: compose-rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.compose-window.is-closing { animation: compose-sink 0.16s ease both; }
.compose-window.is-min { height: auto; }
.compose-window.is-min .compose-window-body { display: none; }
.compose-window.is-full {
  position: fixed; top: 20px; bottom: 20px; left: 20px; right: 20px;
  width: auto; height: auto; max-width: 1080px; max-height: none; margin: 0 auto;
  border: var(--hairline) solid var(--border-default);
  border-radius: var(--radius-card); z-index: 80;
}
@media (max-width: 560px) {
  .compose-dock { right: 0; left: 0; gap: 0; }
  .compose-window, .compose-window.is-full { width: 100vw; max-width: 100vw; height: calc(100vh - 8px); inset: auto; border-radius: 0; margin: 0; }
}

.compose-window-head {
  display: flex; align-items: center; gap: var(--space-1);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  background: var(--surface-raised); border-bottom: var(--hairline) solid var(--border-subtle);
  cursor: pointer; user-select: none; flex: none;
}
.compose-window-head > .grow { font-size: var(--fz-label); font-weight: var(--fw-semibold); }
.cw-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border: none; background: transparent;
  color: var(--text-tertiary); border-radius: var(--radius-control); cursor: pointer;
  transition: color 0.14s ease, background 0.14s ease;
}
.cw-btn:hover { color: var(--text-primary); background: var(--surface-hover); }
.cw-close:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 15%, transparent); }

.compose-window-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.compose-fields { padding: 0 var(--space-4); flex: none; }
.compose-line { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: var(--hairline) solid var(--border-subtle); }
.compose-line > label { width: 52px; color: var(--text-tertiary); font-size: var(--fz-label); flex-shrink: 0; }
.compose-line input, .compose-line .menu-wrap { border: none; background: transparent; height: 26px; padding: 0; box-shadow: none; }
.compose-line input:focus { box-shadow: none; }
.compose-line .select-menu { background: transparent; border: none; padding: 0; height: 26px; }
.locked-from { font-size: var(--fz-label); color: var(--text-secondary); }
.link-btn { border: none; background: transparent; color: var(--text-tertiary); font-size: var(--fz-label); cursor: pointer; padding: 3px 7px; border-radius: var(--radius-control); transition: color 0.14s ease, background 0.14s ease; }
.link-btn:hover, .link-btn.on { color: var(--accent); background: var(--surface-sunken); }

.compose-toolbar {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: var(--space-2) var(--space-3); flex: none;
  border-bottom: var(--hairline) solid var(--border-subtle);
}
.tb-sep { width: 1px; align-self: stretch; margin: 4px var(--space-1); background: var(--border-default); }

.editor-wrap { flex: 1; min-height: 0; overflow-y: auto; }
.editor { padding: var(--space-4); min-height: 100%; outline: none; font-size: var(--fz-body); line-height: 1.6; color: var(--text-primary); }
.editor:empty::before { content: attr(data-placeholder); color: var(--text-tertiary); pointer-events: none; }
.editor img { max-width: 100%; height: auto; border-radius: var(--radius-control); margin: var(--space-2) 0; }
.editor blockquote { border-left: 2px solid var(--border-strong); margin: var(--space-2) 0 var(--space-2) 2px; padding-left: var(--space-4); color: var(--text-secondary); }
.editor a { color: var(--link); }
.editor ul, .editor ol { padding-left: 1.5em; margin: var(--space-2) 0; }
.editor h2 { font-size: var(--fz-title); font-weight: var(--fw-bold); margin: var(--space-3) 0 var(--space-2); }
.editor p { margin: 0 0 var(--space-3); }
.plain-editor {
  width: 100%; height: 100%; min-height: 160px; resize: none;
  border: none; background: transparent; outline: none; padding: var(--space-4);
  font-family: var(--font-mono); font-size: var(--fz-label); line-height: 1.6; color: var(--text-primary);
}

.att-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-2) var(--space-4); flex: none; }
.att-chip {
  display: inline-flex; align-items: center; gap: var(--space-2); max-width: 100%;
  padding: 4px 6px 4px 10px; background: var(--surface-sunken);
  border: var(--hairline) solid var(--border-default); border-radius: var(--radius-control);
  font-size: var(--fz-label); animation: pop-in 0.2s ease both;
}
.att-chip .ellipsis { max-width: 180px; }
.att-chip button { border: none; background: transparent; color: var(--text-tertiary); cursor: pointer; display: inline-flex; padding: 2px; border-radius: 999px; }
.att-chip button:hover { color: var(--danger); background: var(--surface-hover); }

.compose-attachbar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-4); flex: none; }
.compose-foot {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: var(--hairline) solid var(--border-subtle); flex: none;
}

@keyframes compose-rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes compose-sink { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(16px); } }

/* ---- styled dropdown menus (design-matched, not native selects) ---- */
.menu-wrap { position: relative; display: inline-flex; }
.select-menu {
  display: inline-flex; align-items: center; gap: var(--space-2); width: 100%; min-width: 0;
  padding: 6px 10px; cursor: pointer; color: var(--text-primary); font-size: var(--fz-label);
  background: var(--surface-sunken); border: var(--hairline) solid var(--border-default);
  border-radius: var(--radius-control); transition: border-color 0.14s ease, background 0.14s ease;
}
.select-menu:hover { border-color: var(--border-strong); }
.select-menu .grow { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-menu > svg:last-child { color: var(--text-tertiary); flex: none; }

.menu-wrap.split { display: inline-flex; }
.split-main { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split-caret {
  border-top-left-radius: 0; border-bottom-left-radius: 0; padding-left: 7px; padding-right: 7px;
  margin-left: 1px; border-left: var(--hairline) solid color-mix(in srgb, var(--accent-fg) 28%, transparent);
}

.menu-pop {
  position: fixed; z-index: 200; min-width: 180px; max-width: 320px;
  background: var(--surface-overlay); border: var(--hairline) solid var(--border-default);
  border-radius: var(--radius-card); box-shadow: var(--shadow-overlay);
  padding: var(--space-2); display: flex; flex-direction: column; gap: 1px;
  animation: menu-pop-in 0.14s ease both;
}
.menu-item {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; text-align: left;
  padding: 7px var(--space-2); border: none; background: transparent; cursor: pointer;
  color: var(--text-secondary); border-radius: var(--radius-control); font-size: var(--fz-label);
  transition: background 0.12s ease, color 0.12s ease;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-hover); color: var(--text-primary); outline: none; }
.menu-item.danger:hover { color: var(--danger); }
.menu-item.checked { color: var(--text-primary); }
.menu-item .menu-tick { width: 16px; height: 16px; display: inline-flex; align-items: center; color: var(--accent); flex: none; }
.menu-item > .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-hint { font-size: var(--fz-meta); color: var(--text-tertiary); flex: none; letter-spacing: 0.02em; }
.menu-sep { height: 1px; margin: var(--space-1) 0; background: var(--border-subtle); }
@keyframes menu-pop-in { from { opacity: 0; transform: translateY(4px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ============================================================== DASHBOARD */
.dash { flex: 1; min-height: 0; display: grid; grid-template-columns: 232px 1fr; grid-template-rows: minmax(0, 1fr); }
@media (max-width: 760px) { .dash { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); } }
.dash-side {
  background: var(--surface-base); border-right: var(--hairline) solid var(--border-default);
  padding: var(--space-5) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2);
}
.dash-side .brand { margin-bottom: var(--space-5); }
.dash-nav { display: flex; flex-direction: column; gap: 1px; }
@media (max-width: 760px) { .dash-nav { flex-direction: row; flex-wrap: wrap; } }
.dash-nav button {
  display: flex; align-items: center; gap: var(--space-3); text-align: left;
  padding: var(--row-pad-y) var(--space-3); border-radius: var(--radius-control);
  border: none; background: transparent; color: var(--text-secondary);
  font-size: var(--fz-body); font-weight: var(--fw-medium); cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.dash-nav button:hover { background: var(--surface-hover); color: var(--text-primary); }
.dash-nav button.on { background: var(--selection-bg); color: var(--link); }
.dash-side-foot { margin-top: auto; }

.dash-main { overflow-y: auto; min-height: 0; padding: var(--space-6); }
.dash-main-inner { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-6); animation: view-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.section { animation: fade-in 0.32s ease both; }
.section-title { font-size: var(--fz-heading); font-weight: var(--fw-bold); margin: 0 0 var(--space-1); }
.section-sub { color: var(--text-tertiary); font-size: var(--fz-label); margin: 0 0 var(--space-4); line-height: 1.5; }
.card {
  background: var(--surface-raised); border: var(--hairline) solid var(--border-default);
  border-radius: var(--radius-card); padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-4);
}
.card + .card { margin-top: var(--space-4); }

/* about — third-party licenses panel */
.about-licenses { border-top: var(--hairline) solid var(--border-subtle); margin-top: var(--space-2); padding-top: var(--space-3); animation: fade-in-down 0.18s ease both; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-4); }
.tile {
  background: var(--surface-raised); border: var(--hairline) solid var(--border-default);
  border-radius: var(--radius-card); padding: var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-2);
  animation: fade-in-up 0.3s ease both;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: 0 6px 18px -10px rgba(0, 0, 0, 0.4); }
.tile .n { font-size: var(--fz-title); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }
.tile .l { font-size: var(--fz-label); color: var(--text-tertiary); display: flex; align-items: center; gap: 6px; }

/* permission rules */
.rules { display: flex; flex-direction: column; gap: var(--space-3); }
.rule {
  border: var(--hairline) solid var(--border-default); border-radius: var(--radius-card);
  padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--surface-raised);
  animation: fade-in-up 0.25s ease both;
}
.rule-top { display: flex; align-items: center; gap: var(--space-3); }
.rule-top .email { font-weight: var(--fw-semibold); font-family: var(--font-mono); font-size: var(--fz-label); }
.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
@media (max-width: 560px) { .rule-grid { grid-template-columns: 1fr; } }

/* mail servers — drag-reorderable priority blocks */
.servers { display: flex; flex-direction: column; gap: var(--space-3); }
.server-card {
  position: relative;
  border: var(--hairline) solid var(--border-default); border-radius: var(--radius-card);
  padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--surface-raised);
  animation: fade-in-up 0.25s ease both;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease, transform 0.16s ease;
}
.server-card::before {
  content: ''; position: absolute; left: 0; top: var(--space-4); bottom: var(--space-4); width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent); opacity: 0.55;
}
.server-card:hover { border-color: var(--border-strong); }
.server-card.dragging { opacity: 0.5; border-style: dashed; border-color: var(--accent); transform: scale(0.99); }
.server-card.drop-target { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.server-head { display: flex; align-items: center; gap: var(--space-2); }
.server-head .input { flex: 1; font-weight: var(--fw-semibold); }
.drag-handle {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); cursor: grab; padding: 2px; border-radius: var(--radius-control);
  transition: color 0.14s ease, background 0.14s ease;
}
.drag-handle:hover { color: var(--text-secondary); background: var(--surface-sunken); }
.server-card.dragging .drag-handle { cursor: grabbing; }
.prio {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px; flex: none;
  font-size: var(--fz-caption); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums;
  color: var(--accent-fg); background: var(--accent); border-radius: 999px;
}

/* =============================================================== TOASTS */
.toast-wrap { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 100; display: flex; flex-direction: column; gap: var(--space-3); max-width: 360px; }
.toast {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-overlay); color: var(--text-primary);
  border: var(--hairline) solid var(--border-default);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-card); box-shadow: var(--shadow-overlay);
  font-size: var(--fz-label);
  animation: slide-in-right 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.toast.leaving { animation: fade-in 0.2s ease reverse both; }
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--success); }
.toast.info { border-left-color: var(--accent); }
.toast .icon { margin-top: 1px; }
.toast.err .icon { color: var(--danger); }
.toast.ok .icon { color: var(--success); }

/* action toast (undo send): a button + a draining countdown bar */
.toast.action { align-items: center; position: relative; overflow: hidden; padding-bottom: calc(var(--space-3) + 2px); }
.toast-action {
  border: var(--hairline) solid var(--border-default); background: var(--surface-sunken);
  color: var(--accent); font-weight: var(--fw-semibold); font-size: var(--fz-label);
  padding: 4px 12px; border-radius: var(--radius-control); cursor: pointer; flex: none;
  transition: background 0.14s ease, border-color 0.14s ease;
}
.toast-action:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.toast-timer { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; transform-origin: left; background: var(--accent); }
@keyframes toast-countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* schedule ("send later") picker popover */
.sched-pop { min-width: 244px; padding: var(--space-3); gap: var(--space-1); }
.sched-title { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--fw-semibold); font-size: var(--fz-label); color: var(--text-secondary); padding: 0 var(--space-1) var(--space-2); }
.sched-preset {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; text-align: left;
  padding: 8px var(--space-2); border: none; background: transparent; cursor: pointer;
  color: var(--text-primary); border-radius: var(--radius-control); font-size: var(--fz-label);
  transition: background 0.12s ease;
}
.sched-preset:hover { background: var(--surface-hover); }
.sched-preset .sched-when { font-size: var(--fz-meta); color: var(--text-tertiary); }
.sched-custom { display: flex; flex-direction: column; gap: var(--space-2); border-top: var(--hairline) solid var(--border-subtle); margin-top: var(--space-2); padding-top: var(--space-3); }
.sched-custom label { font-size: var(--fz-meta); color: var(--text-tertiary); }
.sched-custom .btn { align-self: flex-end; }

/* scheduled-sends list row */
.sched-row .msg-dot { display: inline-flex; align-items: center; justify-content: center; color: var(--accent); }

/* full-page loader */
.page-loader { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); color: var(--text-tertiary); }

/* topbar (mobile back etc.) */
.only-narrow { display: none; }
@media (max-width: 860px) { .only-narrow { display: inline-flex; } }

/* ==========================================================================
   TACTICAL UI  —  shooter-game / HUD redesign layer.
   Overrides the visual treatment of the shared components (buttons, popovers,
   inputs, panels) while leaving layout intact. Two signatures:
     • buttons: dark dotted fill, no frame until hover, on hover a white stroke
       DRAWS around the perimeter; selected/primary = accent frame + accent text.
     • popovers/windows: open as a horizontal line, then expand vertically, then
       the contents fade in.
   Loads last, so equal-specificity rules win. To restore the old design, see
   public/css/legacy/README.md.
   ========================================================================== */

/* the box opens as a line L↔R, then T↕B (clip-path), contents fade in after */
@keyframes tac-open {
  0%   { clip-path: inset(49.5% 49.5% 49.5% 49.5%); }
  46%  { clip-path: inset(49.5% 0 49.5% 0); }
  100% { clip-path: inset(0 0 0 0); }
}
@keyframes tac-content-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

/* --- shell: plain background (no dot-grid — dots live inside buttons only) --- */
body { background-color: var(--surface-base); background-image: none; }

/* --- buttons: THREE states, each a single colour (grey = idle, accent =
       selected, white = hover). Text, dots and frame all follow that one colour
       via currentColor, so the whole button always reads as one colour.
       Dots are small & round and fade out toward the centre label. The side
       borders are solid; the top & bottom are two segments that leave a faded
       gap in the middle at rest and grow together to CLOSE the frame on hover.
       Corners follow --radius-control so the app's rounded option still works. */
.btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--control-height); padding: 0 var(--space-5);
  border: 0; box-shadow: none; border-radius: var(--radius-control);
  color: var(--btn-fg-idle);
  font-family: var(--font-ui); font-weight: var(--fw-bold); font-size: var(--fz-label);
  letter-spacing: 0.1em; text-transform: uppercase; white-space: nowrap; cursor: pointer;
  /* the dotted plate: small round dots in the button's colour (dimmed), with a
     fill-coloured centre wash on top that rubs them out behind the label.
     --dotc carries the dot colour per state (currentColor doesn't reliably
     re-evaluate inside a background gradient on hover). */
  --dotc: var(--btn-fg-idle);
  --plate:
    radial-gradient(72% 120% at 50% 50%, var(--btn-bg) 10%, transparent 70%),
    radial-gradient(circle at center, color-mix(in srgb, var(--dotc) 62%, transparent) 0.45px, transparent 1.15px);
  background-color: var(--btn-bg);
  background-image: var(--plate);
  background-size: 100% 100%, 4px 4px;
  transition: color 0.16s ease;
}
/* The whole frame lives on ::before as a full outline that rounds WITH the
   button (border-radius: inherit), so the sides and corners are always solid and
   round correctly. A horizontal mask fades only the TOP & BOTTOM centres to a
   gap (open at rest) — the sides sit at the far edges, outside the mask's gap. */
.btn::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  border: 1.5px solid currentColor; border-radius: inherit;
  -webkit-mask: linear-gradient(90deg, #000 32%, transparent 47%, transparent 53%, #000 68%);
          mask: linear-gradient(90deg, #000 32%, transparent 47%, transparent 53%, #000 68%);
}
/* ::after = four top/bottom segments anchored at the CORNERS. On hover they
   grow inward (width 0 → 51%) and meet in the centre, so the frame closes from
   the OUTSIDE in. */
.btn::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(currentColor, currentColor) top left / 0 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) top right / 0 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) bottom left / 0 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) bottom right / 0 1.5px no-repeat;
  transition: background-size 0.24s cubic-bezier(0.5, 0, 0.2, 1);
}
/* hover: one white colour everywhere; top & bottom grow together to close. */
.btn:hover { color: var(--stroke-hover); --dotc: var(--stroke-hover); background-color: var(--btn-bg); background-image: var(--plate); background-size: 100% 100%, 4px 4px; }
.btn.primary:hover { color: var(--stroke-hover); --dotc: var(--stroke-hover); background-color: var(--btn-bg); background-image: var(--plate); background-size: 100% 100%, 4px 4px; }
.btn:hover::after { background-size: 51% 1.5px, 51% 1.5px, 51% 1.5px, 51% 1.5px; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* selected: accent colour throughout (identical frame shape to idle). */
.btn.primary { color: var(--accent); --dotc: var(--accent); background-color: var(--btn-bg); background-image: var(--plate); background-size: 100% 100%, 4px 4px; }

/* subtle: the idle grey plate (restated so the original shorthand can't drop it). */
.btn.subtle { background-color: var(--btn-bg); background-image: var(--plate); background-size: 100% 100%, 4px 4px; }

/* ghost: flat text button — no plate, no frame. */
/* ghost now also gets the grey plate + frame (only tiny icon-only buttons stay
   flat). Restated so the original .btn.ghost { background: transparent } can't
   win. */
.btn.ghost { color: var(--btn-fg-idle); background-color: var(--btn-bg); background-image: var(--plate); background-size: 100% 100%, 4px 4px; }

/* danger: red throughout, stays red on hover. */
.btn.danger { color: var(--danger); --dotc: var(--danger); background-color: var(--btn-bg); background-image: var(--plate); background-size: 100% 100%, 4px 4px; }
.btn.danger:hover { background-color: var(--btn-bg); background-image: var(--plate); background-size: 100% 100%, 4px 4px; }

.btn.block { width: 100%; }
.btn.sm { height: 26px; padding: 0 var(--space-4); letter-spacing: 0.08em; }

/* icon buttons: lighter treatment, a crisp frame on hover (no draw) */
.icon-btn { border-radius: var(--radius-control); transition: color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease; }
.icon-btn:hover { background: var(--surface-hover); color: var(--stroke-hover); box-shadow: inset 0 0 0 1px var(--border-strong); }
.icon-btn.on { color: var(--accent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent); }

/* segmented control: HUD chips, accent when active */
.seg { background: var(--surface-sunken); border: 1px solid var(--border-default); border-radius: var(--radius-control); padding: 2px; gap: 2px; }
.seg button {
  border-radius: var(--radius-control); text-transform: uppercase; letter-spacing: 0.06em; font-weight: var(--fw-bold);
  font-size: var(--fz-meta); color: var(--text-tertiary); padding: 4px 12px;
}
.seg button:hover { color: var(--stroke-hover); }
.seg button.on { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }

/* inputs: sunken plates, crisp accent frame on focus */
.input, .select, .textarea { border-radius: var(--radius-control); border: 1px solid var(--border-default); background: var(--surface-sunken); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent); background: var(--surface-raised);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* switch: sharp accent track */
.switch .track { border-radius: 2px; }
.switch .track::after { border-radius: 1px; }

/* --- popovers / windows / toasts: line-open + content fade --- */
.menu-pop {
  border-radius: var(--radius-card); background: var(--panel-fill);
  border: 1px solid var(--border-strong);
  box-shadow: 0 10px 40px -8px rgba(0, 0, 0, 0.7);
  animation: tac-open 0.3s cubic-bezier(0.6, 0, 0.2, 1) both;
}
.menu-pop > * { animation: tac-content-in 0.22s ease both; animation-delay: 0.28s; }
.menu-item { border-radius: var(--radius-control); text-transform: uppercase; letter-spacing: 0.05em; font-size: var(--fz-meta); font-weight: var(--fw-semibold); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-hover); color: var(--stroke-hover); box-shadow: inset 0 0 0 1px var(--border-strong); }

.compose-window {
  border-radius: var(--radius-card) var(--radius-card) 0 0 !important; border: 1px solid var(--border-strong);
  background: var(--panel-fill);
  animation: tac-open 0.34s cubic-bezier(0.6, 0, 0.2, 1) both;
}
.compose-window.is-closing { animation: compose-sink 0.16s ease both; }
.compose-window > * { animation: tac-content-in 0.26s ease both; animation-delay: 0.32s; }
.compose-window-head { background: var(--surface-sunken); }
.compose-window-head > .grow { text-transform: uppercase; letter-spacing: 0.08em; }

.toast {
  border-radius: var(--radius-card); border: 1px solid var(--border-strong); background: var(--panel-fill);
  animation: tac-open 0.28s cubic-bezier(0.6, 0, 0.2, 1) both;
}
.toast > * { animation: tac-content-in 0.2s ease both; animation-delay: 0.26s; }

/* --- panels: auth, cards, tiles get the line-open reveal + sharp frames --- */
.auth {
  border-radius: var(--radius-card); border: 1px solid var(--border-strong); background: var(--panel-fill);
  animation: tac-open 0.4s cubic-bezier(0.6, 0, 0.2, 1) both;
}
.auth > * { animation: tac-content-in 0.3s ease both; animation-delay: 0.4s; }
.card, .tile, .rule, .server-card { border-radius: var(--radius-card); }
.tile { position: relative; }
.tile::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--accent); opacity: 0.7; }

/* --- nav rows (sidebar folders + dashboard/settings sections) get the same
   dotted plate + frame as the buttons, keeping their left-aligned layout:
   grey idle, white on hover, accent when selected. --- */
.folder, .dash-nav button {
  position: relative; overflow: hidden;
  --dotc: var(--btn-fg-idle);
  --plate:
    radial-gradient(72% 120% at 50% 50%, var(--btn-bg) 10%, transparent 70%),
    radial-gradient(circle at center, color-mix(in srgb, var(--dotc) 62%, transparent) 0.45px, transparent 1.15px);
  color: var(--btn-fg-idle);
  background-color: var(--btn-bg);
  background-image: var(--plate);
  background-size: 100% 100%, 4px 4px;
  border-radius: var(--radius-control);
  transition: color 0.16s ease;
}
/* the full frame (rounds with the row); the extra resets kill the old
   accent-bar ::before that folders used. */
.folder::before, .folder.active::before, .dash-nav button::before {
  content: ''; position: absolute; inset: 0; width: auto; height: auto; pointer-events: none;
  border: 1.5px solid currentColor; border-radius: inherit; background: none; animation: none;
  -webkit-mask: linear-gradient(90deg, #000 32%, transparent 47%, transparent 53%, #000 68%);
          mask: linear-gradient(90deg, #000 32%, transparent 47%, transparent 53%, #000 68%);
}
.folder::after, .dash-nav button::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(currentColor, currentColor) top left / 0 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) top right / 0 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) bottom left / 0 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) bottom right / 0 1.5px no-repeat;
  transition: background-size 0.24s cubic-bezier(0.5, 0, 0.2, 1);
}
.folder:hover, .dash-nav button:hover { color: var(--stroke-hover); --dotc: var(--stroke-hover); background-color: var(--btn-bg); background-image: var(--plate); background-size: 100% 100%, 4px 4px; }
.folder:hover::after, .dash-nav button:hover::after { background-size: 51% 1.5px, 51% 1.5px, 51% 1.5px, 51% 1.5px; }
.folder.active, .dash-nav button.on { color: var(--accent); --dotc: var(--accent); background-color: var(--btn-bg); background-image: var(--plate); background-size: 100% 100%, 4px 4px; box-shadow: none; }
.folder.active .fname { color: var(--accent); }
/* a little more breathing room between the stacked plates */
.folders { gap: var(--space-2); }
.dash-nav { gap: var(--space-2); }
.tabs, .tab { border-radius: var(--radius-control); }

/* --- uppercase the UI chrome (never message content) --- */
.brand-name, .side-brand, .section-title, .list-title, .fname, .tile .l,
.detail-who .to, .field > label, .dash-nav button, .seg button {
  text-transform: uppercase; letter-spacing: 0.05em;
}
.section-title { letter-spacing: 0.06em; }
.brand-mark { border-radius: var(--radius-control); }

/* keep the sandboxed message iframe and its text perfectly normal-case */
.mail-frame, .mail-text, .msg-subject, .detail-subject, .editor, .plain-editor { text-transform: none; letter-spacing: normal; }
/* the message "paper" gets an explicit dark backing (never the white canvas) */
.mail-frame { background: #101216; }

/* --- refinements --- */
/* uppercase widened the compose foot; let it wrap and tighten the mode chips */
.compose-foot { flex-wrap: wrap; row-gap: var(--space-2); }
.compose-foot .seg { margin-left: auto; }
.compose-foot .seg button { padding: 4px 9px; letter-spacing: 0.03em; }
/* sharp HUD chips/tags */
.tag { border-radius: var(--radius-control); text-transform: uppercase; letter-spacing: 0.05em; font-size: var(--fz-meta); }
.att-chip { border-radius: var(--radius-control); }
/* reduce-motion: don't leave delayed content hidden (base.css only zeroes
   durations, not delays) */
:root[data-reduce-motion] .menu-pop > *,
:root[data-reduce-motion] .compose-window > *,
:root[data-reduce-motion] .auth > *,
:root[data-reduce-motion] .toast > * { animation-delay: 0ms !important; }
@media (prefers-reduced-motion: reduce) {
  .menu-pop > *, .compose-window > *, .auth > *, .toast > * { animation-delay: 0ms !important; }
}
