/* DocForge — Option C: Modern SaaS
   Plus Jakarta Sans · Clean, card-based, indigo-purple brand
   v9.0 */

/* Google Fonts loaded via <link> in HTML with display=swap for FOIT prevention */

:root {
  /* ── Brand ── */
  --brand:        #5B4FE9;
  --brand-d:      #4840C7;
  --brand-l:      #EEEDFE;
  --brand-b:      #AFA9EC;

  /* ── Palette ── */
  --bg:           #F5F5F7;
  --bg2:          #EFEFEF;
  --surface:      #FFFFFF;
  --border:       rgba(0,0,0,.08);
  --border2:      rgba(0,0,0,.14);

  --ink:          #111118;
  --ink2:         #2C2C35;
  --ink3:         #5A5A6E;
  --ink4:         #8E8EA8;

  --green:        #3B6D11;
  --green-l:      #EAF3DE;
  --green-b:      #C0DD97;
  --amber:        #854F0B;
  --amber-l:      #FAEEDA;
  --amber-b:      #FAC775;
  --red:          #A32D2D;
  --red-l:        #FCEBEB;
  --red-b:        #F7C1C1;
  --purple:       #534AB7;
  --purple-l:     #EEEDFE;
  --teal:         #0F6E56;
  --teal-l:       #E1F5EE;

  /* ── Sidebar ── */
  --sidebar-w:    228px;

  /* ── Shape ── */
  --r:    4px;
  --r2:   6px;
  --r3:   8px;
  --r4:   12px;

  /* ── Fonts ── */
  --sans:  'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --serif: 'Merriweather', Georgia, serif;
  --mono:  'JetBrains Mono', 'Fira Code', monospace;

  --topbar-h: 52px;
  --ribbon-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-size: 14px; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }
a { color: inherit; text-decoration: none; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ═══════════════════════════════════════════════
   LOGIN — Simple classic internal tool style
═══════════════════════════════════════════════ */
#login {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}

.login-simple-wrap {
  width: 100%; max-width: 360px;
  padding: 0 20px;
}

.login-simple-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 32px;
}

.login-brand-logo {
  width: 280px;
  max-width: 100%;
  height: auto;
  display: block;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: block;
  flex: 0 0 auto;
}

.brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  line-height: 1;
}

.brand-name {
  font-size: 19px;
  font-weight: 750;
  letter-spacing: 0;
  line-height: 1.05;
}

.brand-subtitle {
  margin-top: 4px;
  font-size: 8px;
  font-weight: 500;
  letter-spacing: .15px;
  line-height: 1.1;
  white-space: nowrap;
}

.brand-lockup-dark .brand-name { color: #ffffff; }
.brand-lockup-dark .brand-subtitle { color: #cfe1f3; }
.brand-lockup-light .brand-name { color: #10213a; }
.brand-lockup-light .brand-subtitle { color: #53667d; font-size: 12px; }
.brand-lockup-light .brand-mark { width: 50px; height: 50px; }
.brand-lockup-light .brand-name { font-size: 38px; }

.login-simple-mark {
  width: 36px; height: 36px; border-radius: 9px;
  background: var(--brand);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.login-simple-mark svg { width: 20px; height: 20px; }
.login-simple-mark img { width: 24px; height: 24px; object-fit: contain; display: block; }

.login-simple-name {
  font-size: 17px; font-weight: 600;
  color: var(--ink); letter-spacing: -.2px;
}

.login-simple-subtitle {
  font-size: 12px; color: var(--ink4); margin-top: 1px;
}

.login-simple-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r4);
  padding: 28px;
}

.login-simple-heading {
  font-size: 15px; font-weight: 600;
  color: var(--ink); margin-bottom: 4px;
}

.login-simple-sub {
  font-size: 12px; color: var(--ink4);
  margin-bottom: 22px;
}

/* hide the old split layout */
.login-bg-split { display: contents; }
.login-left, .login-right { display: none !important; }

/* ── Form elements (shared) ── */
.f-lbl {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--ink3); margin-bottom: 5px; letter-spacing: .1px;
}
.f-inp {
  width: 100%; padding: 9px 12px; margin-bottom: 14px;
  border: 1px solid var(--border2); border-radius: var(--r3);
  font-size: 13px; outline: none;
  color: var(--ink); background: var(--bg);
  transition: border-color .15s, box-shadow .15s;
}
.f-inp:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(91,79,233,.10);
}
.pw-wrap     { position: relative; margin-bottom: 0; }
.pw-toggle   { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--ink4); cursor: pointer; padding: 3px; display: grid; place-items: center; }
.pw-toggle:hover { color: var(--ink2); }
.btn-login   { width: 100%; padding: 10px; background: var(--brand); color: white; border: none; border-radius: var(--r3); font-size: 13px; font-weight: 600; cursor: pointer; transition: background .15s; margin-top: 4px; }
.btn-login:hover { background: var(--brand-d); }
.login-err   { color: var(--red); font-size: 12px; margin-top: 10px; display: none; }

/* Change password overlay */
#change-pw-overlay .login-card {
  background: var(--surface);
  border-radius: var(--r4);
  padding: 28px;
}

/* ═══════════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════════ */
#app         { height: 100vh; display: none; flex-direction: row; }
#app.on      { display: flex; }

/* Mobile header */
.mobile-header {
  display: none; align-items: center; justify-content: space-between;
  height: 52px; min-height: 52px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border2);
  position: fixed; top: 0; left: 0; right: 0; z-index: 190;
}
.mobile-header .tb-brand { gap: 8px; }
.btn-menu {
  display: none; flex-direction: column; justify-content: center; gap: 5px;
  background: none; border: none; padding: 6px; cursor: pointer; flex-shrink: 0;
}
.btn-menu span { display: block; width: 18px; height: 1.5px; background: var(--ink); border-radius: 2px; }

/* Sidebar scrim */
.sidebar-scrim {
  display: none; position: fixed; inset: 0; z-index: 195;
  background: rgba(0,0,0,.3); opacity: 0;
  transition: opacity .25s ease; pointer-events: none;
}

/* ── SIDEBAR ── */
.topbar {
  width: var(--sidebar-w); min-width: var(--sidebar-w); height: 100vh;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0; overflow: hidden; z-index: 100;
}

.tb-brand {
  display: flex; align-items: center; gap: 9px;
  padding: 16px 14px 12px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.tb-mark {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--brand);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.tb-mark svg { width: 16px; height: 16px; }

.tb-logo {
  width: 150px;
  height: auto;
  display: block;
  object-fit: contain;
}

.tb-name {
  font-size: 14px; font-weight: 600;
  color: var(--ink); letter-spacing: -.2px;
}

/* Nav */
.tb-nav {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 8px; flex: 1; overflow-y: auto;
}

.tb-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 10px;
  border: none; border-radius: var(--r3);
  background: transparent; color: var(--ink3);
  font-size: 13px; font-weight: 400; text-align: left;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .1s, color .1s;
}
.tb-btn:hover { background: var(--bg); color: var(--ink2); }
.tb-btn.act   { background: var(--brand-l); color: var(--brand); font-weight: 600; }
.sb-divider   { height: 1px; background: var(--border); margin: 4px 4px; }

/* Sidebar footer */
.tb-right {
  padding: 10px 12px 14px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px; flex-shrink: 0;
}
.api-chip { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink4); }
.api-led  { width: 6px; height: 6px; border-radius: 50%; background: var(--ink4); flex-shrink: 0; }
.api-led.on  { background: #22c55e; }
.api-led.off { background: var(--red); }
.sidebar-user {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
#tb-username { font-size: 12px; font-weight: 600; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── App body ── */
.app-body { flex: 1; min-width: 0; height: 100vh; overflow: hidden; position: relative; background: var(--bg); }
.page     { position: absolute; inset: 0; display: none; background: var(--bg); }
.page.act { display: flex; flex-direction: column; }
.page-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; }

/* Server status banner */
.server-banner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 8px 18px; font-size: 13px; font-weight: 500;
  position: relative; z-index: 50; flex-shrink: 0;
}
.server-banner-warn  { background: var(--amber-l); color: var(--amber); border-bottom: 1px solid var(--amber-b); }
.server-banner-error { background: var(--red-l); color: var(--red); border-bottom: 1px solid var(--red-b); }

/* ═══════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--r3);
  font-size: 13px; font-weight: 500; border: 1px solid transparent;
  transition: background .12s, border-color .12s, color .12s;
  cursor: pointer; outline: none; white-space: nowrap; line-height: 1.4;
}
.btn:focus-visible         { outline: 2px solid var(--brand); outline-offset: 2px; }
.tb-btn:focus-visible      { outline: 2px solid var(--brand); outline-offset: 1px; }
.rb-btn:focus-visible      { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn-login:focus-visible   { outline: 2px solid var(--brand); outline-offset: 2px; }
.f-inp:focus-visible       { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(91,79,233,.15); }
.tpl-card:focus-visible    { outline: 2px solid var(--brand); outline-offset: 2px; }
.dash-qa:focus-visible     { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn-primary  { background: var(--brand); color: white; border-color: var(--brand); }
.btn-primary:hover  { background: var(--brand-d); border-color: var(--brand-d); }
.btn-primary:disabled { opacity: .38; cursor: not-allowed; pointer-events: none; }
.btn-outline:disabled { opacity: .38; cursor: not-allowed; pointer-events: none; }
.btn-login:disabled   { opacity: .6;  cursor: not-allowed; pointer-events: none; }
.btn-outline  { background: var(--surface); color: var(--ink2); border-color: var(--border2); }
.btn-outline:hover  { border-color: var(--brand); color: var(--brand); background: var(--brand-l); }
.btn-danger   { background: var(--red-l); color: var(--red); border-color: var(--red-b); }
.btn-danger:hover   { background: var(--red); color: white; border-color: var(--red); }
.btn-ghost    { background: transparent; color: var(--ink3); border-color: transparent; }
.btn-ghost:hover    { background: var(--bg2); }
.btn-sm  { padding: 5px 10px; font-size: 12px; }
.btn-lg  { padding: 10px 20px; font-size: 14px; }

/* ═══════════════════════════════════════════════
   DASHBOARD
═══════════════════════════════════════════════ */
.dash-wrap { width: 100%; margin: 0; padding: 32px clamp(18px, 2vw, 28px) 64px; }

.dash-greeting {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px; gap: 16px; flex-wrap: wrap;
}
.dash-greeting-name { font-size: 22px; font-weight: 600; color: var(--ink); letter-spacing: -.3px; }
.dash-greeting-sub  { font-size: 13px; color: var(--ink3); margin-top: 3px; }

.dash-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px;
}
@media (max-width: 800px) { .dash-stats { grid-template-columns: repeat(2, 1fr); } }

.dash-stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r4);
  padding: 16px; display: flex; align-items: center; gap: 12px;
  transition: border-color .15s;
}
.dash-stat-card:hover { border-color: var(--border2); }
.dash-stat-icon { width: 38px; height: 38px; border-radius: var(--r3); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; flex-shrink: 0; letter-spacing: .4px; }
.dash-stat-val  { font-size: 22px; font-weight: 600; color: var(--ink); font-family: var(--mono); line-height: 1; }
.dash-stat-lbl  { font-size: 11px; color: var(--ink3); margin-top: 3px; font-weight: 500; }

.dash-section-title {
  font-size: 11px; font-weight: 600; color: var(--ink3); letter-spacing: .5px;
  text-transform: uppercase; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.dash-section-title a { font-size: 12px; color: var(--brand); font-weight: 500; text-transform: none; letter-spacing: 0; }

.dash-quick {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 28px;
}
@media (max-width: 560px) { .dash-quick { grid-template-columns: 1fr; } }

.dash-qa {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r4);
  padding: 18px 16px; text-align: left; cursor: pointer; display: block;
  transition: border-color .15s, transform .1s;
}
.dash-qa:hover { border-color: var(--brand-b); transform: translateY(-1px); }
.dash-qa-icon  { font-size: 20px; margin-bottom: 8px; }
.dash-qa-label { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 2px; }
.dash-qa-sub   { font-size: 11px; color: var(--ink3); line-height: 1.5; }

/* Template cards */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tpl-card {
  background: var(--surface); border-radius: var(--r4); padding: 14px 15px;
  border: 1px solid var(--border);
  transition: border-color .15s, transform .12s;
  display: flex; align-items: flex-start; gap: 10px;
  cursor: pointer; position: relative; outline: none; user-select: none;
  min-width: 0;
}
.tpl-card:hover { border-color: var(--brand-b); transform: translateY(-1px); }
.tpl-card:active { transform: scale(.98); }
.tpl-card--sel { border-color: var(--brand) !important; background: var(--brand-l) !important; }
.tpl-card--clickable { cursor: pointer; }
.tpl-card--clickable:hover { border-color: var(--brand); }
.tpl-card-icon { font-size: 20px; flex-shrink: 0; line-height: 1; }
.tpl-card-body { flex: 1; min-width: 0; overflow: hidden; }
.tpl-card-top  { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 8px; gap: 6px; min-width: 0; }
.tpl-card-doc-icon { font-size: 22px; line-height: 1; }
.tpl-card-edit-btn {
  width: 24px; height: 24px; border-radius: var(--r2); background: var(--bg);
  border: 1px solid var(--border2); font-size: 12px; color: var(--ink3);
  cursor: pointer; display: grid; place-items: center; flex-shrink: 0;
  transition: background .12s, color .12s;
}
.tpl-card-edit-btn:hover { background: var(--brand-l); border-color: var(--brand-b); color: var(--brand); }
.tpl-card-name { font-weight: 600; font-size: 13px; color: var(--ink); margin-bottom: 3px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; }
.tpl-card--sel .tpl-card-name { color: var(--brand); }
.tpl-card-date { font-size: 11px; color: var(--ink4); margin-bottom: 3px; }
.tpl-card-meta { font-size: 11px; color: var(--ink3); margin-bottom: 8px; }
.tpl-card-generate-hint { font-size: 11px; font-weight: 600; color: var(--brand); opacity: 0; transform: translateY(3px); transition: opacity .15s, transform .15s; }
.tpl-card--clickable:hover .tpl-card-generate-hint { opacity: 1; transform: translateY(0); }
.tpl-card-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.tpl-card-check { position: absolute; top: 8px; right: 9px; font-size: 11px; color: var(--brand); font-weight: 800; background: white; border-radius: 50%; width: 18px; height: 18px; display: grid; place-items: center; }

.tpl-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; padding: 4px 0 12px; }
@media (max-width: 700px) { .tpl-card-grid { grid-template-columns: repeat(2, 1fr); } }

.empty-state { text-align: center; padding: 64px 24px; color: var(--ink3); }
.empty-state-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--ink2); }
.empty-state-sub   { font-size: 13px; margin-bottom: 22px; line-height: 1.6; }

/* ═══════════════════════════════════════════════
   UPLOAD PAGE
═══════════════════════════════════════════════ */
.upload-wrap { width: min(100%, 760px); margin: 0 auto; padding: 40px clamp(20px, 3vw, 36px) 64px; }
.page-title  { font-size: 20px; font-weight: 600; color: var(--ink); letter-spacing: -.2px; margin-bottom: 6px; }
.page-sub    { color: var(--ink3); font-size: 13px; margin-bottom: 22px; line-height: 1.65; }
.page-sub code { font-family: var(--mono); font-size: 12px; background: var(--bg2); padding: 1px 5px; border-radius: 3px; color: var(--ink2); }

.dropzone {
  border: 2px dashed var(--border2); border-radius: var(--r4);
  background: var(--surface); padding: 48px 24px; text-align: center;
  cursor: pointer; transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-l); }
.dz-icon  { font-size: 32px; margin-bottom: 10px; }
.dz-title { font-size: 14px; font-weight: 600; color: var(--ink2); margin-bottom: 5px; }
.dz-sub   { font-size: 12px; color: var(--ink4); }
.dz-chosen { margin-top: 12px; font-size: 13px; color: var(--brand); font-weight: 500; }

/* ═══════════════════════════════════════════════
   EDITOR RIBBON
═══════════════════════════════════════════════ */
.word-ribbon {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 16px; display: flex; align-items: center;
  gap: 10px; min-height: var(--ribbon-h); flex-wrap: wrap;
  position: relative; z-index: 10;
}
.ribbon-left  { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ribbon-fname { font-size: 13px; font-weight: 600; color: var(--ink); max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ribbon-badge { background: var(--amber); color: white; font-size: 9px; font-weight: 700; letter-spacing: .5px; padding: 2px 6px; border-radius: 3px; text-transform: uppercase; }
.ribbon-sep   { width: 1px; height: 30px; background: var(--border2); flex-shrink: 0; }
.ribbon-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ribbon-group { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.ribbon-group-label { font-size: 9px; color: var(--ink4); letter-spacing: .3px; text-transform: uppercase; font-weight: 500; }
.ribbon-group-btns  { display: flex; gap: 2px; }
.rb-btn {
  padding: 5px 10px; border: 1px solid var(--border2);
  border-radius: var(--r2); background: var(--surface); color: var(--ink2);
  font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .1s, border-color .1s, color .1s;
}
.rb-btn:hover    { background: var(--bg); border-color: var(--ink4); }
.rb-btn.active   { background: var(--brand-l); border-color: var(--brand-b); color: var(--brand); }
.rb-italic   { font-style: italic; }
.rb-underline { text-decoration: underline; }
.rb-var   { background: var(--brand-l); border-color: var(--brand-b); color: var(--brand); }
.rb-var:hover { background: var(--brand); color: white; border-color: var(--brand); }
.rb-save  { background: var(--green-l); border-color: var(--green-b); color: var(--green); }
.rb-save:hover { background: var(--green); color: white; border-color: var(--green); }
.rb-clear { background: var(--amber-l); border-color: var(--amber-b); color: var(--amber); }
.rb-clear:hover { background: var(--amber); color: white; }
.rb-back  { background: var(--bg); }

/* ── Editor body ── */
.editor-body {
  display: flex; flex: 1; min-height: 0; overflow: hidden;
}
.editor-left {
  flex: 1; min-width: 0; overflow: hidden;
  display: flex; flex-direction: column; background: var(--bg);
}
.preview-scroll { flex: 1; overflow-y: auto; padding: clamp(16px, 2.4vw, 32px); }
.doc-paper {
  width: min(100%, 860px); margin: 0 auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r4);
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
  min-height: 100%;
}
.doc-sheet {
  padding: 52px 56px; min-height: 100%;
  font-family: var(--serif); font-size: 14px; color: var(--ink); line-height: 1.8;
  outline: none;
}
@media (max-width: 700px) { .doc-sheet { padding: 28px 20px; } }

/* Variable chip inside document */
.var-chip {
  display: inline-block; background: var(--brand-l); color: var(--brand);
  border: 1px solid var(--brand-b); border-radius: var(--r);
  font-family: var(--mono); font-size: 12px; padding: 1px 5px;
  cursor: pointer; user-select: none;
  transition: background .12s, color .12s;
  vertical-align: baseline;
}
.var-chip:hover { background: var(--brand); color: white; }

/* Variables panel */
.var-panel {
  width: clamp(300px, 24vw, 380px); min-width: 300px; max-width: 380px;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.vp-head { padding: 18px 18px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.vp-head-title { font-size: 14px; font-weight: 700; color: var(--ink); }
.vp-head-sub   { font-size: 12px; color: var(--ink4); margin-top: 2px; }
.vp-list { flex: 1; overflow-y: auto; padding: 12px; }
.vp-item {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r3); padding: 10px 12px; margin-bottom: 6px;
}
.vp-item-label { font-size: 12px; font-weight: 600; color: var(--ink2); }
.vp-item-key   { font-family: var(--mono); font-size: 11px; color: var(--brand); margin-top: 2px; }
.vp-item-type  { font-size: 10px; color: var(--ink4); margin-top: 4px; }
.vp-item-actions { display: flex; gap: 5px; margin-top: 8px; }
.vp-foot { padding: 12px; border-top: 1px solid var(--border); flex-shrink: 0; }
.vp-empty {
  border: 1px dashed var(--border2);
  border-radius: var(--r4);
  background: var(--bg);
  padding: 18px 14px;
  text-align: center;
}
.vp-empty-title { font-size: 13px; font-weight: 700; color: var(--ink2); }
.vr {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r4);
  padding: 12px;
  margin-bottom: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.vr:hover {
  border-color: var(--brand-b);
  box-shadow: 0 1px 8px rgba(0,0,0,.04);
}
.vr-top {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}
.vr-dot {
  width: 8px; height: 8px; margin-top: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-l);
}
.vr-dot-manual {
  background: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-l);
}
.vr-info { min-width: 0; }
.vr-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vr-key {
  display: inline-flex;
  max-width: 100%;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: var(--r);
  background: var(--brand-l);
  color: var(--brand);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vr-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.vr-btn,
.vr-del,
.vr-rename button {
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  background: var(--surface);
  color: var(--ink2);
  font-size: 11px;
  font-weight: 600;
  min-height: 26px;
}
.vr-btn { padding: 4px 8px; }
.vr-btn:hover,
.vr-rename button:hover {
  border-color: var(--brand-b);
  background: var(--brand-l);
  color: var(--brand);
}
.vr-del {
  width: 26px;
  display: grid;
  place-items: center;
  color: var(--red);
  background: var(--red-l);
  border-color: var(--red-b);
}
.vr-del:hover { background: var(--red); color: white; border-color: var(--red); }
.vr-rename {
  display: none;
  gap: 6px;
  margin-top: 10px;
}
.vr-rename.show { display: flex; }
.vr-rename input {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  background: var(--bg);
  color: var(--ink);
  outline: none;
}
.vr-rename input:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(91,79,233,.10);
}
.vr-rename button { padding: 4px 8px; flex-shrink: 0; }
.preview-var-key,
.ev-chip,
.var-chip {
  font-weight: 700;
}

/* ═══════════════════════════════════════════════
   GENERATE PAGE
═══════════════════════════════════════════════ */
.gen-wrap { width: 100%; margin: 0; padding: 28px clamp(18px, 2vw, 28px) 64px; }
.gen-top-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }

/* Generate form */
.gen-form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r4); padding: 20px 22px; margin-top: 16px;
}
.gen-form-title { font-size: 14px; font-weight: 600; color: var(--ink); margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.gen-form-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .gen-form-grid { grid-template-columns: 1fr; } }
.gen-form-field { display: flex; flex-direction: column; gap: 4px; }
.gen-form-field label { font-size: 11px; font-weight: 600; color: var(--ink3); }
.gen-form-field input,
.gen-form-field select,
.gen-form-field textarea {
  padding: 8px 11px; border: 1px solid var(--border2);
  border-radius: var(--r3); font-size: 13px;
  color: var(--ink); background: var(--bg);
  transition: border-color .15s, box-shadow .15s; outline: none;
}
.gen-form-field input:focus,
.gen-form-field select:focus,
.gen-form-field textarea:focus {
  border-color: var(--brand); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(91,79,233,.10);
}
.gen-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* Output format toggle */
.fmt-toggle { display: flex; gap: 6px; margin-top: 10px; }
.fmt-btn {
  padding: 5px 12px; border: 1px solid var(--border2);
  border-radius: var(--r2); font-size: 12px; font-weight: 500;
  background: var(--surface); color: var(--ink3); cursor: pointer;
  transition: all .12s;
}
.fmt-btn.sel { background: var(--brand-l); border-color: var(--brand-b); color: var(--brand); }

/* ═══════════════════════════════════════════════
   LIBRARY PAGE
═══════════════════════════════════════════════ */
.lib-wrap { width: 100%; margin: 0; padding: 28px clamp(18px, 2vw, 28px) 64px; }
.lib-head  { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.lib-title { font-size: 20px; font-weight: 600; color: var(--ink); letter-spacing: -.2px; }
.lib-grid  { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }

/* ═══════════════════════════════════════════════
   DROPDOWNS PAGE
═══════════════════════════════════════════════ */
/* inherits gen-form + page-title */

/* Dropdown card */
.dd-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r4); padding: 16px 18px; margin-bottom: 10px;
}
.dd-card-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.dd-card-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.dd-card-key  {
  font-size: 10px; font-family: var(--mono); color: var(--brand);
  background: var(--brand-l); padding: 2px 8px; border-radius: 20px;
}
.dd-card-actions { margin-left: auto; display: flex; gap: 6px; }
.dd-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.dd-chip  {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px;
  font-size: 11px; color: var(--ink2);
}

/* ═══════════════════════════════════════════════
   USERS PAGE
═══════════════════════════════════════════════ */
/* uses surface card pattern + f-inp */
.user-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r4); padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; margin-bottom: 8px;
}
.user-av {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-l); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.user-role { font-size: 11px; color: var(--ink4); margin-top: 1px; }
.user-badge {
  font-size: 10px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px;
}
.badge-admin { background: var(--brand-l); color: var(--brand); }
.badge-user  { background: var(--bg2); color: var(--ink3); }

/* ═══════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════ */
.modal-bg {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.35);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-bg.on { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--r4); padding: 24px;
  width: 100%; max-width: 440px;
  position: relative;
}
.modal-lg { max-width: 560px; }
.modal-title { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.modal-sub   { font-size: 12px; color: var(--ink3); margin-bottom: 14px; line-height: 1.5; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Form fields inside modal */
.ff { margin-bottom: 12px; }
.ff label { display: block; font-size: 11px; font-weight: 600; color: var(--ink3); margin-bottom: 4px; }
.ff input, .ff select, .ff textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border2); border-radius: var(--r3);
  font-size: 13px; color: var(--ink); background: var(--bg);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.ff input:focus, .ff select:focus, .ff textarea:focus {
  border-color: var(--brand); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(91,79,233,.10);
}

.m-key-row { font-size: 12px; color: var(--ink3); margin: 6px 0; }
.m-key-val { font-family: var(--mono); color: var(--brand); font-size: 12px; background: var(--brand-l); padding: 1px 6px; border-radius: 3px; }
.m-existing-vars { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.smart-note { font-size: 11px; color: var(--amber); background: var(--amber-l); border-radius: var(--r2); padding: 5px 9px; margin-top: 5px; }
.val-list { list-style: none; padding: 0; margin: 10px 0 16px; }
.val-list li { font-size: 12px; color: var(--red); padding: 4px 0; border-bottom: 1px solid var(--red-b); }
.val-list li:last-child { border-bottom: none; }

/* ═══════════════════════════════════════════════
   PREVIEW MODAL
═══════════════════════════════════════════════ */
.preview-modal-bg {
  position: fixed; inset: 0; z-index: 600;
  background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.preview-modal-bg.on { display: flex; }
.preview-modal {
  background: var(--surface); border-radius: var(--r4);
  width: 100%; max-width: 700px; max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.preview-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.preview-modal-title { font-size: 14px; font-weight: 600; color: var(--ink); }
.preview-modal-close {
  width: 28px; height: 28px; border-radius: 50%;
  border: none; background: var(--bg2); color: var(--ink3);
  font-size: 18px; display: grid; place-items: center; cursor: pointer;
}
.preview-modal-close:hover { background: var(--red-l); color: var(--red); }
.preview-modal-body {
  flex: 1; overflow-y: auto; padding: 20px 22px;
  font-family: var(--serif); font-size: 13px; line-height: 1.8; color: var(--ink);
}
.preview-modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   BULK MODAL
═══════════════════════════════════════════════ */
.bulk-modal-bg {
  position: fixed; inset: 0; z-index: 600;
  background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.bulk-modal-bg.on { display: flex; }
.bulk-modal {
  background: var(--surface); border-radius: var(--r4);
  width: 100%; max-width: 640px; max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.bulk-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.bulk-modal-title { font-size: 14px; font-weight: 600; color: var(--ink); }
.bulk-modal-body { flex: 1; overflow-y: auto; padding: 18px 20px; }
.bulk-modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.bulk-csv-hint {
  font-size: 12px; color: var(--ink3); line-height: 1.6;
  background: var(--bg); border-radius: var(--r3); padding: 12px 14px;
  margin-bottom: 14px;
}
.bulk-csv-hint code { font-family: var(--mono); font-size: 11px; background: var(--bg2); padding: 1px 4px; border-radius: 3px; }
.bulk-dropzone {
  border: 2px dashed var(--border2); border-radius: var(--r4);
  background: var(--surface); padding: 36px 24px; text-align: center;
  cursor: pointer; transition: border-color .2s, background .2s;
  margin-bottom: 14px;
}
.bulk-dropzone:hover { border-color: var(--brand); background: var(--brand-l); }
.bulk-dz-title { font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 4px; }
.bulk-dz-sub   { font-size: 11px; color: var(--ink4); }

/* ═══════════════════════════════════════════════
   EASY DROPDOWN MODAL (override inline styles in HTML)
═══════════════════════════════════════════════ */
#easy-dd-modal .modal {
  border-radius: var(--r4); padding: 24px; max-width: 560px;
}

/* ═══════════════════════════════════════════════
   TOASTS
═══════════════════════════════════════════════ */
#toasts {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
  max-width: calc(100vw - 40px);
}
.toast {
  background: var(--ink); color: white;
  padding: 10px 14px; border-radius: var(--r3);
  font-size: 13px; font-weight: 500;
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  animation: toast-in .22s cubic-bezier(.34,1.56,.64,1);
  transition: opacity .3s;
}
.toast-icon {
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0; line-height: 1;
}
.toast-success, .toast-s { background: var(--green); }
.toast-error,   .toast-e { background: var(--red); }
.toast-warn,    .toast-w { background: var(--amber); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.95); } to { opacity: 1; transform: none; } }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin .7s linear infinite; }

/* ═══════════════════════════════════════════════
   SELECTION TIP
═══════════════════════════════════════════════ */
#sel-tip {
  position: fixed; z-index: 800; display: none;
  background: var(--ink); color: white;
  font-size: 11px; font-weight: 600; padding: 5px 11px;
  border-radius: var(--r2); pointer-events: none;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════
   MOBILE RESPONSIVE
═══════════════════════════════════════════════ */
@media (max-width: 768px) {
  .mobile-header { display: flex; }
  .btn-menu      { display: flex; }

  .topbar {
    position: fixed; top: 52px; left: 0; height: calc(100vh - 52px);
    transform: translateX(-100%); transition: transform .25s ease;
    z-index: 200;
  }
  .topbar.open { transform: translateX(0); }
  .sidebar-scrim { display: block; }
  .sidebar-scrim.on { opacity: 1; pointer-events: auto; }

  .app-body { margin-top: 52px; height: calc(100vh - 52px); }
  .dash-wrap { padding: 20px 16px 48px; }
  .gen-wrap { padding: 20px 16px 48px; }
  .lib-wrap { padding: 20px 16px 48px; }
  .admin-tools { grid-template-columns: 1fr; }
  .editor-body { flex-direction: column; overflow-y: auto; }
  .editor-left { flex: none; min-height: 58vh; overflow: visible; }
  .preview-scroll { overflow: visible; }
  .var-panel {
    width: 100%;
    min-width: 0;
    max-width: none;
    min-height: 260px;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .vp-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
    gap: 10px;
  }
  .vr { margin-bottom: 0; }
}

/* ═══════════════════════════════════════════════
   MISC UTILITIES
═══════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center;
  font-size: 10px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px; white-space: nowrap;
}
.badge-green  { background: var(--green-l);  color: var(--green); }
.badge-amber  { background: var(--amber-l);  color: var(--amber); }
.badge-red    { background: var(--red-l);    color: var(--red); }
.badge-purple { background: var(--purple-l); color: var(--purple); }
.badge-blue   { background: var(--brand-l);  color: var(--brand); }
.badge-gray   { background: var(--bg2);      color: var(--ink3); }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* Usage bar (template card) */
.usage-bar { height: 3px; border-radius: 2px; background: var(--bg2); margin-top: 8px; overflow: hidden; }
.usage-bar-fill { height: 100%; background: var(--brand); border-radius: 2px; transition: width .3s; }

/* ═══════════════════════════════════════════════
   TEMPLATE CARD — used by renderDash() & renderLib()
═══════════════════════════════════════════════ */
.tpl-card-top {
  display: flex; align-items: flex-start;
  justify-content: space-between; margin-bottom: 8px;
  gap: 6px; min-width: 0;
}
.tpl-card-doc-icon {
  font-size: 11px; font-weight: 700;
  color: var(--brand); background: var(--brand-l);
  padding: 3px 7px; border-radius: var(--r2);
  letter-spacing: .3px; line-height: 1.6;
}
.tpl-card-edit-btn {
  padding: 3px 9px; border-radius: var(--r2);
  background: var(--bg); border: 1px solid var(--border2);
  font-size: 11px; font-weight: 500; color: var(--ink3);
  cursor: pointer; flex-shrink: 0;
  transition: background .12s, color .12s, border-color .12s;
}
.tpl-card-edit-btn:hover {
  background: var(--brand-l); border-color: var(--brand-b); color: var(--brand);
}
.tpl-card-name {
  font-weight: 600; font-size: 13px; color: var(--ink);
  margin-bottom: 3px; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; line-height: 1.35;
}
.tpl-card--sel .tpl-card-name { color: var(--brand); }
.tpl-card-date { font-size: 11px; color: var(--ink4); margin-bottom: 2px; }
.tpl-card-meta { font-size: 11px; color: var(--ink3); margin-bottom: 6px; }
.tpl-card-generate-hint {
  font-size: 11px; font-weight: 600; color: var(--brand);
  opacity: 0; transform: translateY(3px);
  transition: opacity .15s, transform .15s;
}
.tpl-card--clickable:hover .tpl-card-generate-hint {
  opacity: 1; transform: translateY(0);
}

/* ═══════════════════════════════════════════════
   TEMPLATE PICKER — Generate page (no selection)
═══════════════════════════════════════════════ */
.tpl-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px; margin-bottom: 8px;
}
.tpl-picker-card {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r4); padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.tpl-picker-card:hover {
  border-color: var(--brand-b); transform: translateY(-1px);
}
.tpl-picker-icon {
  font-size: 11px; font-weight: 700; color: var(--brand);
  background: var(--brand-l); padding: 4px 7px;
  border-radius: var(--r2); flex-shrink: 0; letter-spacing: .3px;
}
.tpl-picker-body { flex: 1; min-width: 0; }
.tpl-picker-name {
  font-size: 13px; font-weight: 600; color: var(--ink);
  white-space: normal; overflow: visible; text-overflow: clip;
  overflow-wrap: anywhere; line-height: 1.35;
}
.tpl-picker-meta { display: none; }
.tpl-picker-arrow {
  font-size: 14px; color: var(--ink4); flex-shrink: 0;
  transition: color .15s, transform .15s;
}
.tpl-picker-card:hover .tpl-picker-arrow {
  color: var(--brand); transform: translateX(3px);
}

/* ═══════════════════════════════════════════════
   GENERATE SELECTED BAR — template selected state
═══════════════════════════════════════════════ */
.gen-sel-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; background: var(--brand-l);
  border: 1px solid var(--brand-b); border-radius: var(--r4);
  padding: 12px 16px; margin-bottom: 16px; flex-wrap: wrap;
}
.gen-sel-bar-left  { display: flex; align-items: center; gap: 10px; min-width: 0; }
.gen-sel-bar-icon  {
  font-size: 11px; font-weight: 700; color: var(--brand);
  background: white; padding: 4px 8px; border-radius: var(--r2);
  flex-shrink: 0; letter-spacing: .3px;
}
.gen-sel-bar-name  {
  font-size: 14px; font-weight: 600; color: var(--brand);
  white-space: normal; overflow: visible; text-overflow: clip;
  overflow-wrap: anywhere; line-height: 1.35;
}
.gen-sel-bar-meta  { display: none; }
.gen-sel-bar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex-shrink: 0; }

/* ═══════════════════════════════════════════════
   LIBRARY PAGE CARDS
═══════════════════════════════════════════════ */
.lib-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r4); padding: 16px;
  transition: border-color .15s;
}
.lib-card:hover { border-color: var(--brand-b); }
.lib-card-hd   { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.lib-card-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.lib-card-date { font-size: 11px; color: var(--ink4); margin-top: 2px; }
.lib-var-count {
  font-size: 11px; font-weight: 600; color: var(--ink3);
  background: var(--bg2); padding: 3px 8px;
  border-radius: 20px; flex-shrink: 0;
}
.lib-var-list  { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; min-height: 24px; }
.lib-tag {
  font-size: 10px; background: var(--brand-l); color: var(--brand);
  padding: 2px 8px; border-radius: 20px;
}
.lib-card-act  { display: flex; gap: 6px; }
/* handle both .lib-card-act and .lib-card-acts from JS */
.lib-card-acts { display: flex; gap: 6px; }
.tpl-star {
  width: 28px; height: 28px;
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  background: var(--surface);
  color: var(--ink4);
  display: grid;
  place-items: center;
  font-size: 14px;
}
.tpl-star.on,
.tpl-star:hover { color: var(--amber); background: var(--amber-l); border-color: var(--amber-b); }
.review-data-grid { display: grid; gap: 8px; }
.review-data-row {
  display: grid;
  grid-template-columns: minmax(130px, 220px) 1fr;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r3);
}
.review-data-row strong { color: var(--ink2); font-family: var(--mono); font-size: 12px; }
.review-data-row span { color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }

.admin-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.admin-tool {
  min-height: 96px;
  text-align: left;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r4);
  background: var(--surface);
  color: var(--ink);
}
.admin-tool:hover { border-color: var(--brand2); box-shadow: var(--shadow-sm); }
.admin-tool-k {
  display: inline-flex;
  margin-bottom: 10px;
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--brand-l);
  color: var(--brand);
  font-size: 10px;
  font-weight: 800;
}
.admin-tool strong { display: block; font-size: 14px; margin-bottom: 4px; }
.admin-tool small { display: block; color: var(--ink3); line-height: 1.35; }

/* ═══════════════════════════════════════════════
   GENERATE FORM CARD & GROUPS
═══════════════════════════════════════════════ */
.gen-form-card {
  background: var(--surface); border-radius: var(--r4);
  border: 1px solid var(--border); overflow: visible;
  margin-bottom: 16px;
}
.gen-group { margin-bottom: 0; }
.gen-group-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px 8px; background: var(--bg);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
  cursor: pointer;
}
.gen-group-header:first-child { border-top: none; }
.gen-group-icon  { font-size: 14px; width: 22px; text-align: center; flex-shrink: 0; }
.gen-group-name  { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px; color: var(--ink3); }
.gen-group-count { margin-left: auto; font-size: 10px; color: var(--ink4); font-weight: 600; }
.gen-group-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 0;
}
.gen-group.is-collapsed .gen-group-fields { display: none; }
.gen-group-fields .ff {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  margin: 0;
}
.gen-group-fields .ff:last-child { border-right: none; }
@media (max-width: 720px) { .gen-group-fields .ff { border-right: none; } }
.gen-group-fields .ff label {
  display: block; font-size: 10px; font-weight: 700;
  color: var(--ink3); text-transform: uppercase;
  letter-spacing: .4px; margin-bottom: 6px;
}
.gen-group-fields .ff input,
.gen-group-fields .ff select,
.gen-group-fields .ff textarea {
  width: 100%; min-height: 36px; padding: 9px 11px;
  border: 1px solid var(--border2); border-radius: var(--r3);
  font-size: 13px; outline: none;
  background: var(--bg); color: var(--ink);
  font-family: var(--sans);
  transition: border-color .15s, box-shadow .15s;
}
.gen-group-fields .ff textarea {
  min-height: 36px;
  max-height: 220px;
  line-height: 1.45;
  resize: vertical;
  overflow-y: hidden;
}
.gen-group-fields .ff input:focus,
.gen-group-fields .ff select:focus,
.gen-group-fields .ff textarea:focus {
  border-color: var(--brand); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(91,79,233,.10);
}
.gen-group-fields .ff input.err,
.gen-group-fields .ff select.err,
.gen-group-fields .ff textarea.err { border-color: var(--red); }
.gen-group-fields .ff .ferr { font-size: 11px; color: var(--red); display: none; margin-top: 3px; }
.gen-group-fields .ff input.err ~ .ferr,
.gen-group-fields .ff select.err ~ .ferr,
.gen-group-fields .ff textarea.err ~ .ferr { display: block; }

/* Generate footer */
.gen-footer {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 18px; background: var(--bg);
  border-top: 1px solid var(--border); flex-wrap: wrap;
  border-radius: 0 0 var(--r4) var(--r4);
}
.gen-footer .btn-primary { min-width: 200px; justify-content: center; }

/* Format toggle */
.fmt-row  { display: flex; gap: 6px; }
.fmt-opt  {
  padding: 7px 18px; border: 1px solid var(--border2);
  border-radius: var(--r3); background: var(--surface);
  cursor: pointer; font-size: 13px; font-weight: 500;
  color: var(--ink2); transition: all .15s;
}
.fmt-opt.on {
  border-color: var(--brand); background: var(--brand-l); color: var(--brand);
}

/* Generate result bar */
.gen-result {
  display: none; margin-top: 14px;
  background: var(--green-l); border: 1px solid var(--green-b);
  border-radius: var(--r4); padding: 14px 18px;
  align-items: center; justify-content: space-between; gap: 10px;
}
.gen-result.show { display: flex; }
.gr-name { font-size: 14px; font-weight: 600; color: var(--green); }
.gr-meta { font-size: 11px; color: var(--ink3); margin-top: 2px; }
.btn-dl  {
  background: var(--green); color: white; border: none;
  padding: 8px 18px; border-radius: var(--r3);
  font-size: 13px; font-weight: 600; cursor: pointer;
  text-decoration: none; flex-shrink: 0;
}

/* Field badges */
.ff-badge    { font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 3px; margin-left: 5px; text-transform: uppercase; letter-spacing: .3px; vertical-align: middle; }
.fb-district { background: #dbeafe; color: #1e40af; }
.fb-casetype { background: #f3e8ff; color: #7e22ce; }
.fb-smart    { background: #dcfce7; color: #15803d; }
.fb-police   { background: #fef3c7; color: #92400e; }

/* No template state */
.no-tpl { text-align: center; padding: 48px 20px; color: var(--ink3); }
.no-tpl h3 { font-size: 17px; font-weight: 600; margin-bottom: 8px; color: var(--ink2); }

/* Array (repeat) sections */
.arr-section {
  background: var(--surface); border: 1px solid var(--brand-b);
  border-radius: var(--r4); padding: 16px; margin: 0 16px 16px;
}
.arr-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.arr-title  { font-size: 13px; font-weight: 700; color: var(--brand); text-transform: capitalize; }
.arr-row {
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r3); padding: 10px 10px 10px 12px;
  margin-bottom: 8px; position: relative;
}
.arr-row:last-child { margin-bottom: 0; }
.arr-row-num {
  font-size: 11px; font-weight: 700; color: var(--ink4);
  background: var(--bg2); border-radius: 4px; padding: 2px 6px;
  margin-top: 26px; flex-shrink: 0; min-width: 24px; text-align: center;
}
.arr-row-fields { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 10px; }
.arr-row-del {
  width: 28px; height: 28px; flex-shrink: 0; margin-top: 22px;
  background: var(--red-l); border: 1px solid var(--red-b);
  border-radius: var(--r3); color: var(--red); font-size: 18px;
  line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.arr-row-del:hover { background: var(--red); color: white; border-color: var(--red); }

/* ff-inline (inside array rows) */
.ff-inline { margin: 0; }
.ff-inline label { font-size: 10px; font-weight: 600; color: var(--ink3); display: block; margin-bottom: 3px; text-transform: uppercase; letter-spacing: .3px; }
.ff-inline input,
.ff-inline select,
.ff-inline textarea {
  width: 100%; min-height: 34px; padding: 7px 9px;
  border: 1px solid var(--border2); border-radius: var(--r);
  font-size: 12px; background: var(--bg); color: var(--ink);
  outline: none; font-family: var(--sans);
}
.ff-inline textarea {
  max-height: 180px;
  line-height: 1.45;
  resize: vertical;
  overflow-y: hidden;
}
.ff-inline input:focus,
.ff-inline select:focus,
.ff-inline textarea:focus { border-color: var(--brand); background: var(--surface); }

/* Card chips (gender, month) */
.card-select { display: flex; flex-wrap: wrap; gap: 6px; }
.card-chip {
  padding: 7px 14px; border: 1px solid var(--border2);
  border-radius: var(--r3); font-size: 13px; font-weight: 500;
  cursor: pointer; background: var(--surface); color: var(--ink2);
  transition: all .12s; user-select: none;
}
.card-chip:hover { border-color: var(--brand-b); color: var(--brand); background: var(--brand-l); }
.card-chip.selected { border-color: var(--brand); background: var(--brand); color: white; font-weight: 600; }
.card-chip.selected:hover { background: var(--brand-d); }

/* ═══════════════════════════════════════════════
   SEARCHABLE SELECT (sselect)
═══════════════════════════════════════════════ */
.sselect-wrap     { position: relative; }
.sselect-input    {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border2); border-radius: var(--r3);
  font-size: 13px; outline: none;
  background: var(--bg); color: var(--ink);
  cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.sselect-input:focus  { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(91,79,233,.10); }
.sselect-input.err    { border-color: var(--red); }
.sselect-dropdown {
  display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 200;
  background: var(--surface); border: 1px solid var(--brand-b);
  border-top: none; border-radius: 0 0 var(--r3) var(--r3);
  box-shadow: 0 8px 24px rgba(0,0,0,.10); max-height: 220px; overflow-y: auto;
}
.sselect-wrap.open .sselect-dropdown { display: block; }
.sselect-search  {
  width: 100%; padding: 8px 12px; border: none;
  border-bottom: 1px solid var(--border); font-size: 12px; outline: none;
  background: var(--bg); position: sticky; top: 0;
  font-family: var(--sans); color: var(--ink);
}
.sselect-opt     { padding: 8px 14px; font-size: 13px; cursor: pointer; color: var(--ink2); transition: background .08s; }
.sselect-opt:hover, .sselect-opt.focused { background: var(--brand-l); color: var(--brand); }
.sselect-opt.selected { background: var(--brand-l); color: var(--brand); font-weight: 600; }
.sselect-none    { padding: 12px 14px; font-size: 12px; color: var(--ink4); text-align: center; }
.sselect-clear   {
  position: absolute; right: 32px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--ink4); font-size: 16px;
  cursor: pointer; display: none; line-height: 1;
}
.sselect-wrap.has-value .sselect-clear { display: block; }
.sselect-arrow   {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: var(--ink4); font-size: 10px; pointer-events: none;
}

/* ═══════════════════════════════════════════════
   DROPDOWNS PAGE — built-in grid + custom cards
═══════════════════════════════════════════════ */
.dd-vars-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px; margin-bottom: 24px;
}
.dd-var-card {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--brand) !important;
  border-radius: var(--r3); padding: 10px 12px;
  cursor: pointer; transition: border-color .15s;
}
.dd-var-card:hover { border-color: var(--brand-b); background: var(--brand-l); }
.dd-var-card-label { font-size: 12px; font-weight: 600; color: var(--ink); margin-bottom: 3px; }
.dd-var-card-key   { font-size: 10px; color: var(--ink4); font-family: var(--mono); }

.dd-card-hd   { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.dd-card-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.dd-card-key  { font-size: 11px; color: var(--ink4); font-family: var(--mono); margin-top: 2px; }
.dd-card-key code { font-family: var(--mono); background: var(--brand-l); color: var(--brand); padding: 1px 5px; border-radius: 3px; font-size: 11px; }
.dd-options   { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.dd-opt       { font-size: 11px; background: var(--bg2); color: var(--ink2); padding: 2px 9px; border-radius: 20px; }
.dd-more      { color: var(--ink4); font-style: italic; }

/* Easy Dropdown Builder option rows */
.edd-option-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r3); padding: 7px 10px;
}
.edd-option-row:hover { border-color: var(--border2); }
.edd-opt-label {
  flex: 1; font-size: 13px; color: var(--ink);
  background: none; border: none; outline: none; font-family: var(--sans);
}
.edd-opt-label:focus { color: var(--brand); }
.edd-opt-del {
  width: 22px; height: 22px; border-radius: var(--r); flex-shrink: 0;
  background: none; border: none; color: var(--ink4); cursor: pointer;
  font-size: 15px; display: grid; place-items: center;
}
.edd-opt-del:hover { background: var(--red-l); color: var(--red); }

/* Mobile fixes for gen form */
@media (max-width: 600px) {
  .gen-group-header { position: relative; top: auto; }
  .arr-section { margin: 0 10px 14px; padding: 12px; }
  .arr-row { flex-wrap: wrap; padding: 10px; }
  .arr-row-num { margin-top: 0; }
  .arr-row-fields { flex-basis: calc(100% - 38px); grid-template-columns: 1fr; }
  .arr-row-del { margin-top: 0; margin-left: auto; }
  .gen-footer {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    z-index: 50; padding: 10px 14px;
  }
  .gen-footer .btn-primary { flex: 1; min-width: unset; }
}

/* ==========================================================================
   Legal desktop refresh
   UI-only overrides for a compact office-software shell.
   ========================================================================== */

:root {
  --brand:        #1f5f9f;
  --brand2:       #1f5f9f;
  --brand-d:      #184c80;
  --brand-l:      #e9f2fb;
  --brand-b:      #9fc3e5;
  --bg:           #eef2f6;
  --bg2:          #e4eaf1;
  --surface:      #ffffff;
  --border:       #ccd6e2;
  --border2:      #b7c5d5;
  --ink:          #102033;
  --ink2:         #24364b;
  --ink3:         #52647a;
  --ink4:         #7b8da3;
  --green:        #18703f;
  --green-l:      #e5f5ec;
  --green-b:      #a8d7bd;
  --amber:        #9a5b12;
  --amber-l:      #fff1d8;
  --amber-b:      #e7bf79;
  --red:          #a73333;
  --red-l:        #fbe8e8;
  --red-b:        #e7b7b7;
  --purple:       #4e5d8c;
  --purple-l:     #edf0fa;
  --teal:         #0c6b61;
  --teal-l:       #e2f4f1;
  --sidebar-w:    100%;
  --topbar-h:     108px;
  --r:            3px;
  --r2:           4px;
  --r3:           6px;
  --r4:           8px;
  --sans:         "Segoe UI", "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  --shadow-sm:    0 1px 2px rgba(16,32,51,.08);
  --shadow-md:    0 8px 24px rgba(16,32,51,.12);
}

html,
body {
  font-size: 13px;
  background:
    linear-gradient(180deg, #f7f9fc 0, var(--bg) 180px);
}

body {
  color: var(--ink);
}

#app.on {
  display: flex;
  flex-direction: column;
  border: 1px solid #0f2034;
  background: var(--bg);
}

.topbar {
  width: 100%;
  min-width: 0;
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  background: linear-gradient(180deg, #142238 0 38px, #ffffff 38px 100%);
  border-right: 0;
  border-bottom: 1px solid var(--border2);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: 38px 70px;
  overflow: visible;
  box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
}

.tb-brand {
  grid-column: 1;
  grid-row: 1;
  height: 38px;
  padding: 0 16px;
  border-bottom: 0;
  gap: 10px;
  background: transparent;
}

.tb-mark,
.login-simple-mark {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: linear-gradient(180deg, #2f7ec6, #155a96);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.28);
}

.tb-logo {
  width: 154px;
  max-height: 38px;
}

.topbar .brand-lockup {
  height: 38px;
}

.topbar .brand-mark {
  width: 30px;
  height: 30px;
}

.topbar .brand-name {
  font-size: 18px;
}

.topbar .brand-subtitle {
  font-size: 7.5px;
}

.login-brand-logo {
  width: 286px;
}

.tb-name {
  color: white;
  font-weight: 700;
  letter-spacing: 0;
}

.tb-name::after {
  content: "AlphaLegist Legal Document Studio";
  display: inline-flex;
  align-items: center;
  height: 20px;
  margin-left: 12px;
  padding: 0 10px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  color: #d7e5f6;
  background: rgba(255,255,255,.06);
  font-size: 11px;
  font-weight: 600;
}

.tb-nav {
  grid-column: 1 / 3;
  grid-row: 2;
  flex-direction: row;
  align-items: stretch;
  gap: 4px;
  padding: 9px 12px 10px;
  overflow-x: auto;
  overflow-y: hidden;
}

.tb-btn {
  width: auto;
  min-width: 86px;
  height: 50px;
  padding: 7px 12px;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: var(--r3);
  color: var(--ink2);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.tb-btn svg {
  width: 16px;
  height: 16px;
  opacity: .84 !important;
}

.tb-btn:hover {
  background: #f2f6fb;
  color: var(--brand-d);
  border-color: var(--border);
}

.tb-btn.act {
  background: linear-gradient(180deg, #f0f6fd, #dcebf9);
  color: var(--brand-d);
  border-color: var(--brand-b);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.9), var(--shadow-sm);
}

.sb-divider {
  width: 1px;
  height: 42px;
  margin: 4px 4px;
  background: var(--border);
}

.tb-right {
  grid-column: 3;
  grid-row: 1 / 3;
  min-width: 250px;
  padding: 8px 14px;
  border-top: 0;
  border-left: 1px solid rgba(255,255,255,.08);
  display: grid;
  grid-template-rows: 26px 1fr;
  align-items: center;
  background: transparent;
}

.api-chip {
  justify-self: end;
  color: #d7e5f6;
  font-size: 11px;
}

.sidebar-user {
  align-self: end;
  justify-content: flex-end;
  gap: 10px;
}

#tb-username {
  max-width: 130px;
  color: var(--ink2);
}

.app-body {
  height: calc(100vh - var(--topbar-h) - 2px);
  background: #e9eef4;
}

.page {
  background:
    linear-gradient(180deg, #f7f9fc 0, #edf2f7 90px, #e9eef4 100%);
}

.page-scroll {
  scrollbar-width: thin;
}

.dash-wrap,
.gen-wrap,
.lib-wrap,
.upload-wrap,
#page-dropdowns .page-scroll > div,
#page-users .page-scroll > div {
  padding: 18px 18px 44px !important;
}

.dash-greeting,
.gen-top-bar,
.lib-head,
#page-dropdowns .page-scroll > div > div:first-child,
#page-users .page-scroll > div > div:first-child {
  min-height: 54px;
  margin-bottom: 14px !important;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r4);
  background: linear-gradient(180deg, #ffffff, #f7f9fc);
  box-shadow: var(--shadow-sm);
}

.dash-greeting-name,
.page-title,
.lib-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0;
  color: #162b44;
}

.dash-greeting-sub,
.page-sub {
  color: var(--ink3);
}

.dash-stats,
.dash-quick,
.tpl-grid,
.tpl-card-grid,
.tpl-picker-grid,
.lib-grid,
.dd-vars-grid,
.admin-tools {
  gap: 8px;
}

.dash-stat-card,
.dash-qa,
.tpl-card,
.tpl-picker-card,
.lib-card,
.dd-card,
.dd-var-card,
.admin-tool,
.user-card,
.gen-form,
.gen-form-card,
.arr-section,
.dropzone,
.bulk-dropzone {
  border-color: var(--border);
  border-radius: var(--r4);
  box-shadow: var(--shadow-sm);
}

.dash-stat-card,
.dash-qa,
.tpl-card,
.tpl-picker-card,
.lib-card,
.admin-tool,
.user-card {
  background: linear-gradient(180deg, #ffffff, #fbfcfe);
}

.dash-stat-card {
  padding: 12px 14px;
}

.dash-stat-icon,
.dash-qa-icon,
.tpl-card-doc-icon,
.tpl-picker-icon,
.gen-sel-bar-icon,
.admin-tool-k {
  border: 1px solid rgba(31,95,159,.16);
  border-radius: var(--r2) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.65);
}

.dash-stat-val {
  font-size: 20px;
  color: #142238;
}

.dash-section-title {
  margin: 16px 2px 8px;
  color: #334a65;
}

.dash-qa {
  padding: 14px;
}

.tpl-card,
.tpl-picker-card,
.lib-card {
  transform: none;
}

.tpl-card:hover,
.tpl-picker-card:hover,
.lib-card:hover,
.dash-qa:hover,
.dash-stat-card:hover,
.admin-tool:hover {
  border-color: var(--brand-b);
  box-shadow: 0 2px 10px rgba(31,95,159,.12);
  transform: none;
}

.tpl-card--sel,
.fmt-opt.on,
.fmt-btn.sel,
.card-chip.selected,
.gen-sel-bar {
  background: #e6f1fb !important;
  color: var(--brand-d);
  border-color: var(--brand-b) !important;
}

.btn,
.btn-login,
.rb-btn,
.fmt-opt,
.fmt-btn,
.card-chip,
.tpl-star,
.preview-modal-close,
.edd-opt-del {
  border-radius: var(--r3);
  font-weight: 600;
}

.btn {
  min-height: 32px;
  padding: 6px 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}

.btn-primary,
.btn-login,
.btn-dl {
  background: linear-gradient(180deg, #2f7ec6, #1f5f9f);
  border-color: #1a5289;
  color: white;
}

.btn-primary:hover,
.btn-login:hover,
.btn-dl:hover {
  background: linear-gradient(180deg, #276eaf, #184c80);
}

.btn-outline {
  background: linear-gradient(180deg, #ffffff, #f4f7fa);
  border-color: var(--border2);
}

.btn-outline:hover {
  background: #eef6fd;
  border-color: var(--brand-b);
  color: var(--brand-d);
}

.f-inp,
.ff input,
.ff select,
.ff textarea,
.gen-form-field input,
.gen-form-field select,
.gen-form-field textarea,
.gen-group-fields .ff input,
.gen-group-fields .ff select,
.gen-group-fields .ff textarea,
.ff-inline input,
.ff-inline select,
.ff-inline textarea,
.sselect-input,
#edd-new-opt {
  min-height: 34px;
  border-radius: var(--r2) !important;
  border-color: var(--border2) !important;
  background: #fbfdff !important;
  box-shadow: inset 0 1px 2px rgba(16,32,51,.05);
}

.f-inp:focus,
.ff input:focus,
.ff select:focus,
.ff textarea:focus,
.gen-form-field input:focus,
.gen-form-field select:focus,
.gen-form-field textarea:focus,
.gen-group-fields .ff input:focus,
.gen-group-fields .ff select:focus,
.gen-group-fields .ff textarea:focus,
.ff-inline input:focus,
.ff-inline select:focus,
.ff-inline textarea:focus,
.sselect-input:focus {
  border-color: var(--brand) !important;
  background: white !important;
  box-shadow: 0 0 0 2px rgba(31,95,159,.14), inset 0 1px 2px rgba(16,32,51,.04);
}

.f-lbl,
.ff label,
.gen-form-field label,
.gen-group-fields .ff label,
.ff-inline label {
  color: #334a65;
  letter-spacing: .2px;
}

.gen-form-card {
  overflow: hidden;
}

.gen-group-header {
  padding: 9px 14px;
  background: linear-gradient(180deg, #f4f7fb, #e9eff6);
  border-color: var(--border);
}

.gen-group-name {
  color: #263c55;
  letter-spacing: .6px;
}

.gen-group-fields .ff {
  padding: 11px 12px;
  background: #fff;
}

.gen-footer {
  background: linear-gradient(180deg, #f8fafc, #eef3f8);
}

.word-ribbon {
  min-height: 72px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #ffffff, #f3f7fb);
  border-bottom-color: var(--border2);
  box-shadow: var(--shadow-sm);
}

.ribbon-fname {
  color: #142238;
}

.ribbon-group {
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: var(--r3);
  background: rgba(255,255,255,.7);
}

.ribbon-sep {
  display: none;
}

.rb-btn {
  min-height: 28px;
  background: linear-gradient(180deg, #fff, #f3f6fa);
}

.rb-var,
.rb-save {
  color: var(--brand-d);
  background: #e9f2fb;
  border-color: var(--brand-b);
}

.editor-left {
  background: #dfe6ee;
}

.doc-paper,
.var-panel {
  border-color: var(--border2);
  box-shadow: 0 6px 28px rgba(16,32,51,.12);
}

.var-panel,
.vp-head,
.vp-foot {
  background: linear-gradient(180deg, #ffffff, #f7f9fc);
}

.vr,
.vp-item,
.review-data-row,
.edd-option-row,
.arr-row {
  background: #f8fafc;
  border-color: var(--border);
}

.var-chip,
.vr-key,
.m-key-val,
.dd-card-key,
.dd-card-key code,
.lib-tag,
.badge-blue {
  background: var(--brand-l);
  color: var(--brand-d);
}

.dropzone,
.bulk-dropzone {
  background:
    repeating-linear-gradient(135deg, rgba(31,95,159,.035) 0 8px, transparent 8px 16px),
    #ffffff;
  border-style: dashed;
}

.dropzone:hover,
.dropzone.over,
.bulk-dropzone:hover {
  background: #eef6fd;
}

.modal,
.preview-modal,
.bulk-modal,
.login-simple-card,
#change-pw-overlay > div {
  border: 1px solid var(--border2);
  border-radius: var(--r4) !important;
  box-shadow: var(--shadow-md);
}

.modal-title,
.preview-modal-title,
.bulk-modal-title,
.login-simple-heading {
  color: #142238;
  font-weight: 700;
}

.preview-modal-head,
.preview-modal-foot,
.bulk-modal-head,
.bulk-modal-foot {
  background: linear-gradient(180deg, #ffffff, #f5f8fb);
}

#login {
  background:
    radial-gradient(circle at 25% 15%, rgba(31,95,159,.12), transparent 34%),
    linear-gradient(180deg, #f8fafc, #e8eef5);
}

.login-simple-wrap {
  max-width: 390px;
}

.login-simple-logo {
  justify-content: center;
  margin-bottom: 22px;
}

.login-simple-name {
  color: #142238;
  font-weight: 800;
}

.login-simple-card {
  padding: 26px;
}

#toasts {
  right: 14px;
  bottom: 14px;
}

.toast {
  border-radius: var(--r3);
  box-shadow: var(--shadow-md);
}

@media (max-width: 900px) {
  :root { --topbar-h: 52px; }

  .mobile-header {
    display: flex;
    background: #142238;
    border-bottom: 1px solid #0f2034;
  }

  .mobile-header .tb-name {
    color: white;
  }

  .mobile-header .brand-lockup {
    height: 32px;
  }

  .mobile-header .brand-mark {
    width: 30px;
    height: 30px;
  }

  .mobile-header .brand-name {
    font-size: 17px;
  }

  .mobile-header .brand-subtitle {
    display: none;
  }

  .mobile-header .tb-name::after {
    display: none;
  }

  .btn-menu span {
    background: white;
  }

  .topbar {
    position: fixed;
    top: 52px;
    left: 0;
    width: 260px;
    height: calc(100vh - 52px);
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-right: 1px solid var(--border2);
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 200;
  }

  .topbar.open {
    transform: translateX(0);
  }

  .topbar .tb-brand {
    display: none;
  }

  .tb-nav {
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
  }

  .tb-btn {
    width: 100%;
    min-width: 0;
    height: 40px;
    flex-direction: row;
    justify-content: flex-start;
    text-align: left;
  }

  .sb-divider {
    width: auto;
    height: 1px;
    margin: 5px 0;
  }

  .tb-right {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .api-chip {
    color: var(--ink3);
    justify-self: auto;
  }

  .sidebar-user {
    align-self: auto;
    justify-content: space-between;
  }

  .sidebar-scrim {
    display: block;
  }

  .sidebar-scrim.on {
    opacity: 1;
    pointer-events: auto;
  }

  .app-body {
    margin-top: 52px;
    height: calc(100vh - 52px);
  }
}

@media (max-width: 640px) {
  .dash-greeting,
  .gen-top-bar,
  .lib-head,
  #page-dropdowns .page-scroll > div > div:first-child,
  #page-users .page-scroll > div > div:first-child {
    align-items: stretch;
    flex-direction: column;
  }

  .dash-stats {
    grid-template-columns: 1fr;
  }

  .tpl-card-grid,
  .tpl-picker-grid,
  .lib-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 481px) and (max-width: 900px) {
  :root { --topbar-h: 108px; }

  .mobile-header {
    display: none;
  }

  .btn-menu {
    display: none;
  }

  .topbar {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    min-width: 0;
    height: var(--topbar-h);
    min-height: var(--topbar-h);
    transform: none;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: 38px 70px;
    background: linear-gradient(180deg, #142238 0 38px, #ffffff 38px 100%);
    border-right: 0;
    border-bottom: 1px solid var(--border2);
    overflow: visible;
  }

  .topbar .tb-brand {
    display: flex;
    grid-column: 1;
    grid-row: 1;
    height: 38px;
    padding: 0 16px;
    background: transparent;
  }

  .tb-nav {
    grid-column: 1 / 3;
    grid-row: 2;
    flex-direction: row;
    align-items: stretch;
    gap: 4px;
    padding: 9px 12px 10px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .tb-btn {
    width: auto;
    min-width: 86px;
    height: 50px;
    flex-direction: column;
    justify-content: center;
    text-align: center;
  }

  .sb-divider {
    width: 1px;
    height: 42px;
    margin: 4px;
  }

  .tb-right {
    grid-column: 3;
    grid-row: 1 / 3;
    min-width: 220px;
    display: grid;
    grid-template-rows: 26px 1fr;
    align-items: center;
    background: transparent;
    border-top: 0;
    border-left: 1px solid rgba(255,255,255,.08);
  }

  .api-chip {
    color: #d7e5f6;
    justify-self: end;
  }

  .sidebar-user {
    align-self: end;
    justify-content: flex-end;
  }

  .sidebar-scrim,
  .sidebar-scrim.on {
    display: none;
    opacity: 0;
    pointer-events: none;
  }

  .app-body {
    margin-top: 0;
    height: calc(100vh - var(--topbar-h) - 2px);
  }
}

.tpl-card-body {
  overflow: visible;
}

.tpl-card-top {
  display: grid;
  grid-template-columns: auto max-content;
  align-items: start;
  gap: 8px;
}

.tpl-card-edit-btn {
  width: auto !important;
  min-width: 42px;
  height: 26px !important;
  padding: 3px 10px !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  line-height: 1;
  white-space: nowrap;
  overflow: visible;
}
