:root {
  /*
    Palette — "Sandy Toes": a calm, official scheme of muted teal-blues on
    warm ivory paper. One deep teal carries structure, headings and buttons;
    a soft sky blue handles accents and focus; warm grey hairlines and cream
    surfaces keep it quiet and print-like. No loud colour anywhere.
      658689 teal-grey · 6DABC4 sky blue · DCD3CE warm grey
      94B9CC muted blue · F5EFEA ivory
  */
  --white: #ffffff;
  --cream: #f5efea;           /* warm ivory — page bg + light text on dark */
  --sage: #4f7d76;            /* muted teal-green — success / positive accent */
  --green-tint: #eaf1f3;      /* soft blue wash — tinted backgrounds */
  --green-tint-mid: #d7e4ea;  /* stronger blue tint */
  --green-tint-border: #bcd2da;
  --sea: #ece4da;             /* warm sand — chips / soft fills / light text on teal */
  --slate: #7c817f;           /* warm grey — muted text */
  --forest: #3f5d61;          /* deep teal — brand: panels, buttons, headings */
  --forest-deep: #658689;     /* teal-grey — gradient light end / mid accents */
  --saffron: #3d7d8a;         /* teal-blue — accents, hovers, links, focus */
  --saffron-bright: #6dabc4;  /* sky blue — small highlights only */
  --green-deep: #2f5b5f;      /* deep teal — text on tints / secondary hovers */
  --accent-soft: #94b9cc;     /* muted blue — soft washes / focus glow */

  --bg: var(--cream);
  --surface: var(--white);
  --ink: #2b3a3c;             /* dark slate — body copy */
  --muted: var(--slate);
  --line: #dcd3ce;            /* warm hairline */
  --brand: var(--forest);
  --brand-2: var(--sage);
  --accent: var(--saffron);
  --ok: var(--sage);
  --danger: #9e4a3a;          /* muted brick red */
  --chip: var(--sea);
  --blank: var(--saffron);
  --shadow: 0 8px 24px rgba(40, 58, 61, 0.10);
  --radius: 12px;
  --sidebar: 10%;
}

* { box-sizing: border-box; }
html, body, #app {
  margin: 0;
  height: 100%;
  overflow: hidden;
}
body {
  font-family: var(--font-gu);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}
body.lang-en { font-family: var(--font-en); }
button, input, select, textarea { font: inherit; }
a { color: var(--brand); }
button { cursor: pointer; }

.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  overflow: hidden;
}
.sidebar {
  background: var(--forest);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--cream);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
}
.brand { font-family: var(--font-display); font-size: 1.25rem; line-height: 1.25; }
.brand small { display: block; opacity: 0.7; font-size: 0.72rem; margin-top: 4px; color: var(--sea); }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav button {
  text-align: left; background: transparent; border: 0; color: inherit;
  padding: 9px 11px; border-radius: 8px;
}
.nav button:hover, .nav button.active { background: rgba(248, 243, 236, 0.16); }
.user-box {
  font-size: 0.85rem; opacity: 0.95;
  border-top: 1px solid rgba(248, 243, 236, 0.25); padding-top: 12px;
}
.main {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 12px;
  min-width: 0;
  background: var(--cream);
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-shrink: 0; margin-bottom: 12px;
}
.topbar h1 {
  margin: 0; font-family: var(--font-display);
  font-size: 1.45rem; font-weight: 600; min-width: 0; color: var(--forest);
}
.lang-toggle { display: flex; gap: 4px; flex-shrink: 0; z-index: 5; position: relative; align-items: center; }
.lang-toggle-label {
  font-size: 0.72rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em; margin-right: 4px;
}
.lang-toggle button {
  border: 1px solid var(--line); background: var(--white); color: var(--muted);
  border-radius: 8px; padding: 7px 12px; font-weight: 600; pointer-events: auto;
}
.lang-toggle button.active {
  background: var(--forest); color: var(--cream); border-color: var(--forest);
}

.btn, .btn-ghost, .btn-danger, .btn-ok {
  border: 0; border-radius: 9px; padding: 9px 14px; font-weight: 600;
}
/* Deep teal with white text; darkens a touch on hover for feedback. */
.btn { background: var(--forest); color: var(--white); }
.btn:hover { background: #33494c; }
.btn-ghost { background: var(--white); border: 1px solid var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--green-tint); border-color: var(--green-tint-border); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-ok { background: var(--sage); color: var(--white); }
.btn-ok:hover { background: var(--green-deep); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 4px 8px; font-size: 0.8rem; }
.btn-icon {
  width: 32px; height: 32px; padding: 0; border-radius: 8px;
  border: 1px solid var(--line); background: var(--white); color: var(--muted);
  font-size: 1.1rem; line-height: 1; flex-shrink: 0;
}
.btn-icon:hover { background: var(--green-tint); color: var(--green-deep); }

#content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  overflow: auto;
  min-height: 0;
  flex: 1;
}
.panel h2 { margin: 0 0 8px; font-size: 1.05rem; color: var(--forest); }
.panel-lead { margin: 0 0 12px; color: var(--muted); font-size: 0.88rem; }

.grid { display: grid; gap: 12px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; color: var(--forest); }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 0; }
.field label { font-weight: 600; font-size: 0.88rem; color: var(--forest); }
.field .req { color: var(--danger); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: var(--white); width: 100%;
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(148, 185, 204, 0.55); border-color: var(--saffron);
}
.field textarea { min-height: 72px; resize: vertical; }
.field .help { color: var(--muted); font-size: 0.78rem; }
.hint-box {
  padding: 10px 12px; background: var(--green-tint); border-left: 3px solid var(--sage);
  border-radius: 6px; font-size: 0.85rem; color: var(--green-deep); margin-bottom: 10px;
}
.error { color: var(--danger); font-size: 0.88rem; margin-top: 8px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; background: var(--sea); color: var(--forest);
}
.badge.draft { background: var(--sea); color: var(--slate); }
.badge.published, .badge.approved, .badge.dispatched { background: var(--green-tint-mid); color: var(--green-deep); }
.badge.pending_approval { background: #f6e6cf; color: #8a5a1c; }
.badge.returned { background: #f0dcd4; color: var(--danger); }
.empty { color: var(--muted); padding: 20px; text-align: center; }

/* ---- Login ---- */
.login-wrap {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(280px, 44%) 1fr;
  overflow: hidden;
  background: var(--cream);
}
.login-brand {
  /* Clean, official: a single deep-teal panel — no gradient, no curve. */
  background: var(--forest);
  color: var(--cream);
  padding: 56px 56px 40px 64px;
  display: flex;
  flex-direction: column;
  /*
    Reading order, not symmetry. One left spine at 64px: identity enters first
    at the top, the step ribbon sits low as peripheral reassurance, and the
    space between them is what pushes the eye across to the form.
  */
  align-items: flex-start;
  text-align: left;
  position: relative;
  z-index: 1;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}
.login-brand > * { position: relative; z-index: 2; }

.login-brand-mark {
  width: 64px; height: 64px;
  border: 1px solid rgba(245, 239, 234, 0.35);
  border-radius: 12px;
  display: grid; place-items: center;
  color: var(--cream);
  margin: 0 0 22px;
  background: rgba(245, 239, 234, 0.10);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.login-brand h1 {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 3.2vw, 2.65rem);
  font-weight: 600;
  margin: 0 0 12px;
  line-height: 1.15;
  white-space: nowrap; /* keep the brand name on one line */
}
.login-brand .tagline {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.6;
  max-width: 24ch;
  color: var(--sea);
  opacity: 0.88;
}

.login-brand-top {
  flex: 0 0 auto;
  max-width: 28ch;
}
/* Process steps sit in the mid-band of the brand panel (~45% of its height). */
.login-steps {
  list-style: none;
  margin: auto 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(28px, 4.5vh, 48px);
  position: relative;
  width: fit-content;
  max-width: 100%;
  min-height: 45%;
  flex: 0 0 auto;
}
.login-steps::before {
  content: "";
  position: absolute;
  left: 34px; /* centre of the larger numeral circle */
  top: 36px;
  bottom: 36px;
  width: 2px;
  background: linear-gradient(
    180deg,
    rgba(248, 243, 236, 0.12) 0%,
    rgba(248, 243, 236, 0.45) 50%,
    rgba(248, 243, 236, 0.12) 100%
  );
  z-index: 0;
}
.login-steps li {
  display: flex;
  align-items: center;
  gap: 22px;
  margin: 0;
  position: relative;
  z-index: 1;
}
.login-steps .n {
  flex-shrink: 0;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2px solid rgba(245, 239, 234, 0.5);
  background: rgba(20, 38, 40, 0.4);
  box-shadow: 0 0 0 6px rgba(245, 239, 234, 0.1);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--cream);
  transition: transform 0.22s ease, background 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
}
.login-steps .step-label {
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  font-weight: 500;
  line-height: 1.35;
  color: var(--cream);
  opacity: 0.94;
  max-width: 16ch;
  transition: opacity 0.22s ease;
}
/* A quiet, official hover: the numeral warms slightly, no bounce. */
.login-steps li:hover .n {
  background: rgba(245, 239, 234, 0.16);
  border-color: var(--cream);
  box-shadow: 0 0 0 5px rgba(245, 239, 234, 0.14);
}
.login-steps li:hover .step-label {
  opacity: 1;
}
.login-brand-foot {
  font-size: 0.82rem;
  opacity: 0.75;
  color: var(--sea);
  margin-top: 0;
  flex: 0 0 auto;
}
.login-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: auto;
  background:
    radial-gradient(900px 480px at 100% 0%, rgba(148, 185, 204, 0.16) 0%, transparent 55%),
    var(--cream);
  position: relative;
}
.login-main-top {
  display: flex;
  justify-content: flex-end;
  padding: 20px 28px 0;
  position: relative;
  z-index: 2;
}
/*
  Eye-stop #2. The optical centre sits above the geometric one, so the block is
  nudged up — dead-centring makes a form feel like it is sinking.
*/
.login-main-body {
  margin: auto;
  padding: 0 32px 40px;
  width: min(464px, 100%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  position: relative;
  z-index: 2;
}
.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 34px 36px 32px;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: 0 18px 44px rgba(40, 58, 61, 0.12);
  border-radius: 14px;
  animation: login-in 0.45s ease-out;
}
@keyframes login-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
/* Verb-forward: names the destination, not the widget. */
.login-card h2 {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 600;
  margin: 0 0 6px;
  line-height: 1.25;
  color: var(--forest);
}
.login-card .lead {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.95rem;
}
.login-card .field { margin-bottom: 16px; }
.login-card .field input {
  padding: 12px 14px;
  font-size: 1rem;
  border-radius: 10px;
}
.login-card .btn {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  margin-top: 4px;
}

@media (max-width: 900px) {
  .login-wrap {
    grid-template-columns: 1fr;
    /* Stacked panels are taller than the viewport — let the page scroll. */
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
  }
  #app { overflow: auto; }
  .login-brand {
    padding: 28px 24px 32px;
    min-height: auto;
  }
  .login-main {
    height: auto;
    overflow: visible;
  }
  .login-brand-top { margin-bottom: 24px; }
  /* No centre band to float in when stacked — sit under the identity block. */
  .login-steps {
    margin: 12px 0 16px;
    gap: 22px;
    min-height: 0;
  }
  .login-steps .n { width: 56px; height: 56px; font-size: 1.35rem; }
  .login-steps::before { left: 28px; }
  .login-steps .step-label { font-size: 1.15rem; }
  .login-main-body { width: 100%; padding: 12px 20px 32px; }
  .login-card { padding: 22px 22px 26px; }
}

/* ---- Draft / template workspace ---- */
.draft-workspace {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 12px;
  overflow: hidden;
}
.letter-pane {
  background: var(--green-tint);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  min-height: 0;
  padding: 16px;
  position: relative;
}
.letter-pane-label {
  position: sticky; top: 0; z-index: 2;
  display: inline-block; margin-bottom: 10px;
  background: var(--forest); color: var(--cream);
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; padding: 4px 10px; border-radius: 999px;
}
.form-pane {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.form-pane-head {
  padding: 12px 14px 8px; border-bottom: 1px solid var(--line); flex-shrink: 0;
  background: linear-gradient(180deg, var(--white) 0%, var(--cream) 100%);
}
.form-pane-head h2 { margin: 0 0 4px; font-size: 1rem; color: var(--forest); }
.form-pane-head p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.form-pane-body {
  flex: 1; overflow: auto; padding: 10px 14px; min-height: 0;
}
.form-pane-foot {
  flex-shrink: 0; padding: 12px 14px;
  border-top: 1px solid var(--green-tint-border);
  background: var(--green-tint);
}

.kv-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--green-tint-border);
}
.kv-row:last-child { border-bottom: 0; }
.kv-row .field { margin: 0; }
.kv-menu { position: relative; padding-top: 22px; }
.kv-menu-pop {
  display: none; position: absolute; right: 0; top: 54px; z-index: 20;
  width: 220px; background: var(--white); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 10px;
}
.kv-menu.open .kv-menu-pop { display: block; }
.kv-menu-pop .help { margin-top: 6px; }

.document-sheet {
  background: var(--white); max-width: 210mm; margin: 0 auto;
  padding: 22px 26px; box-shadow: var(--shadow); line-height: 1.65; font-size: 14px;
  color: #111; /* the letter reads in black, like an official document */
}
.lh-header {
  display: flex; gap: 12px; align-items: center;
  border-bottom: 2px solid var(--forest); padding-bottom: 10px; margin-bottom: 16px;
}
.lh-emblem { font-size: 28px; color: var(--sage); }
.lh-dept { font-weight: 700; }
.lh-place { color: var(--muted); font-size: 0.9em; }
.lh-footer {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line);
  font-size: 0.82em; color: var(--muted); text-align: center;
}
/* Letterheads admin — selected item in the list */
.lh-pick.is-active { border-color: var(--saffron); color: var(--forest); font-weight: 600; }

/* ---- Gujarati transliteration (phonetic typing) ---- */
.translit-toggle {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  font-size: 0.82rem; color: var(--muted); cursor: pointer; user-select: none;
}
.translit-toggle small { color: var(--muted); font-family: var(--font-letter-gu); }
.translit-offline {
  margin-left: 10px; font-size: 0.78rem; color: var(--danger); font-weight: 600;
}
.translit-pop {
  position: fixed; z-index: 60;
  min-width: 150px; max-width: 340px; max-height: 240px; overflow: auto;
  background: var(--white); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); padding: 4px;
}
.translit-item {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 7px 10px; border-radius: 7px; cursor: pointer; color: var(--ink);
  font-family: var(--font-letter-gu); font-size: 1.02rem; line-height: 1.3;
}
.translit-item:hover, .translit-item.active {
  background: var(--green-tint); color: var(--green-deep);
}
.urgent { color: var(--danger); font-weight: 700; text-align: center; }
.placeholder-blank {
  display: inline;
  color: var(--forest);
  background: var(--cream);
  border-bottom: 2px dashed var(--sage);
  font-weight: 700;
  font-size: 0.92em;
  letter-spacing: 0.02em;
  padding: 0 3px;
  border-radius: 3px;
}

/*
  Fill marks — only in the live "writing" preview (never in the final preview).
  A blank variable shows its name in RED; once you type a value it turns YELLOW
  but stays highlighted; focusing its field rings the spot(s) it maps to.
*/
.fill-mark {
  display: inline;
  padding: 0 3px;
  border-radius: 3px;
  scroll-margin: 32px;
  transition: background 0.15s ease, box-shadow 0.15s ease, outline-color 0.15s ease;
}
.fill-mark.is-empty {
  color: #c0281c;
  background: #fbe4e2;
  border-bottom: 1px dashed #dd9b95;
  font-weight: 600;
}
.fill-mark.is-filled {
  color: #1a1a1a;
  background: #fff2a8;
  box-shadow: inset 0 -1px 0 #e6cf6a;
}
.fill-mark.is-active {
  outline: 2px solid var(--saffron);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px rgba(148, 185, 204, 0.5);
}

.confirm-workspace {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 10px; overflow: hidden;
}
.confirm-bar {
  flex-shrink: 0; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px;
}
.confirm-preview {
  flex: 1; min-height: 0; overflow: auto;
  background: var(--sea); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}

.editor-area {
  width: 100%; min-height: 160px; border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; font-family: ui-monospace, monospace; font-size: 0.85rem;
  background: var(--cream);
}
.editor-toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.var-list { display: flex; flex-direction: column; gap: 8px; }
.var-item {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--cream);
}
.var-chip {
  display: inline-block; background: var(--green-tint); color: var(--green-deep);
  border-radius: 5px; padding: 1px 6px; font-family: ui-monospace, monospace; font-size: 0.85em;
}
.details-alt {
  border: 1px solid var(--line); border-radius: 8px; background: var(--cream); padding: 0 10px; margin-top: 6px;
}
.details-alt summary {
  cursor: pointer; padding: 8px 0; color: var(--muted); font-size: 0.82rem; font-weight: 600;
}
.stack-scroll {
  flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 12px;
}
.tpl-workspace {
  flex: 1; min-height: 0;
  display: grid;
  /* Writing area takes all remaining width; settings is a fixed narrow column. */
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 12px;
  overflow: hidden;
}
/* Full-width writing mode — hides the settings pane so the letter fills the screen. */
.tpl-workspace.editor-full { grid-template-columns: 1fr; }
.tpl-workspace.editor-full .form-pane { display: none; }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; max-height: 28vh; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .draft-workspace, .tpl-workspace, .grid-4, .grid-2 { grid-template-columns: 1fr; }
}


/* ---- Interactive template canvas ---- */
.letter-editor-pane { display: flex; flex-direction: column; }
.letter-pane-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 10px; flex-shrink: 0;
}
.letter-canvas-wrap {
  /* Plain scroll container: the sheet grows with content and scrolls when tall,
     so the border always encloses the whole letter. */
  flex: 1; min-height: 0; overflow: auto; max-width: none; width: 100%;
}
.letter-canvas {
  /* Grows with content (tall default for an empty letter), never a fixed box. */
  min-height: 420px;
  outline: none;
  cursor: text;
  padding: 4px 2px 24px;
  tab-size: 4;
}
/*
  Alignment lives on the paragraph. execCommand also stamps `text-align` onto
  the variable chips inside the selection — keep them inline-flex so they flow
  and move WITH the aligned text instead of collapsing onto their own line.
*/
.letter-canvas .tpl-var-chip[style] { display: inline-flex; }

/* ---- Formatting toolbar (template + letter editors) ---- */
.editor-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 3px;
  padding: 6px; margin-bottom: 8px; flex-shrink: 0;
  background: var(--white); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 3;
}
.editor-toolbar .tb-sep {
  width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px;
}
.editor-toolbar button {
  min-width: 30px; height: 30px; padding: 0 7px;
  border: 1px solid transparent; border-radius: 7px; background: transparent;
  color: var(--ink); font-size: 0.95rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.editor-toolbar button:hover { background: var(--green-tint); }
.editor-toolbar button.active {
  background: var(--green-tint-mid); border-color: var(--green-tint-border); color: var(--green-deep);
}
.editor-toolbar button b { font-weight: 800; }
.editor-toolbar button i { font-style: italic; }
.editor-toolbar button u { text-decoration: underline; }
.editor-toolbar select {
  height: 30px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--white); color: var(--ink); padding: 0 6px; font-size: 0.82rem;
}

/* Small utilities used by the reworked editor / master panels */
.linklike {
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
  color: var(--saffron); text-decoration: underline;
}
.muted-text { color: var(--muted); }

/* Dashboard + Master data (variables manager) */
tr.click-row { cursor: pointer; }
tr.click-row:hover td { background: var(--green-tint); }
.master-cols {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  flex: 1; min-height: 0; overflow: auto;
}
@media (max-width: 1000px) { .master-cols { grid-template-columns: 1fr; } }
.v-label {
  border: 1px solid transparent; background: transparent; border-radius: 6px;
  padding: 4px 6px; width: 100%; color: var(--ink);
}
.v-label:hover, .v-label:focus { border-color: var(--line); background: var(--white); outline: none; }
.v-type {
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
  background: var(--white); color: var(--ink);
}
.letter-canvas:focus {
  box-shadow: inset 0 0 0 2px rgba(148, 185, 204, 0.4);
  border-radius: 6px;
}
.letter-canvas p { margin: 0 0 0.75em; }
.tpl-var-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  background: var(--green-tint-mid);
  color: var(--green-deep);
  border: 1.5px dashed var(--sage);
  border-radius: 6px;
  padding: 1px 20px 1px 8px;
  margin: 0 2px;
  font-weight: 600;
  font-size: 0.92em;
  cursor: pointer;
  user-select: none;
  vertical-align: baseline;
  -webkit-user-modify: read-only;
}
.tpl-var-chip-label { pointer-events: none; }
.tpl-var-chip-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 1px solid var(--green-tint-border);
  border-radius: 999px;
  background: var(--white);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(21, 112, 63, 0.12);
}
.tpl-var-chip-remove:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--white);
}
/*
  Reflect bold / italic / underline applied around a chip onto its label, so
  formatting a variable is visible while editing (the chip is an atomic inline
  box, so ancestor <b>/<i>/<u> don't reach it on their own).
*/
.letter-canvas :is(b, strong) .tpl-var-chip-label { font-weight: 800; }
.letter-canvas :is(i, em) .tpl-var-chip-label { font-style: italic; }
.letter-canvas u .tpl-var-chip-label { text-decoration: underline; }
/* Selected chip — clicking a chip selects it for per-variable formatting. */
.letter-canvas .tpl-var-chip.is-selected {
  outline: 2px solid var(--saffron);
  outline-offset: 1px;
}
.palette-title {
  margin: 4px 0 8px;
  font-size: 0.88rem;
  color: var(--forest);
}
.var-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.palette-help {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: var(--muted);
}
.var-list-title {
  margin: 4px 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--forest);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.palette-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  border: 1px solid var(--green-tint-border);
  background: var(--green-tint);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  max-width: 100%;
  color: var(--ink);
}
.palette-chip:hover {
  border-color: var(--sage);
  background: var(--green-tint-mid);
}
.palette-chip:active { cursor: grabbing; }
.palette-chip-label {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--forest);
}
.palette-chip small {
  color: var(--muted);
  font-size: 0.72rem;
}

.letter-editor-pane { position: relative; }
.quick-var-row { display: flex; gap: 8px; margin-top: 6px; }
.quick-var-row input { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.var-suggest {
  position: absolute;
  z-index: 40;
  min-width: 240px;
  max-width: min(360px, 90%);
  max-height: 260px;
  overflow: auto;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
}
.var-suggest-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
}
.var-suggest-item:hover,
.var-suggest-item.active {
  background: var(--green-tint);
}
.var-suggest-item strong { font-size: 0.9rem; color: var(--forest); }
.var-suggest-item small { font-size: 0.75rem; color: var(--muted); }

/* Plain surfaces — clean white panels, no watermark. */
.dashboard-panel {
  position: relative;
  background: var(--surface);
}
#content > .panel:not(.dashboard-panel) {
  position: relative;
  background: var(--surface);
}
.dashboard-sections { align-items: stretch; }
.surface-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.dashboard-card {
  background: var(--surface);
  padding: 14px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
}
.dashboard-card table { margin-top: 8px; }
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.section-head h2 { margin: 0 0 4px; }

#ui-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
}
.toast-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  min-width: 240px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(17, 24, 39, 0.16);
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.success {
  border-color: var(--green-tint-border);
  background: var(--green-tint);
  color: var(--green-deep);
}
.toast.error { border-color: #e3b7aa; }
.toast.hide { opacity: 0; transform: translateY(-4px); }
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(28, 40, 42, 0.5);
  pointer-events: auto;
  padding: 20px;
}
.modal-card {
  width: min(520px, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 20px 44px rgba(17, 24, 39, 0.18);
  overflow: hidden;
}
.modal-head,
.modal-body,
.modal-actions { padding: 16px 18px; }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.05rem; color: var(--forest); }
.modal-body { padding-bottom: 8px; }
.modal-actions {
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-copy { margin: 0; color: var(--ink); line-height: 1.55; }
.modal-body textarea,
.modal-body input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--white);
  color: var(--ink);
}
.workflow-card,
.return-banner,
.status-note,
.submit-result-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.return-banner,
.status-note {
  padding: 12px 14px;
}
.return-banner {
  background: #fff8ee;
  border-color: #f0d3a3;
}
.status-note {
  margin-top: 8px;
  color: var(--muted);
}
.workflow-card {
  padding: 12px 14px;
}
.workflow-title {
  font-weight: 700;
  color: var(--forest);
  margin-bottom: 8px;
}
.workflow-line {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.workflow-line li {
  min-width: 160px;
  flex: 1 1 180px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--cream);
}
.workflow-line strong {
  display: block;
  text-transform: capitalize;
  color: var(--forest);
}
.workflow-line small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}
.workflow-comment {
  margin-top: 6px;
  color: var(--ink);
}
.submit-result {
  display: grid;
  place-items: center;
  min-height: 100%;
}
.submit-result-card {
  width: min(760px, 100%);
  padding: 24px;
}
.submit-result-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}
.submit-result-head h2 {
  margin: 0 0 4px;
  color: var(--forest);
}
.submit-next {
  margin: 14px 0 18px;
  color: var(--ink);
  line-height: 1.6;
}
