/* Design tokens. Colors are the client's real brand (Arnoldo Wiens / AGE), extracted from
   their official brand guide: pure flat red/blue/black/white, no tints in the source marks.
   --brand-strong/-soft are derived shades for hover/tint states the guide doesn't define. */
:root {
  --brand: #ff0000;
  --brand-strong: #d60000;
  --brand-soft: #ffe5e5;

  --brand-accent: #0000ff;
  --brand-accent-soft: #e5e5ff;

  --font-display: "Archivo Black", "Franklin Gothic Heavy", Impact, sans-serif;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #171a1f;
  --text-muted: #656e7d;

  --ok: #16794a;
  --ok-soft: #e6f4ed;
  --warn: #9a5b00;
  --warn-soft: #fdf1dd;
  --bad: #b3261e;
  --bad-soft: #fdecea;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --sidebar: 248px;

  /* CodeMirror token colors (escritos editor). Chosen per-theme, not reused straight
     from --brand-accent: pure #0000ff text on the dark theme's near-black pill
     background is ~1.7:1 contrast (unreadable) even though the same pair is ~11:1 on
     the light background — every token below is picked for >=4.5:1 against this
     theme's own --surface-2 (the editor's background). */
  --cm-keyword: #7c3aed;
  --cm-string: #047857;
  --cm-comment: #475569;
  --cm-number: #b45309;
  --cm-atom: #1d4ed8;
  --cm-attribute: #0369a1;
  --cm-builtin: #be123c;
  --cm-property: #0f766e;
  --cm-error: #b3261e;
  --cm-pill-bg: var(--brand-accent-soft);
  --cm-pill-fg: #3730a3;
}

/* Dark palette, declared once and applied from two places:
   1. the system preference, unless the user explicitly chose light
   2. an explicit data-theme="dark" from the sidebar toggle
   Both selectors are required. With only the media query, forcing dark on a machine whose
   system preference is light does nothing at all. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-strong: #ff3333;
    --bg: #000000;
    --surface: #0f0f0f;
    --surface-2: #1a1a1a;
    --border: #262626;
    --text: #ffffff;
    --text-muted: #a3a3a3;
    --brand-soft: #331010;
    --brand-accent-soft: #10102a;
    --ok-soft: #12261d;
    --warn-soft: #2a2010;
    --bad-soft: #2d1614;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    --cm-keyword: #c084fc;
    --cm-string: #34d399;
    --cm-comment: #94a3b8;
    --cm-number: #fbbf24;
    --cm-atom: #60a5fa;
    --cm-attribute: #38bdf8;
    --cm-builtin: #fb7185;
    --cm-property: #2dd4bf;
    --cm-error: #ff6b6b;
    --cm-pill-fg: #c7d2fe;
  }
}

:root[data-theme="dark"] {
  --brand-strong: #ff3333;
  --bg: #000000;
  --surface: #0f0f0f;
  --surface-2: #1a1a1a;
  --border: #262626;
  --text: #ffffff;
  --text-muted: #a3a3a3;
  --brand-soft: #331010;
  --brand-accent-soft: #10102a;
  --ok-soft: #12261d;
  --warn-soft: #2a2010;
  --bad-soft: #2d1614;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  --cm-keyword: #c084fc;
  --cm-string: #34d399;
  --cm-comment: #94a3b8;
  --cm-number: #fbbf24;
  --cm-atom: #60a5fa;
  --cm-attribute: #38bdf8;
  --cm-builtin: #fb7185;
  --cm-property: #2dd4bf;
  --cm-error: #ff6b6b;
  --cm-pill-fg: #c7d2fe;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-name { font-family: var(--font-display); font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); padding: 12px 8px 4px;
}
.nav a {
  display: block; padding: 8px 10px; border-radius: 8px;
  text-decoration: none; color: var(--text-muted); font-size: 14px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.is-active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 550; }

.sidebar-foot {
  margin-top: auto; font-size: 13px; color: var(--text-muted); padding: 0 8px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
}
.tema-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); font: inherit; font-size: 13px;
}
.tema-toggle:hover { color: var(--text); border-color: var(--text-muted); }
.tema-icon { font-size: 14px; line-height: 1; }
.usuario { font-size: 13px; }
.salir {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--brand-strong); font: inherit; font-weight: 600; font-size: 13px;
}

.breadcrumb {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; color: var(--text-muted); margin-bottom: 14px;
}
.breadcrumb i { font-style: normal; opacity: .5; }
.breadcrumb-clear { color: var(--brand-strong); text-decoration: none; font-weight: 550; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

.main { padding: 24px 28px 56px; min-width: 0; }

.page-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-title { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.02em; }
.page-sub { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }

/* ---------- cards / stats ---------- */
.stat-row {
  display: grid; gap: 12px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted);
}
.stat-value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card-head {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-title { font-weight: 600; font-size: 14px; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--text-muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 600; text-align: left;
  padding: 9px 12px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px 16px; text-align: center; color: var(--text-muted); }

/* ---------- bits ---------- */
.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.chip-mute { background: var(--surface-2); color: var(--text-muted); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.filters a {
  padding: 6px 12px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface);
  text-decoration: none; color: var(--text-muted);
}
.filters a:hover { border-color: var(--text-muted); color: var(--text); }
.filters a.is-active {
  background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 550;
}

.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--ok); }

.pager { display: flex; gap: 8px; align-items: center; padding: 12px 16px; font-size: 13px; }
.pager a { text-decoration: none; color: var(--brand-strong); font-weight: 550; }

.note {
  border-left: 3px solid var(--warn); background: var(--warn-soft); color: var(--warn);
  padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 13px; margin-bottom: 20px;
}

/* ---------- auth ---------- */
/* Decorative diagonal red/blue bands bleeding off the corners, per the AW brand guide's
   flag-star motif. Pure CSS clip-path so no extra image assets are needed. */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  position: relative; overflow: hidden; background: var(--bg);
}
.auth::before, .auth::after {
  content: ""; position: absolute; width: 46vmax; height: 46vmax; z-index: 0;
}
.auth::before {
  top: -18vmax; left: -18vmax; background: var(--brand);
  clip-path: polygon(0 0, 100% 0, 0 100%);
  opacity: .95;
}
.auth::after {
  bottom: -18vmax; right: -18vmax; background: var(--brand-accent);
  clip-path: polygon(100% 100%, 0 100%, 100% 0);
  opacity: .95;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 32px;
  position: relative; z-index: 1;
}
.auth-logo { display: block; height: 56px; margin: 0 auto 14px; }
.field-icon-wrap { position: relative; }
.field-icon-wrap svg {
  position: absolute; left: 12px; top: 50%; translate: 0 -50%;
  width: 16px; height: 16px; color: var(--text-muted); pointer-events: none;
}
.field .field-icon-wrap input,
.field .field-icon-wrap input[type] { padding-left: 36px; }
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 13px; font-weight: 550; margin-bottom: 6px;
}
.field input {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.btn {
  width: 100%; padding: 10px 14px; font-size: 14px; font-weight: 600;
  border: 0; border-radius: 8px; background: var(--brand); color: #fff; cursor: pointer;
}
.btn:hover { background: var(--brand-strong); }
.errors { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 8px;
  font-size: 13px; margin-bottom: 16px; }

/* ---------- forms / CRUD ---------- */
/* Standalone .form-select/.form-input: `.field select`/`.field input` below already
   style every FIELD-wrapped widget (via partials/campo.html), but a few controls are
   deliberately NOT field-wrapped — e.g. the preview toolbar's distrito selector — and
   were relying on these classes existing with no rule backing them, so they rendered
   as an unstyled native control (white background even in dark mode). */
.form-select, .form-input {
  padding: 8px 11px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-family: inherit;
}
.form-select:focus, .form-input:focus {
  outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent;
}

.form-grid { display: flex; flex-direction: column; gap: 16px; max-width: 1100px; }
.card-body { padding: 16px; }
.card-hint { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.cols-3 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.cols-4 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.field .req { color: var(--brand); }
.field select,
.field textarea,
.field input[type="text"],
.field input[type="number"],
.field input[type="search"],
.field input[type="file"] {
  width: 100%; padding: 9px 11px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-family: inherit;
}
.field textarea { min-height: 76px; resize: vertical; }
.field textarea.code-area {
  font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 12.5px; min-height: 140px;
}
.field select:focus, .field textarea:focus, .field input:focus {
  outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent;
}
.field.has-error select, .field.has-error input, .field.has-error textarea { border-color: var(--bad); }
.field-error { color: var(--bad); font-size: 12px; margin: 4px 0 0; }
.help { color: var(--text-muted); font-size: 12px; margin: 4px 0 0; }

.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn-inline { width: auto; padding: 9px 18px; }
.btn-ghost {
  padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 550;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); text-decoration: none; cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn-danger {
  padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 550;
  color: var(--bad); text-decoration: none; margin-left: auto;
}
.btn-danger:hover { background: var(--bad-soft); }
.btn-danger-solid {
  padding: 9px 18px; border: 0; border-radius: 8px; font-size: 14px; font-weight: 600;
  background: var(--bad); color: #fff; cursor: pointer;
}

.head-actions { display: flex; gap: 8px; align-items: center; }

.searchbar { display: flex; gap: 8px; margin-bottom: 14px; max-width: 560px; }
.searchbar input {
  flex: 1; padding: 9px 12px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
.searchbar input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.row-actions { display: flex; gap: 10px; }
.row-actions a { font-size: 13px; font-weight: 550; color: var(--brand-strong); text-decoration: none; }
.row-actions a.danger { color: var(--text-muted); }
.row-actions a.danger:hover { color: var(--bad); }

.flash {
  padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px;
  border-left: 3px solid;
}
.flash-success { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.flash-error { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.flash-info { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center;
    overflow-x: auto; gap: 16px; }
  .sidebar-foot, .nav-label { display: none; }
  .nav { flex-direction: row; }
  .main { padding: 16px; }
}

/* ---------- escritos editor / generar: split editor + live paper preview ---------- */

.editor-shell {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start;
}

.editor-pane, .preview-pane { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.ajustes {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 4px 4px;
}
.ajustes > summary {
  cursor: pointer; list-style: none; padding: 10px 12px; font-size: 13px;
  color: var(--text-muted); font-weight: 550; user-select: none;
}
.ajustes > summary::-webkit-details-marker { display: none; }
.ajustes > summary::before { content: "▸ "; }
.ajustes[open] > summary::before { content: "▾ "; }
.ajustes-body {
  padding: 4px 12px 14px; display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab-btn {
  padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13px;
  color: var(--text-muted); font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tab-panel[hidden] { display: none; }
.tab-panel { display: flex; flex-direction: column; gap: 10px; }

.chip-toolbar {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px;
}
.chip-toolbar-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
}
.chip-group { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.chip-group-label { font-size: 11px; text-transform: uppercase; color: var(--text-muted); width: 74px; flex: 0 0 auto; }
.chip-group-empty { font-size: 12px; color: var(--text-muted); font-style: italic; }
.var-chip {
  font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 12px; padding: 4px 9px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; color: var(--text);
}
.var-chip:hover { background: var(--brand-accent-soft); border-color: var(--brand-accent); }

/* CodeMirror host + a small custom theme built from the app's own tokens (no theme
   package pulled in) so it follows light/dark/system like everything else. */
.CodeMirror {
  border: 1px solid var(--border); border-radius: 8px;
  height: 360px; font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5;
}
.cm-s-age.CodeMirror { background: var(--surface-2); color: var(--text); }
.cm-s-age .CodeMirror-gutters { background: var(--surface-2); border-right: 1px solid var(--border); }
.cm-s-age .CodeMirror-linenumber { color: var(--text-muted); }
.cm-s-age .CodeMirror-cursor { border-left: 1px solid var(--text); }
/* Full token coverage for the html/xml/javascript/css/django modes stacked under
   "django" mode (htmlmixed's tags/attributes + django's own overlay for {{ }}/{% %}/
   {# #} + filter and tag-name keywords). Every rule below targets a real class the
   vendored modes emit (verified against static/vendor/codemirror/mode/*/*.js) — an
   unstyled token silently falls back to codemirror.css's fixed light-theme hexes,
   which is what made a lone "|upper" filter render near-invisible on the dark theme
   (a "keyword" token no rule here used to override, at ~1.7:1 the same class of bug
   this whole block exists to prevent for every other token too).
   {{ }}/{% %} content itself is highlighted as a solid pill (background + high-
   contrast --cm-pill-fg per theme) so it reads at a glance against plain HTML/prose,
   matching the design; everything else gets a plain per-theme token color. */
.cm-s-age .cm-tag, .cm-s-age .cm-bracket { color: var(--text-muted); }
.cm-s-age .cm-attribute { color: var(--cm-attribute); }
.cm-s-age .cm-string, .cm-s-age .cm-string-2 { color: var(--cm-string); }
.cm-s-age .cm-comment { color: var(--cm-comment); font-style: italic; }
.cm-s-age .cm-number { color: var(--cm-number); }
.cm-s-age .cm-atom { color: var(--cm-atom); }
.cm-s-age .cm-builtin, .cm-s-age .cm-qualifier { color: var(--cm-builtin); }
.cm-s-age .cm-property { color: var(--cm-property); }
.cm-s-age .cm-def, .cm-s-age .cm-type { color: var(--cm-number); font-weight: 600; }
.cm-s-age .cm-variable, .cm-s-age .cm-variable-3 { color: var(--text); }
.cm-s-age .cm-operator, .cm-s-age .cm-punctuation { color: var(--text); }
.cm-s-age .cm-error {
  color: var(--cm-error); text-decoration: underline wavy var(--cm-error);
}
.cm-s-age .cm-keyword, .cm-s-age .cm-django-tag, .cm-s-age .cm-variable-2, .cm-s-age .cm-meta {
  background: var(--cm-pill-bg); color: var(--cm-pill-fg); font-weight: 600;
  border-radius: 4px; padding: 0 2px;
}

.campos-editor { display: flex; flex-direction: column; gap: 12px; }
.campos-table input, .campos-table select {
  width: 100%; padding: 6px 8px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
.campos-table td { vertical-align: middle; }
.campos-table .col-requerido { text-align: center; }
.btn-remove {
  background: none; border: 0; color: var(--text-muted); cursor: pointer; font-size: 15px;
  padding: 4px 8px; border-radius: 6px;
}
.btn-remove:hover { color: var(--bad); background: var(--bad-soft); }

.preview-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.preview-toolbar-title { font-weight: 600; font-size: 14px; }
.preview-toolbar-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.preview-status { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--ok); display: inline-block; }
.status-dot.is-updating { background: var(--warn); }
.status-dot.is-error { background: var(--bad); }
.preview-error-banner {
  border: 1px solid var(--bad); background: var(--bad-soft); color: var(--bad);
  padding: 10px 14px; border-radius: 8px; font-size: 13px;
}
.preview-error-banner p { margin: 4px 0 0; opacity: .85; }
.preview-frame-wrap {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2);
  overflow: auto; min-height: 60vh; max-height: 78vh;
  display: flex; justify-content: center; align-items: flex-start; padding: 16px;
}
.preview-frame-wrap iframe {
  background: #fff; border: 0; width: 21cm; height: 29.7cm; flex: none;
  box-shadow: 0 1px 8px rgba(0, 0, 0, .15);
  /* `zoom` (not `transform: scale`) so the shrunk box actually reserves less layout
     space — a scaled-down transform still occupies its full unscaled height, leaving a
     tall blank gap under the visibly smaller sheet. The fraction itself is computed and
     kept in sync with the pane's actual width by static/js/preview_zoom.js — a fixed
     fraction here fit the wide editor/generar panes but clipped the narrower
     expedientes preview column, so no default is set here at all. */
}
.preview-frame-wrap.oficio iframe { width: 210mm; height: 330mm; }

.editor-footer {
  position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: 14px 20px; margin: 20px -20px 0; z-index: 5;
}

@media (max-width: 1100px) {
  .editor-shell { grid-template-columns: 1fr; }
  .preview-frame-wrap { min-height: 480px; }
}

/* ---------- expedientes selector: alcance + 13-card grid + focused preview ---------- */

.selector-shell {
  display: grid; grid-template-columns: 300px 1fr 340px; gap: 20px; align-items: start;
}
.selector-alcance, .selector-formularios { display: flex; flex-direction: column; gap: 0; min-width: 0; }

.segmented { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented-opt {
  flex: 1; text-align: center; padding: 9px 0; cursor: pointer; font-size: 14px; font-weight: 600;
  color: var(--text-muted); background: var(--surface); border-right: 1px solid var(--border);
  position: relative;
}
.segmented-opt:last-child { border-right: 0; }
.segmented-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented-opt:has(input:checked) { background: var(--brand); color: #fff; }
.segmented-opt:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: -2px; }

.formularios-grid {
  display: grid; gap: 12px; margin-top: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.form-card {
  display: flex; flex-direction: column; gap: 6px; padding: 10px;
  border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; position: relative;
}
.form-card input[type="checkbox"] { position: absolute; top: 8px; left: 8px; width: 16px; height: 16px; accent-color: var(--brand); }
.form-card:has(input:checked) { border-color: var(--brand); }
.form-card-thumb {
  height: 76px; border-radius: 6px; background: var(--surface-2); position: relative;
  display: flex; align-items: center; justify-content: center;
}
.form-card-lines {
  width: 70%; height: 60%;
  background-image: repeating-linear-gradient(var(--border), var(--border) 3px, transparent 3px, transparent 9px);
  opacity: .8;
}
.form-card-page-badge {
  position: absolute; top: 6px; right: 6px; font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 999px; background: var(--surface); color: var(--text-muted);
  border: 1px solid var(--border);
}
.form-card-title { font-size: 12.5px; font-weight: 550; line-height: 1.3; }
.form-card:hover { border-color: var(--text-muted); }
.form-card.is-focused { box-shadow: 0 0 0 2px var(--brand-accent); }

@media (max-width: 1300px) {
  .selector-shell { grid-template-columns: 260px 1fr; }
  .preview-pane { grid-column: 1 / -1; }
}
@media (max-width: 1100px) {
  .selector-shell { grid-template-columns: 1fr; }
}
