/* render-service app styles.
   One stylesheet, no framework, no build step. Light and dark are driven by
   custom properties so every component is themed in one place. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7fb;
  --bg-sunken: #eef0f7;
  --fg: #1a1a2e;
  --fg-soft: #5a5a76;
  --fg-faint: #8a8aa0;
  --line: #e3e5ee;
  --line-strong: #cfd2e0;
  --accent: #2d6cdf;
  --accent-fg: #ffffff;
  --accent-soft: #eaf1fd;
  --bad: #c0392b;
  --bad-soft: #fdecea;
  --good: #1e7a4d;
  --good-soft: #e8f6ee;
  --code-bg: #14161f;
  --code-fg: #e6e8f0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 31, .06), 0 8px 24px rgba(20, 22, 31, .06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1118;
    --bg-soft: #161923;
    --bg-sunken: #1d2130;
    --fg: #e8eaf2;
    --fg-soft: #a6abbd;
    --fg-faint: #7b8095;
    --line: #262b3a;
    --line-strong: #333a4d;
    --accent: #5b8dea;
    --accent-fg: #0f1118;
    --accent-soft: #1a2438;
    --bad: #ff8a7a;
    --bad-soft: #2a1a18;
    --good: #6ddba0;
    --good-soft: #14251c;
    --code-bg: #080a10;
    --code-fg: #e6e8f0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- chrome ---------- */

.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand {
  font-weight: 700; letter-spacing: -.2px; color: var(--fg);
  font-family: var(--mono); font-size: 14px;
}
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }
.nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--fg-soft);
  font-size: 14px; white-space: nowrap;
}
.nav a:hover { background: var(--bg-sunken); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar-end { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.who { color: var(--fg-faint); font-size: 13px; }
@media (max-width: 720px) { .who { display: none; } }

.wrap { max-width: 1040px; margin: 0 auto; padding: 28px 24px 64px; }
.wrap.wide { max-width: 1440px; }

.foot {
  display: flex; gap: 8px; justify-content: center; align-items: center;
  padding: 24px; color: var(--fg-faint); font-size: 12px;
  border-top: 1px solid var(--line);
}
.dot { opacity: .5; }
.pill {
  padding: 2px 8px; border-radius: 999px; font-size: 11px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}

/* ---------- type ---------- */

h1 { font-size: 24px; letter-spacing: -.4px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.sub { color: var(--fg-soft); margin: 0 0 24px; }
.eyebrow {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--fg-faint); font-weight: 700; margin: 0 0 8px;
}

/* ---------- surfaces ---------- */

.card {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 800px) {
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}

.stat { font-size: 30px; font-weight: 700; letter-spacing: -.6px; }
.stat-label { color: var(--fg-faint); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }

/* ---------- forms ---------- */

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.hint { color: var(--fg-faint); font-size: 12px; font-weight: 400; }

input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; padding: 9px 11px;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line-strong); border-radius: 8px;
  font: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.field + .field { margin-top: 14px; }
textarea { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; resize: vertical; }

.btn, .btn-quiet, .btn-bad {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  white-space: nowrap;
}
.btn { background: var(--accent); color: var(--accent-fg); }
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn-quiet { background: var(--bg); color: var(--fg); border-color: var(--line-strong); }
.btn-quiet:hover { background: var(--bg-sunken); text-decoration: none; }
.btn-bad { background: transparent; color: var(--bad); border-color: transparent; }
.btn-bad:hover { background: var(--bad-soft); }
.btn:disabled, .btn-quiet:disabled { opacity: .5; cursor: not-allowed; }
.btn-wide { width: 100%; justify-content: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* ---------- alerts ---------- */

.alert {
  padding: 11px 14px; border-radius: 8px; margin-bottom: 18px;
  font-size: 14px; border: 1px solid transparent;
}
.alert-bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.alert-ok { background: var(--good-soft); color: var(--good); border-color: var(--good); }

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--fg-faint); padding: 0 10px 8px 0; border-bottom: 1px solid var(--line);
}
td { padding: 12px 10px 12px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; }

/* ---------- code ---------- */

pre, code, .mono { font-family: var(--mono); }
pre {
  background: var(--code-bg); color: var(--code-fg);
  padding: 14px 16px; border-radius: 8px; overflow-x: auto;
  font-size: 12.5px; line-height: 1.6; margin: 0;
}
code.inline {
  background: var(--bg-sunken); padding: 1px 5px; border-radius: 4px; font-size: 12.5px;
}
.copy-wrap { position: relative; }
.copy-wrap .btn-copy {
  position: absolute; top: 8px; right: 8px;
  background: rgba(255, 255, 255, .1); color: #e6e8f0;
  border: 1px solid rgba(255, 255, 255, .2); border-radius: 6px;
  padding: 4px 9px; font: 600 11px/1 var(--mono); cursor: pointer;
}
.btn-copy:hover { background: rgba(255, 255, 255, .2); }

.secret {
  display: block; padding: 12px 14px; border-radius: 8px;
  background: var(--code-bg); color: var(--code-fg);
  font-family: var(--mono); font-size: 13px; word-break: break-all;
}

/* ---------- empty + onboarding ---------- */

.empty { text-align: center; padding: 44px 20px; color: var(--fg-soft); }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li {
  position: relative; padding: 0 0 18px 38px; counter-increment: step;
}
.steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: -1px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 13px;
  display: grid; place-items: center;
}
.steps li.done::before { content: "✓"; background: var(--good-soft); color: var(--good); }
.steps li:last-child { padding-bottom: 0; }

.auth { max-width: 400px; margin: 56px auto; }
.auth .card { box-shadow: var(--shadow); }
.auth h1 { text-align: center; }
.auth .sub { text-align: center; }
.auth-alt { text-align: center; margin-top: 18px; color: var(--fg-soft); font-size: 14px; }

/* ---------- editor ---------- */

.ed {
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
}
@media (max-width: 1100px) { .ed { grid-template-columns: 1fr; } }

/* Sticky so Save and Preview stay reachable while editing a long template.
   Sits below the 56px topbar; the toolbar below stacks under both. */
.ed-head {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin-bottom: 16px;
  position: sticky; top: 56px; z-index: 15;
  background: var(--bg-soft);
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.ed-name {
  font-size: 20px; font-weight: 700; letter-spacing: -.3px;
  border: 1px solid transparent; background: transparent; color: var(--fg);
  padding: 6px 8px; border-radius: 8px; width: min(360px, 100%);
}
.ed-name:hover { border-color: var(--line-strong); }
.saved { color: var(--fg-faint); font-size: 12.5px; }

.toolbar {
  display: flex; gap: 3px; flex-wrap: wrap; padding: 8px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0; border-bottom: none;
  position: sticky; top: 121px; z-index: 10;
}
/* Below this width the header wraps to two rows and its height stops being
   predictable, so stacking a second sticky element under it would overlap. */
@media (max-width: 900px) {
  .ed-head { position: static; }
  .toolbar { top: 56px; }
}
.toolbar button {
  min-width: 30px; height: 30px; padding: 0 8px;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--fg-soft); font: 600 13px/1 inherit; cursor: pointer;
}
.toolbar button:hover { background: var(--bg-sunken); color: var(--fg); }
.toolbar .sep { width: 1px; background: var(--line); margin: 4px 5px; }
.toolbar select { width: auto; padding: 4px 6px; font-size: 12.5px; height: 30px; }

.canvas {
  background: #fff; color: #1a1a2e;
  border: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius);
  padding: 32px 36px; min-height: 460px;
  font: 14px/1.6 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-wrap: break-word;
}
.canvas:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.canvas table { width: 100%; }
.canvas th, .canvas td { border-bottom: 1px solid #e3e5ee; padding: 8px 6px; }
.canvas img { max-width: 100%; }

/* Merge-field chips. contenteditable=false in the markup so a chip deletes as a
   single unit instead of losing one character at a time. */
.mf {
  display: inline-block; padding: 1px 7px; margin: 0 1px; border-radius: 5px;
  background: #eaf1fd; color: #2158b8; border: 1px solid #c5d9f7;
  font: 600 12px/1.5 var(--mono); cursor: default; user-select: all;
}
.mf.loop { background: #fdf1e3; color: #a8620d; border-color: #f5d9b3; }

.panel { position: sticky; top: 72px; display: grid; gap: 16px; }
.fields { display: flex; flex-wrap: wrap; gap: 6px; }
.field-chip {
  padding: 3px 9px; border-radius: 6px; cursor: pointer;
  background: var(--bg-sunken); border: 1px solid var(--line-strong);
  font: 600 12px/1.6 var(--mono); color: var(--fg-soft);
}
.field-chip:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.field-chip.loop { color: #a8620d; }

.preview-frame {
  width: 100%; height: 460px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg-sunken);
}
.muted { color: var(--fg-faint); font-size: 12.5px; }
.err-inline { color: var(--bad); font-size: 12.5px; white-space: pre-wrap; }

/* ---------- long-form prose (terms, privacy) ---------- */

.prose {
  max-width: 68ch; /* keeps lines readable rather than full-width */
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 32px 34px;
}
.prose h1 { margin-bottom: 18px; }
.prose h2 { font-size: 15px; margin: 26px 0 8px; }
.prose p, .prose li { color: var(--fg-soft); }
.prose ul { padding-left: 20px; }
.prose li { margin-bottom: 6px; }
.prose table { margin: 12px 0 6px; font-size: 13.5px; }
.prose td { color: var(--fg-soft); }
.prose strong { color: var(--fg); }
@media (max-width: 640px) { .prose { padding: 22px 18px; } }

/* ---------- destructive actions ---------- */

.danger {
  border-color: var(--bad);
}
.danger .eyebrow { color: var(--bad); }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button {
  padding: 5px 11px; border-radius: 7px; border: 1px solid transparent;
  background: transparent; color: var(--fg-soft); font: 600 13px/1 inherit; cursor: pointer;
}
.tabs button.on { background: var(--accent-soft); color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- admin ---------- */

.chip-stripe {
  margin-left: 6px; padding: 2px 6px; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent);
  font: 700 9.5px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase;
}
/* "never" is the answer that matters most on this page, so it should read as a
   state rather than as missing data. */
.never { color: var(--fg-faint); font-style: italic; }
