/* ---------- Reset + tokens ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
}

:root {
  --bg: #0e0e10;
  --bg-elev: #16161a;
  --surface: #1d1d22;
  --surface-2: #26262d;
  --line: #2a2a32;
  --line-strong: #3a3a44;

  --ink: #ffffff;
  --ink-soft: #c9c9d3;
  --ink-mute: #7e7e8b;
  --ink-faint: #5a5a66;

  --brick: #ff6b00;
  --brick-dark: #d75900;
  --brick-soft: #ffae6b;
  --brick-glow: rgba(255, 107, 0, 0.35);
  --ember: #ffaa44;

  --green: #00c853;
  --green-dim: #009638;
  --red: #ff3d00;
  --red-dim: #c8240a;
  --amber: #ffb400;

  --urgent: var(--red);
  --soon: var(--amber);
  --done-green: var(--green);

  --shadow-card: 0 1px 0 rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-elev: 0 8px 32px rgba(0, 0, 0, 0.6);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;
  --tap-lg: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brick); text-decoration: none; }
::selection { background: var(--brick); color: #000; }

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.brand-name {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--ink-mute);
  text-transform: uppercase;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-right: -8px;
}
.icon-only {
  width: var(--tap);
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink-soft);
  padding: 0;
}
.icon-only:active { background: rgba(255, 255, 255, 0.08); color: var(--ink); }
.icon-only.spinning svg { animation: spin 0.8s linear; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ---------- Scoreboard ---------- */
.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border-right: 1px solid var(--line);
}
.score:last-child { border-right: none; }
.score-num {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
  font-feature-settings: "tnum";
  letter-spacing: -0.02em;
}
.score-num.accent { color: var(--brick); }
.score-num.muted { color: var(--ink-mute); }
.score-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  text-transform: uppercase;
}

/* ---------- Main layout ---------- */
#main {
  padding: 12px 14px calc(120px + var(--safe-bot));
  max-width: 720px;
  margin: 0 auto;
}
.list { display: flex; flex-direction: column; gap: 10px; }

.section-head {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  text-transform: uppercase;
  padding: 16px 4px 4px;
}

/* ---------- Card ---------- */
.card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 14px 14px;
  min-height: 108px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.12s ease, background 0.12s ease;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--brick);
  box-shadow: 0 0 8px var(--brick-glow);
}
.card.card-done { opacity: 0.5; }
.card.card-done::before { background: var(--ink-faint); box-shadow: none; }
.card.card-urgent::before { background: var(--red); box-shadow: 0 0 8px rgba(255, 61, 0, 0.5); }
.card:active { transform: scale(0.985); background: var(--surface-2); }
.card.flash-done {
  animation: flash-done 0.6s ease forwards;
}
@keyframes flash-done {
  0% { background: var(--surface); }
  30% { background: rgba(0, 200, 83, 0.25); border-color: var(--green); }
  100% { background: var(--surface); opacity: 0; transform: translateX(40%); }
}

.card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-left: 4px;
}
.card-name {
  font-size: 19px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}
.card-closing {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.card-next {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.3;
  font-weight: 500;
}

.tone-urgent { color: var(--red); }
.tone-soon { color: var(--amber); }
.tone-normal { color: var(--green); }
.tone-past { color: var(--ink-mute); }
.tone-muted { color: var(--ink-mute); }
.tone-done { color: var(--green); font-weight: 700; }

.card-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.card-side .quick-row {
  display: flex;
  gap: 6px;
}
.quick-action {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 107, 0, 0.12);
  color: var(--brick);
  border: 1px solid rgba(255, 107, 0, 0.3);
  transition: background 0.12s ease, transform 0.06s ease;
}
.quick-action:active {
  background: var(--brick);
  color: #000;
  transform: scale(0.92);
}

/* ---------- Step indicators ---------- */
.steps {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.step {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  border: 2px solid var(--line-strong);
  background: transparent;
  color: var(--ink-faint);
  font-feature-settings: "tnum";
  flex-shrink: 0;
}
.step-conn {
  width: 12px;
  height: 2px;
  background: var(--line-strong);
  flex-shrink: 0;
}
.step.sent {
  background: var(--green);
  border-color: var(--green);
  color: #042b14;
}
.step.sent + .step-conn { background: var(--green); }
.step.pending {
  border-color: var(--brick);
  color: var(--brick);
  box-shadow: 0 0 0 0 var(--brick-glow);
  animation: step-pulse 2.2s ease-in-out infinite;
}
@keyframes step-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--brick-glow); }
  50% { box-shadow: 0 0 0 4px transparent; }
}
.step.skipped {
  border-color: var(--line-strong);
  color: var(--ink-faint);
  font-size: 14px;
}
.step.failed {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.step.disabled {
  border-style: dashed;
  border-color: var(--line-strong);
  color: var(--ink-faint);
  opacity: 0.3;
  animation: none;
  box-shadow: none;
}
.card-done .step,
.card-done .step-conn { opacity: 0.7; animation: none; }

/* ---------- Empty ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 48px 12px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
}
.empty-emoji { font-size: 36px; }
.empty-title { font-weight: 800; font-size: 16px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink); }
.empty-sub { color: var(--ink-mute); font-size: 14px; }
.hidden { display: none !important; }

/* ---------- Show done toggle ---------- */
.show-done-row {
  display: flex;
  justify-content: center;
  margin-top: 24px;
}
.show-done {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  cursor: pointer;
  min-height: var(--tap);
}
.show-done input {
  width: 18px;
  height: 18px;
  accent-color: var(--brick);
  cursor: pointer;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 24px;
  bottom: calc(24px + var(--safe-bot));
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--brick);
  color: #000;
  border: none;
  box-shadow: 0 6px 20px var(--brick-glow), 0 2px 8px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  pointer-events: auto;
  transition: transform 0.12s ease, background 0.12s ease;
}
.fab:active { transform: scale(0.92); background: var(--brick-dark); }
body.sheet-open .fab { display: none; }

/* ---------- Bottom sheet ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  animation: fade-in 0.18s ease;
}
.sheet-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  max-height: 92dvh;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-elev);
  padding: 8px 18px calc(18px + var(--safe-bot));
  overflow-y: auto;
  color: var(--ink);
  animation: slide-up 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-small .sheet-card { max-height: 60vh; }
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--line-strong);
  border-radius: 2px;
  margin: 6px auto 8px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 12px;
}
.sheet-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

body.sheet-open { overflow: hidden; }

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field .label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.field .req { color: var(--brick); }
.field input,
.field textarea {
  width: 100%;
  padding: 14px 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 17px;
  color: var(--ink);
  min-height: var(--tap);
  -webkit-appearance: none;
  appearance: none;
}
.field input::placeholder,
.field textarea::placeholder { color: var(--ink-faint); }
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brick);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--brick-glow);
}
.field textarea { min-height: 96px; resize: vertical; }
.field.highlight .label { color: var(--brick); }
.field.highlight input {
  border-color: var(--brick);
  background: rgba(255, 107, 0, 0.06);
}
.field .hint {
  font-size: 13px;
  color: var(--ink-mute);
  margin-top: 2px;
  line-height: 1.4;
}

.more {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.more > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  min-height: var(--tap);
}
.more > summary::-webkit-details-marker { display: none; }
.more .chev { transition: transform 0.2s ease; color: var(--ink-mute); }
.more[open] .chev { transform: rotate(180deg); }
.more-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 14px 14px;
}

.form-error {
  background: rgba(255, 61, 0, 0.12);
  color: #ff8866;
  border: 1px solid rgba(255, 61, 0, 0.4);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  padding-top: 8px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0 18px;
  min-height: var(--tap-lg);
  transition: background 0.12s ease, transform 0.06s ease, box-shadow 0.12s ease;
}
.btn-block { width: 100%; }
.btn-primary {
  background: var(--brick);
  color: #000;
  box-shadow: 0 0 0 0 var(--brick-glow);
}
.btn-primary:active {
  background: var(--brick-dark);
  transform: scale(0.98);
  box-shadow: 0 0 0 6px transparent;
}
.btn-primary.pulse { animation: btn-pulse 1.2s ease-in-out infinite; }
@keyframes btn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--brick-glow); }
  50% { box-shadow: 0 0 0 8px transparent; }
}
.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--line-strong);
}
.btn-secondary:active { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-mute); }
.btn-ghost:active { background: var(--surface); color: var(--ink-soft); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:active { background: var(--red-dim); }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 12px; letter-spacing: 0.08em; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Detail ---------- */
.detail-body { display: flex; flex-direction: column; gap: 16px; padding-bottom: 6px; }

.banner-done {
  background: rgba(0, 200, 83, 0.1);
  color: var(--green);
  border: 1px solid var(--green-dim);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.contact-stack { display: flex; flex-direction: column; gap: 8px; }
.contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  min-height: var(--tap-lg);
}
.contact-row:active { background: var(--surface-2); }
.contact-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 107, 0, 0.12);
  color: var(--brick);
  flex-shrink: 0;
}
.contact-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.contact-value {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-action { font-size: 12px; color: var(--ink-mute); letter-spacing: 0.04em; text-transform: uppercase; }

.facts {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.fact {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.fact:last-child { border-bottom: none; }
.fact-k {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  text-transform: uppercase;
}
.fact-v {
  font-size: 16px;
  color: var(--ink);
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-weight: 600;
}
.fact-notes .fact-v { font-size: 15px; font-weight: 500; }
.fact-date { color: var(--ink-mute); font-weight: 500; font-size: 14px; }

.section-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 0 0 8px;
}
.timeline-list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.tl-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  min-height: 56px;
}
.tl-row:last-child { border-bottom: none; }
.tl-icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}
.tl-sent .tl-icon { background: rgba(0, 200, 83, 0.12); color: var(--green); }
.tl-pending .tl-icon { background: rgba(255, 107, 0, 0.15); color: var(--brick); }
.tl-skipped .tl-icon { background: var(--surface-2); color: var(--ink-faint); }
.tl-failed .tl-icon { background: rgba(255, 61, 0, 0.15); color: var(--red); }
.tl-text { flex: 1; min-width: 0; }
.tl-label { font-weight: 700; font-size: 14px; letter-spacing: 0.02em; }
.tl-sub { font-size: 12px; color: var(--ink-mute); margin-top: 2px; }
.tl-skipped .tl-label { color: var(--ink-faint); font-weight: 500; }
.tl-disabled .tl-icon { background: var(--surface-2); color: var(--ink-faint); }
.tl-disabled .tl-label { color: var(--ink-faint); }
.tl-disabled { opacity: 0.6; }
.tl-right {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Tap-to-edit send date */
.tl-date-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}
.tl-date {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.tl-date svg { opacity: 0.7; }
.tl-date-custom {
  color: var(--brick);
  border-color: var(--brick);
  background: rgba(255, 107, 0, 0.08);
}
.tl-date-reset {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  color: var(--ink-mute);
  background: transparent;
  border: none;
  cursor: pointer;
}
.tl-date-input {
  margin-top: 6px;
  font-size: 13px;
  padding: 5px 8px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--brick);
  border-radius: var(--radius-sm);
  color-scheme: dark;
}

/* On/off switch */
.tl-switch {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.tl-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.tl-switch-track {
  position: relative;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  transition: background 0.18s ease, border-color 0.18s ease;
}
.tl-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink-faint);
  transition: transform 0.18s ease, background 0.18s ease;
}
.tl-switch input:checked + .tl-switch-track {
  background: var(--brick);
  border-color: var(--brick);
}
.tl-switch input:checked + .tl-switch-track .tl-switch-thumb {
  background: #fff;
  transform: translateX(16px);
}
.tl-switch input:focus-visible + .tl-switch-track {
  box-shadow: 0 0 0 3px var(--brick-glow);
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

/* ---------- Confirm ---------- */
.confirm-body { display: flex; flex-direction: column; gap: 6px; padding: 4px 0 6px; }
.confirm-body h2 { margin: 0 0 6px; font-size: 20px; font-weight: 800; }
.confirm-message { margin: 0 0 8px; color: var(--ink-soft); font-size: 15px; line-height: 1.45; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + var(--safe-bot));
  transform: translate(-50%, 0);
  background: var(--brick);
  color: #000;
  padding: 14px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), 0 0 24px var(--brick-glow);
  z-index: 2000;
  max-width: calc(100% - 32px);
  text-align: center;
  animation: toast-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes toast-in {
  from { transform: translate(-50%, 40px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ---------- Topbar actions group (legacy) ---------- */

/* ---------- Settings sheet (template editor) ---------- */
.settings-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 0 6px;
}
.settings-section-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 4px 0 0;
}
.settings-lede {
  margin: 0 0 4px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.45;
}

.tpl-list { display: flex; flex-direction: column; gap: 10px; }
.tpl-loading { color: var(--ink-mute); padding: 16px; text-align: center; font-size: 14px; }

.tpl-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.tpl-summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--tap-lg);
}
.tpl-summary::-webkit-details-marker { display: none; }
.tpl-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.tpl-title { font-size: 15px; font-weight: 800; color: var(--ink); letter-spacing: 0.02em; }
.tpl-when { font-size: 12px; color: var(--ink-mute); }
.tpl-card .chev { color: var(--ink-mute); transition: transform 0.2s ease; flex-shrink: 0; }
.tpl-card[open] .chev { transform: rotate(180deg); }
.tpl-card[open] .tpl-summary { background: var(--surface-2); border-bottom: 1px solid var(--line); }

.tpl-body { display: flex; flex-direction: column; gap: 12px; padding: 14px; }
.tpl-body .field input,
.tpl-body .field textarea { font-family: inherit; font-size: 16px; line-height: 1.45; }
.tpl-body .tpl-body-text { min-height: 150px; white-space: pre-wrap; word-wrap: break-word; }

.tpl-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: -6px 0 0;
}
.tpl-pills-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  text-transform: uppercase;
  margin-right: 4px;
}
.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1.5px solid var(--line-strong);
  color: var(--brick);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 32px;
  transition: background 0.12s ease, transform 0.06s ease, border-color 0.12s ease;
  white-space: nowrap;
  font-family: inherit;
}
.pill:hover { background: var(--surface); border-color: var(--brick); }
.pill:active {
  background: var(--brick);
  color: #000;
  border-color: var(--brick);
  transform: scale(0.94);
}
.tpl-note {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ink-mute);
  font-style: italic;
  line-height: 1.45;
}

/* ---------- Desktop tweaks ---------- */
@media (min-width: 720px) {
  #main { padding: 20px 24px 140px; }
  .list { gap: 12px; }
  .card { padding: 18px 20px; min-height: 116px; }
  .card-name { font-size: 22px; }
  .card-closing { font-size: 20px; }
  .topbar { padding: 18px 28px 14px; }
  .brand-name { font-size: 14px; }
  .scoreboard { padding-top: 14px; margin-top: 14px; }
  .score-num { font-size: 28px; }
  .fab { right: 32px; bottom: 32px; }
  .step { width: 26px; height: 26px; font-size: 13px; }
  .step-conn { width: 14px; }
  .sheet-card {
    border-radius: 22px;
    border-bottom: 1px solid var(--line);
    max-height: 88vh;
    margin-bottom: 24px;
  }
  .sheet { align-items: center; }
}

/* ---------- Auth gating + login screen ---------- */

/* Body class state machine:
 *   .auth-checking → boot, before /api/me has settled. Hide everything.
 *   .auth-gate     → not authenticated. Show only the login overlay.
 *   (no class)     → authenticated. Show the app, hide the login overlay.
 */
body.auth-checking .topbar,
body.auth-checking main,
body.auth-checking .fab,
body.auth-checking .sheet,
body.auth-checking #loginScreen { display: none !important; }

body.auth-gate .topbar,
body.auth-gate main,
body.auth-gate .fab,
body.auth-gate .sheet { display: none !important; }

body:not(.auth-gate) #loginScreen { display: none; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  /* Make the screen feel intentional, not a transient overlay. */
  background-image:
    radial-gradient(circle at 30% 20%, rgba(255, 107, 0, 0.10), transparent 50%),
    radial-gradient(circle at 70% 80%, rgba(255, 107, 0, 0.06), transparent 55%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-elev);
}
.login-brand {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brick);
  text-shadow: 0 0 18px var(--brick-glow);
}
.login-lede {
  margin: -8px 0 4px;
  text-align: center;
  color: var(--ink-mute);
  font-size: 13px;
}
.login-card .field { margin: 0; }
#loginSubmit { margin-top: 6px; }

/* Subtle logout icon — same shape as other topbar icons but a hair dimmer. */
.icon-only.icon-muted { color: var(--ink-mute); opacity: 0.7; }
.icon-only.icon-muted:hover { color: var(--ink-soft); opacity: 1; }

/* ---------- Settings footer / Advanced link ---------- */
.settings-footer {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
}
.settings-advanced-link {
  background: none;
  border: none;
  padding: 8px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-mute);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}
.settings-advanced-link:hover {
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.04);
}
.settings-advanced-link:active {
  background: rgba(255, 255, 255, 0.08);
}
.settings-advanced-link svg { opacity: 0.7; }

/* Advanced sub-sheet stacks above the Settings sheet. */
#advancedSheet { z-index: 1010; }
.sheet-back { margin-right: 4px; }

/* ---------- Email Integration (Settings sheet) ---------- */
.email-integration {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 8px;
}

.email-status-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.email-status-line {
  display: flex;
  align-items: center;
  gap: 10px;
}
.email-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--line);
}
.email-status-dot.ok {
  background: var(--green);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--green-dim), 0 0 8px var(--green);
}
.email-status-dot.bad {
  background: var(--red);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--red-dim), 0 0 8px var(--red);
}
.email-status-dot.off {
  background: var(--ink-faint);
}
.email-status-text {
  font-weight: 700;
  color: var(--ink);
  font-size: 15px;
  word-break: break-word;
}
.email-status-account {
  color: var(--ink-soft);
  font-size: 13px;
  word-break: break-all;
  /* Left-align with the status text by skipping the 10px dot + 10px gap. */
  margin-left: 20px;
  margin-top: -2px;
}
.email-status-account:empty { display: none; }

.email-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.email-actions .btn { flex: 1 1 auto; min-width: 0; }

.email-device-box {
  background: var(--bg-elev);
  border: 1px dashed var(--brick);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.email-device-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.email-device-step {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
}
.email-device-code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 14px;
  color: var(--brick-soft);
  user-select: all;
}
.email-device-status {
  margin: 4px 0 0;
  color: var(--ink-mute);
  font-size: 12px;
  font-style: italic;
}
.btn.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
  letter-spacing: 0.08em;
  align-self: flex-start;
}

/* ---------- Timeline: email preview pane ---------- */
.tl-preview-btn {
  /* Same shape as Send-now but a touch more muted so it doesn't compete. */
  font-weight: 600;
}
.tl-preview-pane {
  /* Wraps under the row using flex-basis: 100% on the .tl-row flex container. */
  flex-basis: 100%;
  margin-top: 4px;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-left: 2px solid var(--brick);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tl-preview-k {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 4px;
}
.tl-preview-subject {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
  word-break: break-word;
}
.tl-preview-body-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-soft);
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
