/* Font for the portal (falls back to the system font when offline) */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');
/* ---------- Indian-language fonts (same as the PDF; each loads only when that script is on the page) ---------- */
@font-face { font-family: "Noto Sans Kannada"; src: url(/fonts/NotoSansKannada-Regular.ttf) format("truetype"); font-weight: 400; unicode-range: U+0C80-0CFF, U+200C-200D; font-display: swap; }
@font-face { font-family: "Noto Sans Kannada"; src: url(/fonts/NotoSansKannada-Bold.ttf) format("truetype"); font-weight: 700; unicode-range: U+0C80-0CFF, U+200C-200D; font-display: swap; }
@font-face { font-family: "Noto Sans Devanagari"; src: url(/fonts/NotoSansDevanagari-Regular.ttf) format("truetype"); font-weight: 400; unicode-range: U+0900-097F, U+A8E0-A8FF, U+1CD0-1CFF, U+200C-200D; font-display: swap; }
@font-face { font-family: "Noto Sans Devanagari"; src: url(/fonts/NotoSansDevanagari-Bold.ttf) format("truetype"); font-weight: 700; unicode-range: U+0900-097F, U+A8E0-A8FF, U+1CD0-1CFF, U+200C-200D; font-display: swap; }
@font-face { font-family: "Noto Sans Tamil"; src: url(/fonts/NotoSansTamil-Regular.ttf) format("truetype"); unicode-range: U+0B80-0BFF; font-display: swap; }
@font-face { font-family: "Noto Sans Telugu"; src: url(/fonts/NotoSansTelugu-Regular.ttf) format("truetype"); unicode-range: U+0C00-0C7F; font-display: swap; }
@font-face { font-family: "Noto Sans Malayalam"; src: url(/fonts/NotoSansMalayalam-Regular.ttf) format("truetype"); unicode-range: U+0D00-0D7F; font-display: swap; }

:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --ink: #14142b;
  --muted: #5f6585;
  --line: #e6e8f2;
  --accent: #5b4bf0;          /* indigo-violet */
  --accent-2: #8b3dff;
  --accent-ink: #ffffff;
  --accent-soft: #eeedff;
  --grad: linear-gradient(135deg, #5b4bf0 0%, #8b3dff 55%, #d946ef 100%);
  --grad-cool: linear-gradient(135deg, #0ea5e9, #6366f1);
  --cyan: #06b6d4; --cyan-soft: #e0f8fc;
  --pink: #db2777; --pink-soft: #fdeaf3;
  --danger: #e11d48;
  --danger-soft: #ffe8ee;
  --ok: #059669;
  --ok-soft: #e3f8ef;
  --warn: #b45309;
  --warn-soft: #fff4dc;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 43, .05), 0 2px 6px rgba(20, 20, 43, .04);
  --shadow: 0 1px 2px rgba(20, 20, 43, .04), 0 10px 30px -12px rgba(76, 60, 200, .18);
  --shadow-lg: 0 30px 60px -24px rgba(48, 32, 140, .35), 0 12px 24px -12px rgba(20, 20, 43, .12);
  --ring: 0 0 0 4px rgba(91, 75, 240, .16);
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Noto Sans Kannada", "Noto Sans Devanagari",
    "Noto Sans Tamil", "Noto Sans Telugu", "Noto Sans Malayalam", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.45; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 14px; margin: 8px 0 0; }

/* ---------- top bar & nav ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.next-pill {
  background: var(--accent-soft); color: var(--accent); padding: 6px 12px; border-radius: 999px;
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw;
}
.next-pill strong { font-variant-numeric: tabular-nums; margin-left: 4px; }

.mainnav {
  display: flex; gap: 2px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  overflow-x: auto; position: sticky; top: 0; z-index: 5;
}
.mainnav button {
  border: 0; background: none; padding: 12px 14px; font: inherit; font-weight: 550; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.mainnav button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.mainnav button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.page { max-width: 1400px; margin: 0 auto; padding: 20px; }
.view { display: flex; flex-direction: column; gap: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.card.narrow { max-width: 820px; width: 100%; margin: 0 auto; }
.split { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 20px; align-items: start; }
.layout-split { grid-template-columns: minmax(340px, 460px) 1fr; }

/* ---------- form elements ---------- */
.muted { color: var(--muted); }
.small { font-size: 12.5px; margin: 0; }
.opt { color: var(--muted); font-weight: 400; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field.inline input { width: 72px; }
input[type="text"], input[type="number"], input[type="date"], input[type="search"], input[type="password"], input[type="url"], input[type="email"], input[type="tel"], input:not([type]), select, textarea {
  font: inherit; font-family: inherit; font-weight: 400; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 60px; line-height: 1.45; }
input[type="color"] { width: 100%; height: 37px; border: 1px solid var(--line); border-radius: 7px; padding: 2px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.check.tight { align-self: end; padding-bottom: 9px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.grid-form { display: grid; grid-template-columns: 1.3fr 1fr 1fr 0.8fr auto; gap: 12px; align-items: end; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.row.nowrap { flex-wrap: nowrap; gap: 6px; }
.row input[type="search"] { min-width: 220px; width: auto; flex: 1; }
.row select { width: auto; }

fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 650; padding: 0 6px; }

.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #b8c3cf; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); }
.btn.big { padding: 12px 16px; font-size: 15px; width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; font-weight: 650; }

.msg { margin: 0; min-height: 1.2em; font-size: 13px; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--danger); }
.notice { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); border: 1px solid #f0dc9c; }
.issued {
  display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 8px;
  background: var(--ok-soft); border: 1px solid #b7e1c3;
}
.issued strong { font-size: 16px; color: var(--ok); }

.stack { display: flex; flex-direction: column; gap: 12px; }
.form-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.grid-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid-fields.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-fields .span-all { grid-column: 1 / -1; }

.notice.revise { background: var(--warn-soft); color: var(--ink); border-color: #f0dc9c; display: flex; flex-direction: column; gap: 10px; }
.badge.warn, .status.warn { background: var(--warn-soft); color: var(--warn); }
.badge + .badge { margin-left: 4px; }
.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.warn-text { color: var(--warn); font-weight: 600; }
.nav-badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; vertical-align: 1px;
}

/* ---------- typing language + formatting ---------- */
.typing-bar { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.typing-bar select { width: auto; min-width: 210px; }
.typing-bar .field.inline { font-weight: 600; }
.typing-help summary { font-size: 13px; }
.typing-help .examples { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0; }
.typing-help .ex code { font-size: 12.5px; }
.small-facts { font-size: 12.5px; grid-template-columns: 90px 1fr; }
.fmt-bar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-bottom: -6px; }
.fmt-btn { font: inherit; font-size: 13px; min-width: 34px; height: 32px; padding: 0 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); cursor: pointer; }
.fmt-btn:hover { border-color: var(--accent); color: var(--accent); }
.fmt-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.fmt-btn:disabled { opacity: .45; cursor: not-allowed; }
.fmt-btn mark { background: #ffe95a; padding: 0 2px; border-radius: 2px; }
.fmt-bar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.look { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.look h3 { margin: 0; font-size: 14px; }
.look-paper { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 18px 22px; box-shadow: 0 1px 3px rgba(16,24,40,.06); font-size: 14px; color: #1a1a1f; max-height: 520px; overflow: auto; }
.look-subject { font-weight: 700; margin: 0 0 1.45em; }
.look-images { margin: 10px 0; }
.rich-line { min-height: 1.45em; line-height: 1.45; }
.rich-li { padding-left: 1.7em; position: relative; }
.rich-label { position: absolute; left: 0; width: 1.4em; text-align: right; }
.rich-blank { height: 1.45em; }
.rich mark { background: #ffe95a; padding: 0 1px; }
.letter-text .rich { font-size: 13.5px; }

/* ---------- tables ---------- */
.rich-table { border-collapse: collapse; width: 100%; margin: 4px 0; font-size: 13px; }
.rich-table th, .rich-table td { border: 1px solid #a3abb8; padding: 4px 7px; vertical-align: middle; position: static; }
.rich-table th { background: #ebeff6; font-weight: 700; color: inherit; }
dialog.side.table-dlg { width: min(1100px, 96vw); } /* wide tables (7–10 columns) fit without scrolling */
.tb-controls { gap: 18px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.stepper output { min-width: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.tb-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 50vh; }
.tb-edit { border-collapse: collapse; width: 100%; }
.tb-edit th, .tb-edit td { border: 1px solid var(--line); padding: 0; position: static; background: none; }
.tb-edit td input { border: 0; border-radius: 0; padding: 8px; min-width: 110px; background: transparent; }
.tb-edit td textarea { border: 0; border-radius: 0; padding: 8px; min-width: 110px; width: 100%; height: 100%; min-height: 38px; background: transparent; resize: none; font: inherit; display: block; field-sizing: content; }
.tb-edit td input:focus, .tb-edit td textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: #fff; }
.tb-edit td.tb-merged { background: #f3f6fb; vertical-align: middle; }
.tb-edit .tb-head td textarea { font-weight: 700; }
.tb-edit td.tb-focus { box-shadow: inset 0 0 0 2px var(--accent); }
.tb-tools { gap: 6px; margin: 2px 0 8px; align-items: center; }
.tb-tools .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.tb-head-rows { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; }
.tb-head-rows select { width: auto; padding: 4px 8px; }
.tb-edit .tb-head td { background: #ebeff6; }
.tb-edit .tb-head td input { font-weight: 700; }
.tb-edit .tb-align th { background: var(--surface-2); padding: 4px; }
.tb-edit .tb-align select { width: 100%; padding: 4px 6px; font-size: 12.5px; }
.tb-edit .tb-rownum, .tb-edit .tb-corner { width: 1%; white-space: nowrap; font-size: 11.5px; color: var(--muted); padding: 0 8px; background: var(--surface-2); font-weight: 600; }

/* ---------- AI writing assistant ---------- */
.write-split { display: grid; grid-template-columns: minmax(0, 820px) minmax(300px, 380px); gap: 20px; justify-content: center; align-items: start; }
.write-split .card.narrow { margin: 0; }
.ai-panel { position: sticky; top: 64px; border-color: #d9cdf5; background: linear-gradient(180deg, #f6f2ff, #fff 220px); }
.ai-head { display: flex; gap: 12px; align-items: flex-start; }
.ai-head h2 { font-size: 16px; }
.ai-head p { margin: 2px 0 0; }
.ai-mark { flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: 17px;
  background: linear-gradient(135deg, #6d4bd8, #1d4e89); }
.ai-body { display: flex; flex-direction: column; gap: 12px; }
.ai-body.disabled { opacity: .55; pointer-events: none; }
.ai-examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ai-chip { font-family: inherit; font-size: 12px; line-height: 1.35; text-align: left; background: #fff; color: var(--text, #3d4b5f); border-color: var(--line); border-radius: 8px; }
.ai-chip:hover { border-color: #6d4bd8; color: #4b2fb0; }
.ai-panel #aiWrite { background: linear-gradient(135deg, #6d4bd8, #1d4e89); border-color: #5b3fc4; }
.ai-panel.working .ai-mark { animation: aipulse 1.2s ease-in-out infinite; }
@keyframes aipulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.ai-note { margin: 0; }
@media (max-width: 1180px) {
  .write-split { grid-template-columns: minmax(0, 820px); }
  .ai-panel { position: static; order: -1; }
}
@media (prefers-reduced-motion: reduce) { .ai-panel.working .ai-mark { animation: none; } }

/* ---------- colours ---------- */
.fmt-color, .fmt-bg { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; font-weight: 700; }
.fmt-color i, .fmt-bg i { display: block; width: 16px; height: 4px; border-radius: 2px; margin-top: 2px; }
.fmt-color i { background: linear-gradient(90deg, #c62828, #1565c0, #2e7d32); }
.fmt-bg i { background: linear-gradient(90deg, #ffe95a, #c8efc3, #ffd3e2); }
.palette { position: absolute; z-index: 60; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; width: 220px;
  box-shadow: 0 10px 30px rgba(16,24,40,.18); display: flex; flex-direction: column; gap: 8px; }
.palette-title { font-size: 12px; font-weight: 700; color: var(--muted); }
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.swatch { width: 100%; aspect-ratio: 1; border-radius: 6px; border: 1px solid rgba(0,0,0,.15); cursor: pointer; }
.swatch:hover, .swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rich-bg { padding: 0 1px; border-radius: 2px; }
.ok-text { color: var(--ok); font-weight: 600; }
.err-text { color: var(--danger); font-weight: 600; }

.brand-logo { width: 30px; height: 30px; }
.org-chip { margin-left: 8px; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 650;
  max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-foot { text-align: center; font-size: 12.5px; color: var(--muted); margin: 0; }
.auth-foot a { color: var(--muted); }
.auth-org { text-align: center; font-weight: 650; color: var(--ink); margin: -8px 0 0; font-size: 15px; }

/* ---------- smart templates ---------- */
.field-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.field-rows:empty { display: none; }
.field-row { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.field-main { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field-main input[type=text] { flex: 1 1 200px; width: auto; }
.field-main select { width: auto; }
.field-sub { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field-sub .opts { flex: 1 1 220px; width: auto; font-size: 13px; padding: 6px 9px; }
.check.tight-inline { font-size: 13px; gap: 6px; }
code.key { background: var(--accent-soft); color: var(--accent); }
.chips-box { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px dashed #c9d4e2; border-radius: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 4px 9px; border-radius: 999px; border: 1px solid #cfdcee; background: var(--accent-soft); color: var(--accent); cursor: pointer; }
.chip.builtin { background: #eef1f5; color: var(--muted); border-color: var(--line); }
.chip:hover { border-color: var(--accent); }
.list-btn .list-meta { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; }
.tpl-details { border: 1px solid #cfdcee; background: linear-gradient(180deg, var(--accent-soft), #fff 80%); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.tpl-details .form-sub { margin: 0; text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 14px; }
.req { color: var(--danger); font-weight: 700; }
.hint-line { font-weight: 400; }
[aria-invalid="true"] { border-color: var(--danger) !important; outline: 2px solid rgba(180, 35, 24, .2); }
textarea.locked-text, input.locked-text { background: #f6f7f9; cursor: not-allowed; }

/* ---------- letter images ---------- */
.img-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.img-list:empty { display: none; }
.img-item { display: flex; gap: 12px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-weight: 400; }
.img-item img { width: 84px; height: 64px; object-fit: contain; border-radius: 5px; background: #fff; border: 1px solid var(--line); flex: none; }
.img-fields { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.img-fields select { width: auto; padding: 5px 8px; font-size: 13px; }
.layout-pick { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.layout-opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px 8px; border: 1.5px solid var(--line);
  border-radius: 9px; background: var(--surface); cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); text-align: center;
}
.layout-opt svg { width: 52px; height: 39px; background: #f4f6f9; border-radius: 4px; }
.layout-opt svg rect { fill: #c3cfdf; }
.layout-opt:hover { border-color: #b8c3cf; }
.layout-opt[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.layout-opt[aria-checked="true"] svg rect { fill: var(--accent); }
.layout-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.img-thumb { position: relative; flex: none; }
.img-badge { position: absolute; left: 4px; top: 4px; font-size: 10px; padding: 0 6px; }
.sig-thumb { height: 48px; max-width: 160px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 5px; padding: 3px; }
/* signatories */
.sig-list { list-style: none; margin: 4px 0 8px; padding: 0; display: flex; flex-direction: column; gap: 8px; font-weight: 400; }
.sig-item { display: flex; gap: 12px; align-items: flex-start; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.sig-image { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; flex: none; width: 168px; }
.sig-image .sig-thumb, .sig-empty { width: 160px; height: 52px; }
.sig-empty { display: flex; align-items: center; justify-content: center; border: 1px dashed var(--line); border-radius: 5px; background: #fff; }
.sig-view { list-style: none; padding: 0; margin: 6px 0 10px; display: flex; flex-wrap: wrap; gap: 10px; }
.sig-view li { display: flex; flex-direction: column; gap: 3px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; min-width: 150px; }
.look-sigs { display: grid; gap: 4px 18px; margin-top: 14px; }
.look-sigs.n1 { grid-template-columns: 1fr; }
.look-sigs.n2 { grid-template-columns: repeat(2, 1fr); }
.look-sigs.n3 { grid-template-columns: repeat(3, 1fr); }
.look-sigs.n4 { grid-template-columns: repeat(4, 1fr); }
/* Each block is as wide as its text: first on the left margin, last on the right margin, the rest centred. */
.look-sig { display: flex; flex-direction: column; text-align: center; font-size: 13px; padding-bottom: 8px; justify-self: center; max-width: 100%; }
.look-sigs.n1 .look-sig, .look-sigs.n2 .look-sig:nth-child(odd), .look-sigs.n3 .look-sig:nth-child(3n+1), .look-sigs.n4 .look-sig:nth-child(4n+1) { justify-self: start; }
.look-sigs.n2 .look-sig:nth-child(even), .look-sigs.n3 .look-sig:nth-child(3n), .look-sigs.n4 .look-sig:nth-child(4n) { justify-self: end; }
.look-sig-img { height: 56px; min-width: 150px; border-bottom: 1px solid #8a8f98; margin-bottom: 4px; display: flex; align-items: flex-end; justify-content: center; }
.look-sigs.no-line .look-sig-img { min-width: 0; }
.look-sig-img img { max-height: 50px; max-width: 100%; object-fit: contain; }
.look-sigs.sign-below .look-sig-img { order: 3; margin: 6px 0 0; }
.look-sigs.no-line .look-sig-img { border-bottom-color: transparent; }
.sig-style { gap: 18px; margin: 0 0 8px; font-weight: 400; }
.sig-style label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.sig-style select { width: auto; padding: 5px 8px; }
@media (max-width: 560px) {
  .sig-item { flex-direction: column; }
  .look-sigs.n3, .look-sigs.n4 { grid-template-columns: repeat(2, 1fr); }
}
.verify-body .sig-list { flex-direction: row; flex-wrap: wrap; }
.verify-body .sig-list li { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; min-width: 150px; }
.verify-body .sig-list img { max-height: 48px; max-width: 160px; margin-top: 4px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 8px; }
.thumb { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.thumb img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.thumb figcaption { font-size: 12px; color: var(--muted); }

/* ---------- tables & lists ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: 70vh; }
.table-wrap.tall { max-height: 75vh; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); position: sticky; top: 0; font-weight: 600; color: var(--muted); z-index: 1; }
td.serial { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
td:last-child { width: 1%; }
.when { font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: #eef1f5; color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; }
tr.inactive td { opacity: .65; }
tr.warn-row td { background: #fffaf0; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.list-btn {
  width: 100%; text-align: left; border: 1px solid transparent; background: none; padding: 9px 10px; border-radius: 7px;
  font: inherit; cursor: pointer; color: var(--ink);
}
.list-btn:hover { background: var(--surface-2); border-color: var(--line); }
.list-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- layout editor ---------- */
.settings { gap: 14px; }
.savebar {
  position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  background: var(--surface); padding: 12px 0 2px; border-top: 1px solid var(--line); margin-top: -2px;
}
.savebar .muted { margin-right: auto; color: var(--warn); font-weight: 600; }
.preview { position: sticky; top: 64px; }
.stage {
  position: relative; width: 100%; max-width: 640px; margin: 0 auto; aspect-ratio: 595 / 842;
  background: #fff; box-shadow: 0 1px 3px rgba(16,24,40,.08), 0 8px 24px rgba(16,24,40,.10); border-radius: 2px;
  overflow: hidden; user-select: none;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.content-box { position: absolute; border: 1.5px dashed rgba(29,78,137,.45); pointer-events: none; }
.marker {
  position: absolute; white-space: nowrap; line-height: 1; cursor: grab; touch-action: none;
  outline: 1.5px dashed rgba(29,78,137,.75); outline-offset: 3px; border-radius: 1px;
}
.marker:hover, .marker:focus-visible { outline: 2px solid var(--accent); background: rgba(29,78,137,.07); }
.marker.dragging { cursor: grabbing; background: rgba(29,78,137,.12); }
.qr-marker {
  display: grid; place-items: center; outline-offset: 0; color: #fff; font-weight: 700;
  background: repeating-conic-gradient(#1f2d3d 0 25%, #52606f 0 50%) 0 0 / 25% 25%;
}
.qr-marker span { background: var(--accent); padding: 1px 3px; border-radius: 2px; line-height: 1; }
.stage.empty .marker, .stage.empty .content-box { display: none; }
.drop {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed #b8c3cf; margin: 16px; border-radius: 10px; text-align: center; padding: 16px;
}
.stage.empty .drop { display: flex; }
.drop-title { font-weight: 650; font-size: 16px; }
.hint { text-align: center; color: var(--muted); font-size: 12.5px; max-width: 640px; margin: 12px auto 0; }

/* ---------- QR scanner ---------- */
.scan-split { grid-template-columns: minmax(300px, 460px) 1fr; }
.scanner {
  position: relative; aspect-ratio: 4 / 3; background: #0f172a; border-radius: 10px; overflow: hidden;
  display: grid; place-items: center;
}
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.scanner.live video { display: block; }
.scan-frame {
  position: absolute; width: 58%; aspect-ratio: 1; border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, .45); border: 3px solid rgba(255,255,255,.9); display: none;
}
.scanner.live .scan-frame { display: block; }
.scan-idle { position: relative; color: #cbd5e1; margin: 0; font-weight: 600; z-index: 1; }
.scanner.live .scan-idle { position: absolute; bottom: 10px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.serial-title { font-size: 22px; word-break: break-all; }
.notice.info { background: var(--accent-soft); color: var(--accent); border-color: #cfdcee; }
#scResult h3, #dtBody h3 { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--line); }
.verify h2 { margin-top: 6px; }

.copy-frame iframe { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 8px; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; overflow: hidden; color: var(--ink); }
dialog::backdrop { background: rgba(15,23,42,.5); }
#previewDlg { width: min(900px, 94vw); height: 92vh; }
#previewDlg[open] { display: flex; flex-direction: column; }
.preview-pages { flex: 1; overflow: auto; background: #525a66; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 16px; user-select: none; -webkit-user-select: none; }
.preview-pages canvas { width: 100%; max-width: 760px; height: auto; background: #fff; box-shadow: 0 4px 16px rgba(0,0,0,.35); -webkit-touch-callout: none; }
.issued-note { background: var(--surface); border-radius: 10px; padding: 28px; text-align: center; max-width: 480px; margin: auto; }
.issued-note strong { font-size: 22px; color: var(--ok); }
.dlg-foot { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.dlg-foot .muted.small { margin: 0; }
.row.end { justify-content: flex-end; }
dialog.side { width: min(560px, 96vw); max-height: 92vh; }
dialog.side[open] { display: flex; flex-direction: column; }
dialog.small-dlg { width: min(420px, 94vw); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.dlg-body { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; }
.pre { white-space: pre-line; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.timeline li { position: relative; }
.timeline li::before {
  content: ""; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
}
.tl-type { font-weight: 600; }
.tl-meta { color: var(--muted); font-size: 12.5px; }
.letter-text { white-space: pre-wrap; font-family: inherit; background: var(--surface-2); padding: 12px; border-radius: 8px; border: 1px solid var(--line); margin: 8px 0 0; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: #17212e; color: #fff; padding: 10px 16px; border-radius: 8px; max-width: min(560px, 92vw); font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.err { background: var(--danger); }

/* ---------- login ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth { width: min(400px, 100%); display: flex; flex-direction: column; gap: 18px; }
.auth-brand { justify-content: center; font-size: 18px; }
/* organisation sign-up */
.auth.wide { width: min(640px, 100%); }
.signup-steps { display: flex; gap: 8px; list-style: none; margin: 0; padding: 0; font-size: 12.5px; color: var(--muted); }
.signup-steps li { flex: 1; padding: 6px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); text-align: center; }
.signup-steps li[aria-current="step"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 650; }
.signup-steps li.done { color: var(--ok); }
.field-err { color: var(--danger); font-size: 12.5px; font-weight: 500; }
.field-err:empty { display: none; }
.form-section { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 4px 0 -6px; }
.otp-input { font-size: 26px !important; letter-spacing: 12px; text-align: center; font-variant-numeric: tabular-nums; padding: 10px !important; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; margin: 0; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.auth-alt { text-align: center; margin: 0; font-size: 14px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- QR verification page ---------- */
.verify-body { padding: 16px; }
.verify { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.verify h1 { word-break: break-all; }
.status { align-self: flex-start; font-weight: 700; padding: 6px 12px; border-radius: 999px; font-size: 13px; }
.status.ok { background: var(--ok-soft); color: var(--ok); }
.status.bad { background: var(--danger-soft); color: var(--danger); }
.status.warn { background: var(--warn-soft); color: var(--warn); }

/* Printing the page while a preview is open gives a blank notice, never the letter. */
@media print {
  body.previewing > * { display: none !important; }
  body.previewing::before {
    content: "Preview only — this letter has not been issued. Issue it in the portal to print it.";
    display: block; padding: 40px; font: 16px system-ui, sans-serif;
  }
}

@media (max-width: 1000px) {
  .split, .layout-split, .scan-split { grid-template-columns: 1fr; }
  .preview { position: static; }
  .grid-form, .grid-fields { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .page { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .grid3, .grid4 { grid-template-columns: 1fr 1fr; }
  .grid2, .grid-fields, .grid-fields.two { grid-template-columns: 1fr; }
  .layout-pick { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
  .row input[type="search"] { min-width: 0; width: 100%; }
}

.ref-preview { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-size: 14px; }
.ref-preview strong { font-size: 16px; letter-spacing: .02em; }

.plan-banner { padding: 9px 20px; background: var(--accent-soft); color: var(--accent); font-size: 13.5px; font-weight: 550; border-bottom: 1px solid var(--line); }
.plan-banner.warn { background: var(--warn-soft); color: var(--warn); }
.plan-banner.bad { background: var(--danger-soft); color: var(--danger); }


/* =====================================================================
   Premium theme (v3) — colourful, soft and easy to read.
   Overrides the base rules above; class names are unchanged.
   ===================================================================== */
body {
  background:
    radial-gradient(900px 500px at 100% -10%, rgba(139, 61, 255, .10), transparent 60%),
    radial-gradient(800px 500px at -10% 10%, rgba(6, 182, 212, .08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  font-size: 14.5px; line-height: 1.5;
}
h1 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 18px; font-weight: 750; letter-spacing: -.01em; }
h3 { font-weight: 700; }
::selection { background: rgba(91, 75, 240, .2); }

/* ---------- top bar ---------- */
.topbar {
  background: linear-gradient(110deg, #14123a 0%, #2c1f7a 45%, #5b2bd6 80%, #8b3dff 100%);
  border-bottom: 0; color: #fff; padding: 12px 24px;
  box-shadow: 0 10px 30px -18px rgba(44, 31, 122, .8);
}
.topbar .brand { color: #fff; font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.topbar .brand-logo { filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .3)); border-radius: 9px; }
.topbar .org-chip { background: rgba(255, 255, 255, .14); color: #fff; border: 1px solid rgba(255, 255, 255, .22); backdrop-filter: blur(6px); }
.topbar .next-pill { background: rgba(255, 255, 255, .12); color: #e9e5ff; border: 1px solid rgba(255, 255, 255, .2); }
.topbar .next-pill strong { color: #fff; }
.topbar .btn { background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .25); }
.topbar .btn:hover { background: rgba(255, 255, 255, .22); border-color: rgba(255, 255, 255, .4); }
.topbar .btn.ghost { background: transparent; border-color: transparent; color: #e9e5ff; }
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, .12); }
.super-chip { background: linear-gradient(135deg, #f59e0b, #ef4444) !important; border: 0 !important; color: #fff !important; }

/* ---------- navigation: pill tabs with icons ---------- */
.mainnav {
  gap: 4px; padding: 10px 20px; background: rgba(255, 255, 255, .82); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line); box-shadow: 0 6px 18px -14px rgba(20, 20, 43, .25);
}
.mainnav button {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 11px; border-bottom: 0;
  color: var(--muted); font-weight: 650; transition: background .15s, color .15s, box-shadow .15s;
}
.mainnav button:hover { background: var(--accent-soft); color: var(--accent); }
.mainnav button[aria-selected="true"] { background: var(--grad); color: #fff; box-shadow: 0 8px 18px -8px rgba(91, 75, 240, .7); }
.mainnav button[aria-selected="true"] .nav-badge { background: #fff; color: var(--danger); }
.nav-ico { width: 18px; height: 18px; flex: none; }
.nav-ico svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- page & cards ---------- */
.page { padding: 26px 24px 40px; }
.view { gap: 22px; animation: viewIn .25s ease both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card { border: 1px solid rgba(230, 232, 242, .9); border-radius: 18px; padding: 22px; box-shadow: var(--shadow); gap: 16px; }
.card > h2:first-child, .card > .row:first-child h2 {
  display: flex; align-items: center; gap: 10px;
}
.card > h2:first-child::before, .card > .row:first-child > h2::before {
  content: ""; width: 6px; height: 20px; border-radius: 4px; background: var(--grad); flex: none;
}
fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 16px 16px 18px; background: linear-gradient(180deg, #fff, var(--surface-2)); }
legend { font-weight: 750; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; }

/* ---------- form elements ---------- */
.field { font-weight: 650; color: #2a2c4a; }
input[type="text"], input[type="number"], input[type="date"], input[type="search"], input[type="password"], input[type="url"], input[type="email"], input[type="tel"], input:not([type]), select, textarea {
  border: 1.5px solid var(--line); border-radius: 11px; padding: 10px 12px; background: #fff;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:hover, select:hover, textarea:hover { border-color: #d3d6ea; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
select { appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%235f6585' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 17px; height: 17px; }
input[type="color"] { border-radius: 11px; border-width: 1.5px; }
code { background: var(--accent-soft); color: #3f31c8; border-radius: 6px; }

/* ---------- buttons ---------- */
.btn {
  border: 1.5px solid var(--line); border-radius: 11px; padding: 9px 16px; font-weight: 700;
  transition: transform .15s ease, box-shadow .15s ease, background .15s, border-color .15s, color .15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: #c9c6ff; color: var(--accent); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 10px 22px -10px rgba(91, 75, 240, .75); }
.btn.primary:hover { filter: saturate(1.1) brightness(1.05); color: #fff; box-shadow: 0 14px 28px -12px rgba(91, 75, 240, .85); }
.btn.ghost { box-shadow: none; }
.btn.ghost:hover { background: var(--accent-soft); color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: #fecdd3; background: var(--danger-soft); color: var(--danger); }
.btn.big { padding: 13px 18px; font-size: 15.5px; border-radius: 13px; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 9px; }
.btn:disabled { transform: none; box-shadow: none; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---------- messages, notices, badges ---------- */
.notice { border-radius: 12px; border: 1px solid #fde7b0; padding: 12px 14px; }
.notice.info { background: linear-gradient(135deg, #eef2ff, #f5f0ff); color: #3f31c8; border-color: #dcd7ff; }
.notice.ok { border-color: #bdeed8; }
.issued { border-radius: 14px; background: linear-gradient(135deg, #e3f8ef, #f0fdf8); border-color: #b5ead2; }
.badge { padding: 3px 10px; font-weight: 700; font-size: 11.5px; background: #eef0f7; color: #4b5073; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.nav-badge { background: linear-gradient(135deg, #f43f5e, #e11d48); box-shadow: 0 4px 10px -4px rgba(225, 29, 72, .7); }
.toast { background: #1b1640; border-radius: 12px; padding: 12px 18px; box-shadow: var(--shadow-lg); animation: toastIn .2s ease both; }
.toast.err { background: linear-gradient(135deg, #e11d48, #be123c); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.plan-banner { padding: 11px 24px; background: linear-gradient(90deg, #eeedff, #f5edff); color: #3f31c8; font-weight: 650; border-bottom: 1px solid #dcd7ff; }
.plan-banner.warn { background: linear-gradient(90deg, #fff4dc, #fff9ec); color: var(--warn); border-color: #fde7b0; }
.plan-banner.bad { background: linear-gradient(90deg, #ffe8ee, #fff3f6); color: var(--danger); border-color: #fecdd3; }
.ref-preview { border-radius: 12px; background: var(--grad); color: #fff; box-shadow: 0 10px 22px -12px rgba(91, 75, 240, .7); }
.ref-preview strong { color: #fff; }

/* ---------- tables & lists ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: 14px; background: #fff; }
th { background: #f6f6fd; color: #5b5f86; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 750; padding: 11px 14px; }
td { padding: 12px 14px; border-bottom-color: #eff0f7; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: #faf9ff; }
td.serial { color: #3f31c8; }
.list-btn { border-radius: 11px; padding: 10px 12px; }
.list-btn:hover { background: var(--surface-2); }
.list-btn.active { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 8px 18px -10px rgba(91, 75, 240, .7); }
.list-btn.active .list-meta { color: rgba(255, 255, 255, .8); }
.chip { border-radius: 999px; }
.timeline { border-left-color: #e3e1fb; }
.timeline li::before { background: var(--grad); box-shadow: 0 0 0 3px #eeedff; border: 0; }
details summary { color: var(--accent); }

/* ---------- writing tools ---------- */
.typing-bar { border-radius: 14px; background: linear-gradient(135deg, #f8f7ff, #f2fbfd); border-color: #e3e1fb; }
.fmt-btn { border-radius: 9px; border-width: 1.5px; transition: all .12s; }
.fmt-btn:hover { background: var(--accent-soft); }
.look { border-radius: 14px; background: linear-gradient(180deg, #fbfbff, #fff); }
.look-paper { border-radius: 10px; box-shadow: 0 2px 6px rgba(20, 20, 43, .06), 0 16px 32px -20px rgba(20, 20, 43, .25); }
.ai-panel { border: 0; background: linear-gradient(170deg, #f3efff 0%, #eef6ff 40%, #fff 75%); box-shadow: 0 0 0 1.5px #ddd5ff inset, var(--shadow); }
.ai-mark { background: var(--grad); border-radius: 12px; width: 40px; height: 40px; box-shadow: 0 10px 20px -8px rgba(139, 61, 255, .7); }
.ai-panel #aiWrite { background: var(--grad); border: 0; }
.ai-chip { border-radius: 10px; }
.ai-chip:hover { background: #fff; border-color: #a78bfa; color: #5b21b6; }
.layout-opt { border-radius: 12px; }
.layout-opt[aria-checked="true"] { background: linear-gradient(180deg, #f2f0ff, #fff); }
.img-item, .sig-item, .field-row { border-radius: 12px; background: #fff; box-shadow: var(--shadow-sm); }
.tpl-details { border-radius: 14px; border-color: #ddd8ff; background: linear-gradient(180deg, #f3f1ff, #fff 80%); }
.chips-box { border-radius: 12px; border-color: #d9d4ff; background: #fcfbff; }

/* ---------- dialogs ---------- */
dialog { border-radius: 20px; box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(20, 16, 60, .45); backdrop-filter: blur(4px); }
.dlg-head { padding: 14px 20px; background: linear-gradient(90deg, #faf9ff, #fff); }
.dlg-head strong { font-size: 16px; font-weight: 800; }
.dlg-body { padding: 20px; }
.preview-pages { background: linear-gradient(160deg, #2a2560, #3b2f88); }

/* ---------- layout editor & scanner ---------- */
.stage { border-radius: 6px; box-shadow: 0 2px 6px rgba(20, 20, 43, .08), 0 30px 60px -30px rgba(48, 32, 140, .45); }
.marker { outline-color: rgba(91, 75, 240, .8); }
.marker:hover, .marker:focus-visible { outline-color: var(--accent); background: rgba(91, 75, 240, .08); }
.content-box { border-color: rgba(139, 61, 255, .5); }
.qr-marker span { background: var(--accent); }
.savebar { background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px); border-radius: 0 0 18px 18px; }
.scanner { border-radius: 16px; background: radial-gradient(400px 300px at 50% 0%, #3b2f88, #14123a); }

/* ---------- sign-in / sign-up: split screen ---------- */
.auth-body { padding: 0; place-items: stretch; background: var(--bg); }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.05fr); }
.auth-side {
  position: relative; overflow: hidden; color: #e9e5ff; padding: 48px 56px; display: flex; flex-direction: column; gap: 28px;
  background:
    radial-gradient(520px 380px at 110% 0%, rgba(217, 70, 239, .55), transparent 60%),
    radial-gradient(520px 420px at -10% 100%, rgba(6, 182, 212, .45), transparent 60%),
    linear-gradient(150deg, #14123a 0%, #2c1f7a 55%, #5b2bd6 100%);
}
.auth-side::after { content: ""; position: absolute; inset: 0; background-image: radial-gradient(rgba(255, 255, 255, .09) 1px, transparent 1px); background-size: 22px 22px; pointer-events: none; }
.auth-side > * { position: relative; z-index: 1; }
.auth-side .brand { color: #fff; font-size: 19px; font-weight: 800; text-decoration: none; }
.auth-side h2 { color: #fff; font-size: clamp(26px, 3vw, 36px); line-height: 1.15; letter-spacing: -.02em; font-weight: 800; }
.auth-side h2 span { background: linear-gradient(90deg, #67e8f9, #f0abfc); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-side p { color: #cfc9f5; font-size: 15.5px; margin: 0; max-width: 30em; }
.auth-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.auth-points li { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; color: #e9e5ff; }
.auth-points .pt { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 16px;
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .2); }
.auth-points strong { color: #fff; display: block; }
.auth-card-demo { margin-top: auto; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .2); border-radius: 16px; padding: 16px 18px;
  backdrop-filter: blur(8px); display: flex; gap: 14px; align-items: center; max-width: 420px; }
.auth-card-demo .qr { width: 46px; height: 46px; border-radius: 8px; background: repeating-conic-gradient(#fff 0 25%, #d9d4ff 0 50%) 0 0 / 33% 33%; flex: none; }
.auth-card-demo strong { color: #fff; }
.auth-card-demo .ok-pill { display: inline-block; margin-top: 4px; font-size: 11.5px; font-weight: 750; padding: 2px 10px; border-radius: 999px; background: #34d399; color: #053b2a; }
.auth-main { display: grid; place-items: center; padding: 40px 24px; }
.auth { width: min(420px, 100%); gap: 20px; }
.auth.wide { width: min(640px, 100%); }
.auth .card { padding: 28px; border-radius: 22px; box-shadow: var(--shadow-lg); border: 1px solid #ecebfb; }
.auth h1 { font-size: 26px; }
.auth-alt a, .auth-foot a { color: var(--accent); }
.auth-alt a { font-weight: 750; }
.signup-steps li { border-radius: 12px; padding: 8px 10px; font-weight: 650; background: #fff; box-shadow: var(--shadow-sm); }
.signup-steps li[aria-current="step"] { background: var(--grad); color: #fff; }
.signup-steps li.done { background: var(--ok-soft); color: var(--ok); border-color: #bdeed8; }
.form-section { color: var(--accent); }
.otp-input { border-radius: 14px !important; background: linear-gradient(180deg, #fff, #f8f7ff) !important; }
.auth-brand.mobile-only { display: none; }
@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .auth-brand.mobile-only { display: flex; }
}

/* ---------- QR verification page ---------- */
.verify-body { background: linear-gradient(160deg, #f3f0ff, #eef8ff); min-height: 100vh; }
.verify .card { border-radius: 20px; }
.status { padding: 7px 14px; font-weight: 800; }
.status.ok { background: linear-gradient(135deg, #d1fae5, #a7f3d0); color: #065f46; }
.status.bad { background: linear-gradient(135deg, #ffe4e6, #fecdd3); color: #9f1239; }

@media (max-width: 560px) {
  .topbar { padding: 10px 14px; }
  .mainnav { padding: 8px 10px; }
  .card { padding: 16px; border-radius: 16px; }
  .page { padding: 18px 14px 32px; }
}
@media (prefers-reduced-motion: reduce) {
  .view, .toast { animation: none; }
  .btn, .mainnav button { transition: none; }
}

.auth-body > .auth { place-self: center; padding: 40px 16px; }

.chip.ai-chip { font: 12.5px/1.4 inherit; font-family: inherit; font-weight: 550; }

/* ---------- table editor & letter tables: even columns ---------- */
/* (the "last column = narrow" rule above is for action columns in lists, not for letter tables) */
.tb-edit { table-layout: fixed; }
.tb-edit td:last-child, .tb-edit th:last-child, .rich-table td:last-child, .rich-table th:last-child { width: auto; }
.tb-edit .tb-corner, .tb-edit .tb-rownum { width: 64px; text-align: center; }
.tb-edit td input, .tb-edit td textarea { min-width: 0; width: 100%; }
.tb-edit .tb-align th { padding: 6px; }
.tb-edit .tb-align select { padding: 6px 28px 6px 10px; background-position: right 8px center; font-weight: 600; }
.tb-head-rows select { padding: 6px 30px 6px 10px; background-position: right 8px center; min-width: 84px; }
.tb-wrap { border-radius: 12px; background: #fff; }
.tb-edit td { background: #fff; }
.tb-edit .tb-head td { background: #f1efff; }
.tb-edit td.tb-merged { background: #f7f5ff; }
.tb-edit .tb-rownum, .tb-edit td { vertical-align: middle; }
