: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 · F2F4F8 soft periwinkle
  */
  --white: #ffffff;
  --cream: #f2f4f8;           /* soft periwinkle — 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: #dfe5ef;             /* soft periwinkle wash — preview / chips / soft fills */
  --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 0.5rem 1.5rem rgba(40, 58, 61, 0.10);
  --radius: 0.75rem;

  /* 1.1× UI scale — rem is based on html font-size */
  --space-1: 0.35rem;   /* ~6px at 16.5px root */
  --space-2: 0.55rem;   /* ~9px */
  --space-3: 0.85rem;   /* ~14px */
  --space-4: 1.15rem;   /* ~19px */
  --control-h: 2.2rem;  /* ~36px — inputs / buttons / toolbar */
  --sidebar-width: min(14rem, 14%);
}

* { box-sizing: border-box; }
html {
  font-size: 16.5px; /* 1.1× of prior 15px body — scales all rem */
}
html, body, #app {
  margin: 0;
  height: 100%;
  overflow: hidden;
}
body {
  font-family: var(--font-gu);
  font-size: 1rem;
  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-width) 1fr;
  overflow: hidden;
}
.sidebar {
  background: var(--forest);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--cream);
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow: auto;
  min-width: 0;
}
.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: var(--space-1); color: var(--sea); }
.nav { display: flex; flex-direction: column; gap: var(--space-1); flex: 1; }
.nav button {
  text-align: left; background: transparent; border: 0; color: inherit;
  padding: 0.55rem 0.7rem; border-radius: 0.5rem;
  line-height: 1.35;
}
.nav button:hover, .nav button.active { background: rgba(248, 243, 236, 0.16); }
.user-box {
  font-size: 0.85rem;
  border-top: 1px solid rgba(248, 243, 236, 0.18);
  padding-top: var(--space-2);
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.user-box-id { line-height: 1.4; }
.user-box-role { margin-top: 0.15rem; opacity: 0.75; font-size: 0.78rem; }
.user-box-profile {
  line-height: 1.35;
  opacity: 0.8;
  padding: 0.15rem 0.7rem;
  font-size: 0.78rem;
  word-break: break-word;
}
.user-box-profile strong {
  font-weight: 500;
  color: rgba(248, 243, 236, 0.92);
}
.sidebar-logout {
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.7rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: rgba(248, 243, 236, 0.78);
  font-weight: 500;
  cursor: pointer;
}
.sidebar-logout:hover {
  background: rgba(248, 243, 236, 0.12);
  color: #fff;
}
.sidebar-admin {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-top: var(--space-1);
}
.sidebar-admin-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 0.55rem 0.7rem;
  border-radius: 0.5rem;
  line-height: 1.35;
  font-weight: inherit;
}
.sidebar-admin-toggle:hover,
.sidebar-admin-toggle.is-open,
.sidebar-admin-toggle.is-route-active {
  background: rgba(248, 243, 236, 0.16);
}
.sidebar-admin-chevron {
  font-size: 0.7rem;
  line-height: 1;
  opacity: 0.7;
}
.sidebar-admin-menu {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0 0 0.15rem 0.55rem;
  margin: 0 0 0 0.55rem;
  border-left: 1px solid rgba(248, 243, 236, 0.18);
}
.sidebar-admin-menu[hidden] { display: none; }
.sidebar-admin-menu button {
  text-align: left; background: transparent; border: 0; color: inherit;
  padding: 0.45rem 0.7rem; border-radius: 0.5rem;
  opacity: 0.92;
}
.sidebar-admin-menu button:hover,
.sidebar-admin-menu button.active { background: rgba(248, 243, 236, 0.16); opacity: 1; }
.page-loading {
  min-height: 12rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted, #5c6b73);
}
.page-loading p { margin: 0; font-size: 0.95rem; }
.main {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: var(--space-3) var(--space-4) var(--space-3);
  min-width: 0;
  background: var(--cream);
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-3); flex-shrink: 0; margin-bottom: var(--space-3);
}
.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: var(--space-1); flex-shrink: 0; z-index: 5; position: relative; align-items: center; }
.lang-toggle-label {
  font-size: 0.75rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em; margin-right: var(--space-1);
}
.lang-toggle button {
  border: 1px solid var(--line); background: var(--white); color: var(--muted);
  border-radius: 0.5rem; padding: 0.45rem 0.75rem; font-weight: 600; pointer-events: auto;
  min-height: var(--control-h);
}
.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: 0.55rem;
  padding: 0.5rem 0.9rem;
  min-height: var(--control-h);
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 1.25;
}
/* 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: 0.3rem 0.55rem; font-size: 0.85rem; min-height: 1.85rem; }
.btn-icon {
  width: var(--control-h); height: var(--control-h); padding: 0; border-radius: 0.5rem;
  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: var(--space-3);
  overflow: auto;
  min-height: 0;
  flex: 1;
}
.panel h2 { margin: 0 0 var(--space-2); font-size: 1.1rem; color: var(--forest); }
.panel-lead { margin: 0 0 var(--space-3); color: var(--muted); font-size: 0.92rem; }

.grid { display: grid; gap: var(--space-3); }
.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: var(--space-3); box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 0.9rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: var(--space-1); color: var(--forest); }

.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: 0; }
.field label { font-weight: 600; font-size: 0.92rem; color: var(--forest); }
.field .req { color: var(--danger); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 0.5rem;
  padding: 0.5rem 0.7rem; background: var(--white); width: 100%;
  color: var(--ink);
  min-height: var(--control-h);
  box-sizing: border-box;
}
.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: 4.5rem; resize: vertical; }
/* Fill-in fields: wrap text and grow downward (JS sets height); no scrollbar, no drag handle. */
.field textarea[data-autogrow] {
  min-height: 2.5rem;
  overflow: hidden;
  resize: none;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.field .help { color: var(--muted); font-size: 0.82rem; }
.hint-box {
  padding: var(--space-2) var(--space-3); background: var(--green-tint); border-left: 3px solid var(--sage);
  border-radius: 0.4rem; font-size: 0.9rem; color: var(--green-deep); margin-bottom: var(--space-2);
}
.error { color: var(--danger); font-size: 0.92rem; margin-top: var(--space-2); }
.field-error {
  margin-top: 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.35;
}
.field input.is-invalid,
.field select.is-invalid,
.field textarea.is-invalid {
  border-color: #d93025;
  box-shadow: 0 0 0 2px rgba(217, 48, 37, 0.15);
}
.row-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.45rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 0.9rem; font-weight: 650; }
td { font-size: 1rem; }

/* Keep list content and actions on stable vertical spines. The action group
   lives inside the table cell so flex layout cannot change the table grid. */
.data-table {
  table-layout: fixed;
  min-width: 680px;
}
.data-table th:last-child,
.data-table td:last-child { padding-left: 0.8rem; }
.data-table td:first-child { overflow-wrap: anywhere; }
.table-actions-cell { width: 30%; }
.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding-right: 0.35rem;
  flex-wrap: nowrap;
  white-space: nowrap;
}
.table-actions > .btn,
.table-actions > .btn-ghost,
.table-actions > .btn-danger,
.table-actions > a { flex: 0 0 auto; }
.table-actions .btn-sm {
  min-height: var(--control-h);
  padding: 0.45rem 0.8rem;
  font-size: 0.9rem;
}
.documents-table { min-width: 900px; }
.documents-table th:nth-child(1), .documents-table td:nth-child(1) { width: 18%; }
.documents-table th:nth-child(2), .documents-table td:nth-child(2) { width: 25%; }
.documents-table th:nth-child(3), .documents-table td:nth-child(3) { width: 8%; }
.documents-table th:nth-child(4), .documents-table td:nth-child(4) { width: 18%; }
.documents-table th:nth-child(5), .documents-table td:nth-child(5) { width: 31%; }
.templates-table { min-width: 760px; }
.templates-table th:nth-child(1), .templates-table td:nth-child(1) { width: 40%; }
.templates-table th:nth-child(2), .templates-table td:nth-child(2) { width: 8%; }
.templates-table th:nth-child(3), .templates-table td:nth-child(3) { width: 20%; }
.templates-table th:nth-child(4), .templates-table td:nth-child(4) { width: 32%; }
.letterheads-table { min-width: 700px; }
.letterheads-table th:nth-child(1), .letterheads-table td:nth-child(1) { width: 38%; }
.letterheads-table th:nth-child(2), .letterheads-table td:nth-child(2) { width: 17%; }
.letterheads-table th:nth-child(3), .letterheads-table td:nth-child(3) { width: 20%; }
.letterheads-table th:nth-child(4), .letterheads-table td:nth-child(4) { width: 25%; }
.dashboard-table { min-width: 620px; }
.dashboard-table th:nth-child(1), .dashboard-table td:nth-child(1) { width: 50%; }
.dashboard-table th:nth-child(2), .dashboard-table td:nth-child(2) { width: 15%; }
.dashboard-table th:nth-child(3), .dashboard-table td:nth-child(3) { width: 35%; }
.badge {
  display: inline-block; padding: 0.2rem 0.55rem; border-radius: 999px;
  font-size: 0.82rem; font-weight: 600; background: var(--sea); color: var(--forest);
}
.badge.draft { background: var(--sea); color: var(--slate); }
.badge.published, .badge.approved, .badge.dispatched, .badge.ready { 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: var(--space-4); 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: auto; min-width: 64px; height: 64px;
  padding: 0 12px;
  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.35rem;
  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: 1.9rem 2rem 1.8rem;
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: 0 1rem 2.5rem rgba(40, 58, 61, 0.12);
  border-radius: 0.85rem;
  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: var(--space-3); }
.login-card .field input {
  padding: 0.7rem 0.85rem;
  font-size: 1rem;
  min-height: var(--control-h);
  border-radius: 0.6rem;
}
.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: var(--space-3);
  overflow: hidden;
}
.letter-pane {
  background: var(--green-tint);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  min-height: 0;
  padding: var(--space-3);
  position: relative;
}
.letter-pane-label {
  display: inline-block; margin-bottom: var(--space-2);
  background: var(--forest); color: var(--cream);
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; padding: 0.3rem 0.65rem; 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: var(--space-3) var(--space-3) var(--space-2); border-bottom: 1px solid var(--line); flex-shrink: 0;
  background: linear-gradient(180deg, var(--white) 0%, var(--cream) 100%);
}
.form-pane-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.form-pane-head h2 { margin: 0 0 var(--space-1); font-size: 1.05rem; color: var(--forest); }
.form-pane-head-row h2 { margin: 0; }
.form-pane-head p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.page-size-panel {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--white);
  color: var(--ink);
  cursor: help;
  line-height: 1.2;
}
.page-size-panel-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.page-size-panel strong {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--forest);
}
.form-pane-body {
  flex: 1; overflow-x: hidden; overflow-y: auto; padding: var(--space-2) var(--space-3); min-height: 0;
}
.form-pane-foot {
  flex-shrink: 0; padding: var(--space-3);
  border-top: 1px solid var(--green-tint-border);
  background: var(--green-tint);
}

.kv-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  align-items: start;
  padding: var(--space-2) 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: 1.2rem; }
.kv-menu-pop {
  display: none; position: absolute; right: 0; top: 3rem; z-index: 20;
  width: 13rem; background: var(--white); border: 1px solid var(--line);
  border-radius: 0.6rem; box-shadow: var(--shadow); padding: var(--space-2);
}
.kv-menu.open .kv-menu-pop { display: block; }
.kv-menu-pop .help { margin-top: var(--space-1); }

.document-sheet {
  background: var(--white); max-width: 210mm; margin: 0 auto;
  padding: 22px 26px; box-shadow: var(--shadow); line-height: 1.65; font-size: 1rem;
  color: #111;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  position: relative;
}
.document-sheet.page-A4 { max-width: 210mm; min-height: 297mm; width: 100%; }
.document-sheet.page-B5 { max-width: 176mm; min-height: 250mm; width: 100%; }
.page-size-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 4;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #1f3a3c;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #9bb4b8;
  padding: 2px 7px 2px 8px;
  border-radius: 6px;
  line-height: 1.2;
  cursor: help;
  user-select: none;
}
/* Superscript help mark — sits on the page-size text like x², not a separate chip. */
sup.page-size-sup {
  font-size: 0.62em;
  font-weight: 700;
  line-height: 0;
  vertical-align: super;
  margin-left: 0.12em;
  color: #4a6a70;
  cursor: help;
  border: 0;
  background: none;
  padding: 0;
  width: auto;
  height: auto;
  border-radius: 0;
  display: inline;
  user-select: none;
}
.doc-body { flex: 1 1 auto; }
.doc-reserve {
  display: flex; align-items: center; justify-content: center;
  width: 100%; flex-shrink: 0;
  background-color: #9eb8c4;
  background-image: repeating-linear-gradient(
    -45deg,
    rgba(31, 58, 60, 0.28),
    rgba(31, 58, 60, 0.28) 10px,
    rgba(255, 255, 255, 0.22) 10px,
    rgba(255, 255, 255, 0.22) 20px
  );
  border: 2px solid #3d5c62;
  border-radius: 4px;
  margin-bottom: 8px;
  position: relative;
}
/* `display:flex` above beats the UA [hidden] rule — force hide when marked. */
.doc-reserve[hidden] {
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  padding: 0 !important;
}
.doc-reserve::after {
  content: attr(data-label);
  font-size: 0.85rem;
  font-weight: 700;
  color: #143033;
  background: rgba(255, 255, 255, 0.85);
  padding: 0.2rem 0.65rem;
  border-radius: 0.25rem;
}
.doc-reserve:not([data-label])::after,
.doc-reserve[data-label=""]::after { display: none; }
.doc-reserve-bottom { margin-top: auto; margin-bottom: 0; }
.doc-footer:empty, .doc-letterhead:empty { display: none; margin: 0; padding: 0; border: 0; }
@media print {
  .doc-reserve { border: 0 !important; background: transparent !important; box-shadow: none !important; }
  .doc-reserve::after { display: none !important; }
  .page-size-badge { display: none !important; }
  .doc-letterhead, .doc-footer, .lh-header, .lh-footer {
    border: 0 !important; margin: 0 !important; padding: 0 !important;
  }
  .doc-letterhead:empty, .doc-footer:empty { display: none !important; }
}

.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;
}

.draft-template-banner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  margin-bottom: var(--space-3); padding: 0.55rem 0.75rem;
  background: linear-gradient(180deg, #f2f4f8 0%, #e8edf5 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.letter-for-banner {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem 0.65rem;
  margin-bottom: var(--space-3); padding: 0.7rem 0.9rem;
  background: #fff; border: 1px solid var(--green-tint-border);
  border-left: 4px solid var(--forest); border-radius: var(--radius);
}
.letter-for-label {
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}
.letter-for-name {
  font-size: 1.25rem; font-weight: 700; color: var(--forest); line-height: 1.25;
}
.letter-who { color: var(--forest); }
#letter-for-slot:empty { display: none; }
.draft-template-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  width: 100%; margin: 0; padding: 0;
  background: transparent; border: 0; border-radius: calc(var(--radius) - 2px);
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.draft-template-trigger:hover .draft-template-change-label,
.draft-template-trigger:hover .draft-template-chevron { color: var(--green-deep); }
.draft-template-trigger:focus-visible {
  outline: 2px solid var(--green-deep); outline-offset: 2px;
}
.draft-template-current {
  min-width: 0; flex: 1 1 auto;
}
.draft-template-title {
  display: block; margin: 0;
  font-size: 1.05rem; font-weight: 700; color: var(--forest); line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.draft-template-side {
  display: inline-flex; align-items: center; gap: 0.45rem; flex-shrink: 0;
}
.draft-template-lang {
  display: inline-block; margin: 0; flex-shrink: 0;
  padding: 0.12rem 0.5rem; border-radius: 999px;
  background: var(--white); border: 1px solid var(--line);
  color: var(--muted); font-size: 0.8rem; line-height: 1.4;
}
.draft-template-change-label {
  font-size: 0.88rem; font-weight: 600; color: var(--forest);
}
.draft-template-chevron {
  font-size: 0.85rem; color: var(--muted); line-height: 1;
}
.draft-template-meta { margin: var(--space-1) 0 0; color: var(--muted); font-size: 0.95rem; }
@media (max-width: 640px) {
  .draft-template-banner { align-items: stretch; }
  .draft-template-trigger { flex-wrap: wrap; row-gap: 0.35rem; }
  .draft-template-title { white-space: normal; }
  .draft-template-side { margin-left: auto; }
}

.modal-card--picker {
  width: min(28rem, 100%);
  max-height: min(34rem, 88vh);
  display: flex;
  flex-direction: column;
}
.modal-card--picker .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow: hidden;
}
.tpl-pick-search { margin: 0; }
.tpl-pick-search input {
  width: 100%;
  box-sizing: border-box;
}
.tpl-pick-list {
  display: flex; flex-direction: column; gap: 0.4rem;
  flex: 1 1 auto;
  min-height: 8rem;
  max-height: min(14rem, 42vh);
  overflow-y: scroll; /* always reserve scrollbar so overflow is obvious */
  overscroll-behavior: contain;
  padding-right: 0.15rem;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #9aa5b5 transparent;
}
.tpl-pick-list::-webkit-scrollbar { width: 10px; }
.tpl-pick-list::-webkit-scrollbar-track {
  background: #eef1f6; border-radius: 999px;
}
.tpl-pick-list::-webkit-scrollbar-thumb {
  background: #9aa5b5; border-radius: 999px; border: 2px solid #eef1f6;
}
.tpl-pick-item {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  width: 100%; text-align: left;
  padding: 0.65rem 0.75rem;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}
.tpl-pick-item:hover { background: var(--green-tint); border-color: var(--green-tint-border); }
.tpl-pick-item.is-current {
  background: var(--green-tint);
  border-color: var(--green-deep);
}
.tpl-pick-item-main {
  display: inline-flex; align-items: flex-start; gap: 0.45rem; min-width: 0;
}
.tpl-pick-check {
  flex-shrink: 0; width: 1rem; color: var(--green-deep); font-weight: 700; line-height: 1.35;
}
.tpl-pick-check--empty { visibility: hidden; }
.tpl-pick-item-title { font-weight: 600; color: var(--forest); line-height: 1.35; }
.tpl-pick-item-meta { color: var(--muted); font-size: 0.85rem; white-space: nowrap; flex-shrink: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.lh-workspace .document-sheet { margin: 0 auto; border: 1px solid var(--line); }
.lh-workspace {
  grid-template-columns: minmax(0, 1fr) minmax(17rem, 20rem);
}
.lh-settings {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.lh-settings > .field { margin: 0; }
.lh-settings select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.lh-reserve-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: var(--space-2);
}
.lh-reserve-row .field { margin: 0; }
.lh-settings .grid.grid-2 {
  gap: var(--space-2);
}
.lh-settings .grid.grid-2 .field { margin: 0; }
.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: var(--space-2); overflow: hidden;
}
.confirm-bar {
  flex-shrink: 0; display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-3); background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--space-2) var(--space-3);
}
.confirm-bar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.confirm-preview {
  flex: 1; min-height: 0; overflow: auto;
  background: var(--sea); border: 1px solid var(--line);
  border-radius: var(--radius); padding: var(--space-3);
}

.editor-area {
  width: 100%; min-height: 10rem; border: 1px solid var(--line);
  border-radius: 0.5rem; padding: var(--space-2); font-family: ui-monospace, monospace; font-size: 0.9rem;
  background: var(--cream);
}
.var-list { display: flex; flex-direction: column; gap: var(--space-2); }
.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: var(--space-3);
}
.tpl-workspace {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(17rem, 22rem);
  gap: var(--space-3);
  overflow: hidden;
}
.tpl-workspace .form-pane { min-width: 0; max-width: 100%; }
.form-pane .field > label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--forest);
  display: block;
  margin-bottom: var(--space-1);
}
.form-pane-body > .field + .field { margin-top: var(--space-3); }
/* 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: var(--space-3); flex-wrap: wrap;
  margin-bottom: var(--space-2); flex-shrink: 0;
}
.letter-canvas-wrap {
  flex: 1; min-height: 0; overflow: auto; max-width: none; width: 100%;
}
.document-sheet.letter-canvas-wrap.page-A4 { min-height: 297mm; }
.document-sheet.letter-canvas-wrap.page-B5 { min-height: 250mm; }
.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: var(--space-1);
  padding: var(--space-2); margin-bottom: var(--space-2); flex-shrink: 0;
  background: var(--white); border: 1px solid var(--line);
  border-radius: 0.65rem; box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 3;
}
.editor-toolbar .tb-sep {
  width: 1px; align-self: stretch; background: var(--line); margin: 0.15rem var(--space-1);
}
.editor-toolbar button {
  min-width: var(--control-h); height: var(--control-h); padding: 0 0.45rem;
  border: 1px solid transparent; border-radius: 0.45rem; 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: var(--control-h); border: 1px solid var(--line); border-radius: 0.45rem;
  background: var(--white); color: var(--ink); padding: 0 0.4rem; font-size: 0.85rem;
}
.tb-page-size {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-1) 0 var(--space-2);
  border-left: 1px solid var(--line);
  height: var(--control-h);
  flex-shrink: 0;
}
.tb-page-size label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.tb-page-size select { min-width: 4rem; font-weight: 700; }
.tb-page-size .page-size-sup {
  margin-left: 0.15em;
  align-self: flex-start;
  margin-top: 0.15rem;
}

/* 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); font-size: 0.92rem; }

/* 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: var(--space-3);
  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;
}

/* Invalid variable pasted/typed as {{bad name}} — flagged, click to fix. */
.tpl-var-error {
  background: #fdecea;
  color: #b3261e;
  text-decoration: underline wavy #d93025;
  text-underline-offset: 2px;
  border-radius: 3px;
  padding: 0 2px;
  cursor: pointer;
  font-weight: 600;
}
.tpl-var-error.flash {
  animation: tplErrFlash 0.42s ease-in-out 3;
}
@keyframes tplErrFlash {
  50% { background: #f6b8b2; box-shadow: 0 0 0 2px rgba(217, 48, 37, 0.45); }
}
.tpl-err-menu {
  position: absolute;
  z-index: 2000;
  background: #fff;
  border: 1px solid #d5d5d5;
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding: 4px;
  display: flex;
  flex-direction: column;
  min-width: 168px;
}
.tpl-err-menu button {
  text-align: left;
  border: 0;
  background: none;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #1a1a1a;
  white-space: nowrap;
}
.tpl-err-menu button:hover { background: #f0f0f0; }
.tpl-err-menu button[data-act="fix"] { color: var(--forest, #0b6b3a); font-weight: 700; }
.tpl-err-menu button[data-act="remove"] { color: #b3261e; }
.palette-title {
  margin: 16px 0 8px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--forest);
  letter-spacing: 0.02em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.var-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.var-palette .palette-chip {
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
  box-sizing: border-box;
}
.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-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
}
.palette-chip-label {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--forest);
}
.palette-chip small {
  color: var(--muted);
  font-size: 0.72rem;
}
/* Gear button — opens the per-variable settings popover (field type + remove). */
.palette-gear {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.palette-chip:hover .palette-gear { opacity: 1; }
.palette-gear:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.06);
  color: var(--forest);
}
/* Small at-a-glance type badge so people can identify the field type. */
.palette-type-pill {
  margin-top: 5px;
  align-self: flex-start;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--forest);
  background: #fff;
  border: 1px solid var(--green-tint-border);
  border-radius: 999px;
  padding: 1px 8px;
  letter-spacing: 0.01em;
}
.var-settings-menu {
  position: absolute;
  z-index: 2000;
  background: #fff;
  border: 1px solid #d5d5d5;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  padding: 6px;
}
.vsm-title {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 4px 8px 6px;
}
.vsm-types { display: flex; flex-direction: column; }
.vsm-type {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  border: 0;
  background: none;
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--ink);
}
.vsm-type:hover { background: var(--green-tint); }
.vsm-type .vsm-check { width: 14px; color: var(--forest); visibility: hidden; font-weight: 700; }
.vsm-type.is-active { color: var(--forest); font-weight: 700; }
.vsm-type.is-active .vsm-check { visibility: visible; }
.vsm-sep { height: 1px; background: #ececec; margin: 5px 4px; }
.vsm-remove {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #b3261e;
}
.vsm-remove:hover { background: #fdecea; }
.vsm-remove small { color: #c9756e; font-weight: 400; }

.letter-editor-pane { position: relative; }
.quick-var-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.quick-var-row input { flex: 1 1 100%; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.quick-var-row select,
.quick-var-row button { flex: 1 1 auto; min-width: 0; }
.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: var(--space-3);
  min-height: 18rem;
  display: flex;
  flex-direction: column;
}
.dashboard-card table { margin-top: var(--space-2); }
.easy-hero {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  margin-bottom: var(--space-3); padding: var(--space-4);
  background: linear-gradient(180deg, #f2f4f8 0%, #dfe5ef 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.easy-hero-title { margin: 0 0 var(--space-1); font-size: 1.4rem; color: var(--forest); }
.btn-lg { padding: 0.7rem 1.25rem; font-size: 1.05rem; min-height: 2.6rem; }
.easy-actions {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: var(--space-3);
}
.easy-card {
  display: flex; flex-direction: column; gap: var(--space-1); text-align: left;
  padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--white); cursor: pointer; color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.easy-card:hover { border-color: var(--saffron); box-shadow: var(--shadow); }
.easy-card strong { color: var(--forest); font-size: 1.05rem; }
.easy-card span { color: var(--muted); font-size: 0.92rem; }
.empty-cta { text-align: center; padding: 2.5rem 1.5rem; }
.empty-cta h2 { margin: 0 0 var(--space-2); }
.empty-cta-inline { padding: var(--space-3); }
.login-hint { margin: 0 0 var(--space-3); font-size: 0.9rem; line-height: 1.5; }
.login-hint code { font-size: 0.85rem; background: var(--sea); padding: 0.1rem 0.35rem; border-radius: 0.25rem; }
@media (max-width: 700px) {
  .easy-hero { flex-direction: column; align-items: stretch; }
}

#ui-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
}
.toast-stack {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  min-width: 15rem;
  max-width: 26rem;
  padding: var(--space-3);
  border-radius: var(--radius);
  box-shadow: 0 1rem 2.5rem 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;
  font-size: 0.95rem;
}
.toast.success {
  border-color: var(--green-tint-border);
  background: var(--green-tint);
  color: var(--green-deep);
}
.toast.error {
  border-color: #e3b7aa;
  background: #fdecea;
  color: #8a1f14;
}
.toast-pop { animation: toastPop 0.28s ease; }
@keyframes toastPop {
  0% { transform: scale(0.98); }
  40% { transform: scale(1.03); }
  100% { transform: scale(1); }
}
.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: var(--space-4);
}
.modal-card {
  width: min(32rem, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: 0 1.25rem 2.75rem rgba(17, 24, 39, 0.18);
  overflow: hidden;
}
.modal-head,
.modal-body,
.modal-actions { padding: var(--space-3) var(--space-4); }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.1rem; color: var(--forest); }
.modal-body { padding-bottom: var(--space-2); }
.modal-actions {
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}
.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: 0.65rem;
  padding: 0.6rem 0.75rem;
  min-height: var(--control-h);
  background: var(--white);
  color: var(--ink);
  box-sizing: border-box;
}
.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;
}
