/* Codex. Loads after bico-theme.css and owns everything under /codex. */

/* ---- page-type stripes, reusing the shared source palette ---- */
.stripe.article  { background: var(--gold); }
.stripe.document { background: var(--src-poi); }
.stripe.media    { background: var(--src-ship); }

/* ---- sub-navigation under the site shell ---- */
.cdx-subnav {
  display: flex;
  align-items: center;
  gap: var(--gap-xs);
  flex-wrap: wrap;
  margin-bottom: var(--gap-md);
  padding-bottom: var(--pad-sm);
  border-bottom: 1px solid var(--border);
}
.cdx-subnav-spacer { flex: 1; min-width: 0; }
.cdx-subnav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
}
.cdx-subnav a:hover { color: var(--text-primary); background: var(--surface-2); text-decoration: none; }
.cdx-subnav a[aria-current='page'] { color: var(--gold); border-color: var(--border-strong); background: var(--surface-2); }
.cdx-subnav-cta { color: var(--gold) !important; border-color: var(--gold-soft) !important; }
.cdx-subnav-you { font-weight: 500; }

/* ---- admin bar ---- */
.cdx-adminbar {
  position: sticky;
  top: 56px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
  background: #241c15;
  border-bottom: 1px solid var(--bar-gold);
  padding: 6px 22px;
  font-size: 13px;
}
.cdx-adminbar-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--bar-gold);
  font-weight: 500;
  letter-spacing: 0.8px;
  margin-right: 10px;
  white-space: nowrap;
}
.cdx-adminbar a {
  color: #c9bda4;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.cdx-adminbar a:hover { background: rgba(217, 169, 76, 0.18); color: var(--bar-gold); text-decoration: none; }
.cdx-adminbar a.active { background: var(--bar-gold); color: #241c15; font-weight: 500; }
.cdx-adminbar-new { margin-left: auto; color: var(--bar-gold) !important; border: 1px solid #4d4132; }

/* ---- welcome banner ---- */
.cdx-welcome {
  text-align: center;
  padding: var(--pad-lg) var(--pad-lg) var(--pad-md);
  margin-bottom: var(--gap-md);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.cdx-welcome h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 26px;
  color: var(--text-primary);
  margin: 0 0 8px;
}
.cdx-welcome p {
  font-family: var(--font-prose);
  color: var(--text-secondary);
  margin: 0 auto 6px;
  max-width: 62ch;
  font-size: 16px;
}
.cdx-welcome-stats { font-size: 13px; color: var(--text-muted); }
.cdx-welcome-stats strong { color: var(--gold); font-weight: 500; }

/* ---- search ---- */
.cdx-search { display: flex; gap: var(--gap-sm); margin-bottom: var(--gap-md); }
.cdx-search input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  color: var(--text-primary);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 18px;
}
.cdx-search input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-wash);
}
.cdx-search button {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  color: #1c150f;
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: var(--radius-pill);
  padding: 9px 22px;
  cursor: pointer;
}
.cdx-search button:hover { background: var(--gold-soft); border-color: var(--gold-soft); }

.cdx-heading {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--text-eyebrow);
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
  margin: var(--gap-lg) 0 var(--gap-sm);
}
.cdx-result-head {
  font-family: var(--font-prose);
  color: var(--text-secondary);
  margin-bottom: var(--gap-md);
}
.cdx-result-head a { color: var(--gold); }

/* ---- portal ---- */
.cdx-portal {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: var(--gap-md);
  margin: var(--gap-md) 0 var(--gap-sm);
  align-items: start;
}
.cdx-portal-col { display: flex; flex-direction: column; gap: var(--gap-md); }

.cdx-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
}
.cdx-panel-head {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16px;
  color: var(--text-primary);
  background: var(--surface-3);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.cdx-panel-body {
  padding: var(--pad-md) var(--pad-lg);
  font-family: var(--font-prose);
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.65;
}
.cdx-panel-body p { margin: 0; }
.cdx-panel-body a { color: var(--gold); font-weight: 500; }
.cdx-panel-more { display: inline-block; margin-top: 6px; white-space: nowrap; font-family: var(--font-ui); font-size: 14px; }

.cdx-feat-img {
  float: left;
  width: 150px;
  max-width: 42%;
  margin: 2px 16px 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.cdx-feat-title {
  display: block;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.cdx-feat-title:hover { color: var(--gold); text-decoration: none; }
.cdx-feat-text { color: var(--text-secondary); }

.cdx-dyk-list, .cdx-news-list, .cdx-cat-list { list-style: none; margin: 0 0 8px; padding: 0; }
.cdx-dyk-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.cdx-dyk-list li:last-child, .cdx-news-list li:last-child, .cdx-cat-list li:last-child { border-bottom: 0; }
.cdx-news-list li { display: flex; align-items: baseline; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cdx-news-list a { flex: 1; }
.cdx-news-when { color: var(--text-muted); font-size: 12px; white-space: nowrap; font-family: var(--font-ui); }
.cdx-cat-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.cdx-cat-list span { color: var(--text-muted); font-size: 12px; font-family: var(--font-ui); font-variant-numeric: tabular-nums; }

.cdx-account {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  flex-wrap: wrap;
  justify-content: space-between;
  padding: var(--pad-md) var(--pad-lg);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--gold-wash);
}
.cdx-portal .cdx-account { margin: 0; }
.cdx-account-text { font-family: var(--font-prose); color: var(--text-secondary); font-size: 16px; max-width: 60ch; }
.cdx-account-text strong { display: block; font-family: var(--font-display); color: var(--text-primary); font-size: 18px; font-weight: 500; margin-bottom: 2px; }
.cdx-account-actions { display: flex; gap: var(--gap-sm); flex-wrap: wrap; }

@media (max-width: 760px) {
  .cdx-portal { grid-template-columns: 1fr; }
}

/* ---- buttons ---- */
.cdx-btn {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  color: #1c150f;
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 9px 18px;
  cursor: pointer;
}
.cdx-btn:hover { background: var(--gold-soft); border-color: var(--gold-soft); text-decoration: none; }
.cdx-btn.ghost { background: transparent; color: var(--text-primary); border-color: var(--border-strong); }
.cdx-btn.ghost:hover { background: var(--surface-3); border-color: var(--gold-soft); }

.cdx-mini-btn {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  cursor: pointer;
}
.cdx-mini-btn:hover { border-color: var(--gold-soft); }
.cdx-mini-btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.cdx-mini-btn.danger:hover { background: var(--danger); color: var(--surface-3); }

/* ---- article reading ---- */
.codex-page, .codex-missing {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--pad-xl) 40px var(--pad-lg);
}
.codex-page .article-title {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--text-primary);
  -webkit-text-fill-color: var(--text-primary);
  font-size: clamp(27px, 4vw, 40px);
  line-height: 1.15;
  letter-spacing: normal;
  text-transform: none;
  text-shadow: none;
  margin: 0 0 6px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.article-meta {
  font-family: var(--font-ui);
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  margin: 0 0 22px;
}

.codex-body {
  font-family: var(--font-prose);
  color: var(--text-secondary);
  font-size: 17px;
  line-height: 1.78;
}
.codex-body > :first-child { margin-top: 0; }
.codex-body p, .codex-body li, .codex-body td, .codex-body th {
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: normal;
  font-size: inherit;
}
.codex-body p { margin: 0 0 1.05em; }
.codex-body h1, .codex-body h2, .codex-body h3, .codex-body h4 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--text-primary);
  -webkit-text-fill-color: var(--text-primary);
  text-shadow: none;
  text-transform: none;
  letter-spacing: normal;
  line-height: 1.25;
  margin: 1.6em 0 0.5em;
}
.codex-body h1 { font-size: 28px; border-bottom: 1px solid var(--rule); padding-bottom: 7px; }
.codex-body h2 { font-size: 23px; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.codex-body h3 { font-size: 19px; }
.codex-body a { color: var(--gold); border-bottom: 1px solid var(--gold-wash); }
.codex-body a:hover { border-bottom-color: var(--gold); text-decoration: none; }
.codex-body a.redlink { color: var(--danger); border-bottom-color: transparent; }
.codex-body ul, .codex-body ol { margin: 0 0 1.05em; padding-left: 1.6em; }
.codex-body li { margin: 0.3em 0; }
.codex-body blockquote {
  margin: 1.2em 0;
  padding: 0.4em 1.2em;
  border-left: 3px solid var(--gold-soft);
  color: var(--text-muted);
  font-style: italic;
}
.codex-body code {
  background: var(--gold-wash);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
.codex-body pre {
  background: #241c15;
  color: #e8ddc6;
  padding: 14px 16px;
  border-radius: var(--radius);
  overflow: auto;
  margin: 1.2em 0;
}
.codex-body pre code { background: none; color: inherit; padding: 0; }
.codex-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.8em 0; }
.codex-body img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.codex-body table { border-collapse: collapse; margin: 1.2em 0; width: 100%; }
.codex-body th, .codex-body td { border: 1px solid var(--border); padding: 8px 11px; }
.codex-body th { background: var(--surface-3); color: var(--text-primary); font-weight: 500; }

.codex-missing h1 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--text-primary);
  -webkit-text-fill-color: var(--text-primary);
  font-size: clamp(25px, 4vw, 36px);
  margin: 0 0 12px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 10px;
}
.codex-missing p { font-family: var(--font-prose); color: var(--text-secondary); text-transform: none; letter-spacing: normal; font-size: 17px; }

.codex-cats-bar {
  margin-top: 26px;
  padding-top: var(--pad-md);
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-xs);
  align-items: center;
}
.codex-cats-bar .label {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-eyebrow);
  margin-right: 4px;
}
.codex-cats-bar a {
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.codex-cats-bar a:hover { border-color: var(--gold-soft); color: var(--gold); text-decoration: none; }

.codex-backlinks {
  margin-top: 24px;
  padding: var(--pad-md) var(--pad-lg);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.codex-backlinks h2 {
  font-family: var(--font-ui);
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--text-eyebrow);
  border: 0;
}
.codex-backlinks ul { margin: 0; padding-left: 18px; font-family: var(--font-prose); }
.codex-backlinks a { color: var(--gold); }
.codex-actions { margin-top: 20px; font-family: var(--font-ui); }
.codex-actions a { color: var(--gold); }
.codex-note { color: var(--text-muted); font-style: italic; }
.codex-history-link { color: var(--gold); }

/* ---- infobox ---- */
.codex-infobox {
  float: right;
  width: 300px;
  max-width: 42%;
  margin: 4px 0 20px 24px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-primary);
}
.codex-infobox.box-left  { float: left;  margin: 4px 24px 20px 0; }
.codex-infobox.box-right { float: right; margin: 4px 0 20px 24px; }
.codex-infobox.box-wide  { float: none; clear: both; width: 100%; max-width: none; margin: 8px 0 22px; }
.ib-title {
  font-family: var(--font-display);
  background: #241c15;
  color: var(--bar-gold);
  -webkit-text-fill-color: var(--bar-gold);
  text-align: center;
  font-weight: 500;
  padding: 9px 12px;
  font-size: 15px;
  letter-spacing: 0.5px;
}
.ib-figure { margin: 0; }
.ib-figure img { width: 100%; display: block; }
.ib-figure figcaption {
  padding: 6px 10px;
  font-size: 12px;
  font-style: italic;
  color: var(--text-muted);
  text-align: center;
  background: var(--surface-2);
}
.ib-rows { width: 100%; border-collapse: collapse; }
.ib-rows th, .ib-rows td {
  padding: 7px 10px;
  vertical-align: top;
  text-align: left;
  border-top: 1px solid var(--border);
  line-height: 1.45;
}
.ib-rows th { width: 38%; color: var(--text-muted); font-weight: 500; }
.ib-rows td { color: var(--text-primary); }
.ib-head th {
  background: var(--gold-wash);
  text-align: center;
  color: var(--text-primary);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 1.2px;
  width: auto;
}
.ib-full { text-align: center; font-style: italic; color: var(--text-muted); }
.ib-rows a { color: var(--gold); }

.codex-holdings, .codex-cats-bar, .codex-backlinks { clear: both; }

@media (max-width: 680px) {
  .codex-infobox,
  .codex-infobox.box-left,
  .codex-infobox.box-right,
  .codex-infobox.box-wide { float: none; width: auto; max-width: none; margin: 4px 0 18px; }
  .codex-page, .codex-missing { padding: var(--pad-lg) var(--pad-md); }
}

/* ---- live holdings panel ---- */
.codex-holdings {
  margin: 28px 0 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
}
.codex-holdings-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 18px;
  background: #241c15;
  border-bottom: 1px solid var(--border);
}
.codex-holdings-head h2 {
  font-family: var(--font-display);
  margin: 0;
  color: var(--bar-gold);
  -webkit-text-fill-color: var(--bar-gold);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: none;
}
.codex-holdings-live { color: #a1937a; font-style: italic; font-size: 12px; }
.codex-holdings-body { padding: var(--pad-md) var(--pad-lg) var(--pad-lg); }
.codex-holdings-status { color: var(--text-muted); font-style: italic; padding: 6px 0; }
.codex-holdings-status.muted { color: var(--text-muted); }

.ch-group { margin-bottom: 18px; }
.ch-group:last-child { margin-bottom: 0; }
.ch-group h3 {
  font-family: var(--font-ui);
  margin: 0 0 9px;
  color: var(--text-eyebrow);
  -webkit-text-fill-color: var(--text-eyebrow);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
}
.ch-count {
  display: inline-block;
  min-width: 18px;
  text-align: center;
  margin-left: 6px;
  background: var(--gold);
  color: #1c150f;
  border-radius: var(--radius-pill);
  font-size: 11px;
  padding: 0 7px;
  vertical-align: middle;
}
.ch-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--gap-sm); }
.ch-item {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
}
.ch-name { font-weight: 500; color: var(--text-primary); font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ch-badge {
  background: var(--src-mage);
  color: var(--surface-3);
  border-radius: var(--radius-sm);
  font-size: 10px;
  padding: 1px 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}
.ch-loc { margin-left: auto; color: var(--text-muted); font-size: 11px; }
.ch-facts { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; }
.ch-fact { color: var(--text-muted); font-size: 12px; }
.ch-fact b { color: var(--text-primary); font-weight: 500; }
.ch-tags { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 4px; }
.ch-tag { background: var(--gold-wash); color: var(--text-secondary); border-radius: var(--radius-sm); font-size: 11px; padding: 1px 7px; }
.ch-insight {
  margin-top: 8px;
  padding: 7px 11px;
  border-left: 3px solid var(--gold);
  background: var(--gold-wash);
  font-family: var(--font-prose);
  font-size: 14px;
  color: var(--text-secondary);
}

/* ---- forms: edit, auth, upload ---- */
.codex-edit, .cdx-auth, .cdx-upload, .review-item, .cdx-cat-block, .tpl-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--pad-lg) var(--pad-lg);
}
.codex-edit { display: grid; gap: var(--gap-md); }
.cdx-auth { max-width: 460px; margin: 0 auto; display: grid; gap: var(--gap-md); }
.cdx-upload { margin-bottom: var(--gap-md); }
.review-item { margin-bottom: var(--gap-md); }
.cdx-cat-block { margin-bottom: var(--gap-md); }
.tpl-card { margin: 0 0 var(--gap-md); }
.tpl-card.tpl-new { margin-top: var(--gap-lg); border-color: var(--gold-soft); }

.codex-edit label, .cdx-auth label {
  display: grid;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.codex-edit > label input, .codex-edit > label textarea,
.codex-edit > .cdx-cat-field input,
.cdx-auth input,
.cdx-upload-row input[type='text'],
.review-actions input,
.cdx-entity-row select, .cdx-entity-row input,
.cdx-ib-line, .cdx-ib-body,
.cdx-inline select, .cat-edit .cat-name, .cat-edit select,
.tpl-name, .tpl-cols textarea,
.cdx-link-input, .cdx-attach-name, .cdx-gallery-title, .cdx-box-place, .cdx-copy-input {
  width: 100%;
  box-sizing: border-box;
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
}
.codex-edit textarea, .tpl-cols textarea, .cdx-ib-body {
  font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.55;
}
.codex-edit input:focus, .codex-edit textarea:focus,
.cdx-auth input:focus, .cdx-link-input:focus, .tpl-name:focus, .tpl-cols textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-wash);
}
.codex-edit > button, .cdx-auth > button, .review-actions button, .cdx-attach-add button,
.cdx-gallery-add button, .cdx-gallery-new button {
  justify-self: start;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  color: #1c150f;
  background: var(--gold);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 9px 20px;
  cursor: pointer;
}
.codex-edit > button:hover, .cdx-auth > button:hover, .review-actions button:hover { background: var(--gold-soft); }
.review-actions button.danger, .cdx-mini-btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.review-actions button.danger:hover { background: var(--danger); color: var(--surface-3); }
.cdx-auth .alt { font-size: 14px; color: var(--text-muted); font-family: var(--font-prose); }
.cdx-auth .alt a { color: var(--gold); }
.cdx-upload-row { display: flex; gap: var(--gap-sm); flex-wrap: wrap; align-items: center; }
.cdx-upload-row input[type='file'] { flex: 0 0 auto; color: var(--text-secondary); }
.cdx-upload-row input[type='text'] { flex: 1 1 240px; width: auto; }
.cdx-inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.cdx-inline select { width: auto; padding: 5px 9px; font-size: 13px; }
.cdx-sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.cdx-you { font-size: 12px; color: var(--src-mage); font-weight: 500; }

.cdx-msg {
  font-family: var(--font-ui);
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left-width: 3px;
  background: var(--surface-2);
  color: var(--text-primary);
}
.cdx-msg.ok   { border-left-color: var(--ok); }
.cdx-msg.warn { border-left-color: var(--warn); }
.cdx-msg.err  { border-left-color: var(--danger); color: var(--danger); }

/* ---- tables ---- */
.cdx-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.cdx-table th, .cdx-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.cdx-table th {
  background: var(--surface-3);
  color: var(--text-eyebrow);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.4px;
}
.cdx-table tr:last-child td { border-bottom: 0; }
.cdx-table .nowrap { white-space: nowrap; color: var(--text-muted); font-size: 13px; }
.cdx-row-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.cdx-row-actions a { color: var(--gold); font-weight: 500; }

.badge-role, .badge-status {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
}
.badge-status.s-active, .badge-status.s-published { color: var(--ok); border-color: var(--ok); }
.badge-status.s-unverified, .badge-status.s-pending, .badge-status.s-draft { color: var(--warn); border-color: var(--warn); }
.badge-status.s-disabled, .badge-status.s-rejected { color: var(--danger); border-color: var(--danger); }

/* ---- browse ---- */
.cdx-breadcrumb { font-family: var(--font-ui); margin-bottom: var(--gap-md); color: var(--text-muted); font-size: 14px; }
.cdx-breadcrumb a { color: var(--gold); }
.cdx-breadcrumb .sep { opacity: 0.5; margin: 0 8px; }
.cdx-cat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: var(--gap-sm); }
.cdx-cat-name { font-family: var(--font-display); font-size: 22px; font-weight: 500; color: var(--text-primary); }
.cdx-cat-name a { color: inherit; }
.cdx-cat-name a:hover { color: var(--gold); text-decoration: none; }
.cdx-cat-total { font-family: var(--font-ui); font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 1.4px; color: var(--text-eyebrow); white-space: nowrap; }
.cdx-cat-block .cdx-grid { margin-bottom: 0; }

.cdx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--gap-sm); }
.cdx-tile {
  display: block;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  color: var(--text-primary);
}
.cdx-tile:hover { border-color: var(--gold-soft); text-decoration: none; }
.cdx-tile-name { font-family: var(--font-display); font-size: 16px; font-weight: 500; }
.cdx-tile-count { font-size: 12px; color: var(--text-muted); }

/* ---- categories picker ---- */
.cdx-cat-field { display: grid; gap: 8px; }
.cdx-cat-label { font-family: var(--font-ui); font-size: 13px; font-weight: 500; color: var(--text-muted); letter-spacing: 0.5px; }
.cdx-cats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px 16px;
  padding: var(--pad-md);
  border-radius: var(--radius);
  background: var(--surface-3);
  border: 1px solid var(--border);
}
.cdx-cats .cat-group { display: grid; gap: 4px; align-content: start; }
.cdx-cats label { display: flex; gap: 8px; align-items: center; color: var(--text-secondary); cursor: pointer; font-size: 14px; }
.cdx-cats .cat-parent { font-weight: 500; color: var(--text-primary); }
.cdx-cats .cat-child { padding-left: 18px; font-size: 13.5px; }
.cdx-cats input[type='checkbox'] { width: 16px; height: 16px; accent-color: var(--gold); }

.cat-admin { display: grid; gap: 6px; }
.cat-admin-child { margin-left: 26px; }
.cat-admin-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
}
.cat-reorder { display: flex; flex-direction: column; gap: 2px; }
.cat-reorder form { margin: 0; line-height: 1; }
.cat-reorder .cdx-mini-btn { padding: 0 8px; font-size: 12px; line-height: 1.6; }
.cat-edit { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 1 1 auto; margin: 0; }
.cat-edit .cat-name { width: auto; min-width: 160px; font-weight: 500; }
.cat-edit select { width: auto; }
.cat-meta code { background: var(--gold-wash); padding: 1px 6px; border-radius: var(--radius-sm); }
.cat-parentnote { font-style: italic; color: var(--text-muted); }
.cat-del { margin: 0; }

/* ---- EasyMDE ---- */
.EasyMDEContainer .CodeMirror {
  background: var(--surface-3);
  color: var(--text-primary);
  border-color: var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}
.EasyMDEContainer .CodeMirror-cursor { border-color: var(--text-primary); }
.editor-toolbar { background: var(--surface-2); border-color: var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.editor-toolbar button { color: var(--text-secondary) !important; border-color: transparent !important; }
.editor-toolbar button:hover, .editor-toolbar button.active { background: var(--gold-wash); border-color: var(--border) !important; }
.editor-toolbar i.separator { border-color: var(--border); }
.EasyMDEContainer .editor-toolbar:not(.fullscreen) { position: sticky; top: 56px; z-index: 60; }
body:has(.cdx-adminbar) .EasyMDEContainer .editor-toolbar:not(.fullscreen) { top: 90px; }
.editor-preview, .editor-preview-side { background: var(--surface-2); color: var(--text-secondary); font-family: var(--font-prose); }
.editor-preview a { color: var(--gold); }
.editor-toolbar .cdx-wikilink-btn::after { content: "\1F517"; font-size: 14px; line-height: 1; }

/* ---- editor: infobox cards ---- */
#cdxBoxesList { display: flex; flex-direction: column; gap: 10px; margin: 8px 0; }
.cdx-box-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 11px; background: var(--surface-3); }
.cdx-box-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.cdx-box-place { width: auto; padding: 5px 9px; font-size: 13px; }
.cdx-box-spacer { flex: 1; }
.cdx-box-head button {
  width: 30px; height: 30px; flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-secondary); cursor: pointer; line-height: 1;
}
.cdx-box-head .cdx-box-del { border-color: var(--danger); color: var(--danger); }
.cdx-box-head .cdx-box-del:hover { background: var(--danger); color: var(--surface-3); }
.cdx-box-add {
  margin-top: 6px; padding: 7px 15px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  background: transparent; color: var(--gold); cursor: pointer; font-family: var(--font-ui); font-weight: 500;
}
.cdx-box-add:hover { background: var(--gold-wash); }
.cdx-box-marker-row { margin-top: 6px; }
.cdx-box-marker-row .cdx-box-key { margin-bottom: 4px; }
.cdx-box-marker { background: #241c15; color: var(--bar-gold); padding: 1px 7px; border-radius: var(--radius-sm); font-size: 12px; }
.cdx-infobox-field { margin: 4px 0 8px; }
.cdx-ib-line, .cdx-ib-body { margin: 6px 0; }
.cdx-entity-field { margin: 4px 0 8px; }
.cdx-entity-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.cdx-entity-row select { width: auto; }
.cdx-entity-row input { flex: 1 1 260px; width: auto; }

/* ---- documents + attachments ---- */
.codex-docs { margin: 30px 0 8px; }
.codex-docs h2 {
  font-family: var(--font-ui);
  font-size: 11px; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--text-eyebrow); margin: 0 0 10px;
  border-bottom: 1px solid var(--border); padding-bottom: 5px;
}
.codex-docs-list, .cdx-attach-list { list-style: none; margin: 0; padding: 0; }
.codex-docs-list li, .cdx-attach-list li {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-3); margin-bottom: 6px; padding: 2px 8px;
}
.codex-docs-list a, .cdx-attach-list a {
  display: flex; align-items: center; gap: 10px; flex: 1;
  color: var(--text-primary); padding: 8px 6px;
}
.codex-docs-list a:hover { background: var(--gold-wash); border-radius: var(--radius-sm); text-decoration: none; }
.cdx-doc-ico { font-size: 18px; color: var(--gold); }
.cdx-doc-name { font-weight: 500; flex: 1; word-break: break-word; }
.cdx-doc-size { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

.cdx-attach, .cdx-galleries {
  margin: 24px 0; padding: var(--pad-md) var(--pad-lg);
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-3);
}
.cdx-attach h2, .cdx-galleries > h2 {
  font-family: var(--font-display); font-size: 17px; font-weight: 500;
  color: var(--text-primary); margin: 0 0 4px;
}
.cdx-attach .cdx-sub, .cdx-galleries > .cdx-sub { margin: 0 0 12px; }
.cdx-attach-empty, .cdx-gallery-empty, .cdx-gallery-none { color: var(--text-muted); font-style: italic; margin: 0 0 12px; }
.cdx-attach-remove, .cdx-gallery-remove {
  width: 28px; height: 28px; flex: 0 0 auto;
  border: 1px solid var(--danger); color: var(--danger); background: transparent;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; line-height: 1;
}
.cdx-attach-remove:hover, .cdx-gallery-remove:hover { background: var(--danger); color: var(--surface-3); }
.cdx-attach-add, .cdx-gallery-add, .cdx-gallery-new { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cdx-attach-add input[type=file], .cdx-gallery-add input[type=file] { font-size: 13px; }
.cdx-attach-name { width: auto; min-width: 220px; flex: 1; padding: 7px 10px; font-size: 13px; }
.cdx-attach-add button:disabled, .cdx-gallery-add button:disabled, .cdx-gallery-new button:disabled { opacity: 0.55; cursor: default; }
.cdx-attach-status, .cdx-gallery-status, .cdx-gallery-newstatus { font-size: 13px; color: var(--ok); }
.cdx-attach-status.err, .cdx-gallery-status.err, .cdx-gallery-newstatus.err { color: var(--danger); }

/* ---- galleries ---- */
.cdx-gallery-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: 11px 13px; margin: 0 0 12px; }
.cdx-gallery-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.cdx-gallery-title { flex: 1; min-width: 140px; width: auto; padding: 6px 10px; font-size: 14px; font-weight: 500; }
.cdx-gallery-spacer { flex: 0 0 4px; }
.cdx-gallery-head button {
  width: 30px; height: 30px; flex: 0 0 auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-3); color: var(--text-secondary); cursor: pointer; line-height: 1;
}
.cdx-gallery-head button:hover { border-color: var(--gold-soft); color: var(--gold); }
.cdx-gallery-del:hover { border-color: var(--danger) !important; color: var(--danger) !important; }
.cdx-gallery-files { list-style: none; margin: 0 0 8px; padding: 0; }
.cdx-gallery-files li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.cdx-gallery-files a { display: flex; align-items: center; gap: 8px; flex: 1; color: var(--text-secondary); padding: 4px 7px; }
.cdx-gallery-files a:hover { background: var(--gold-wash); border-radius: var(--radius-sm); text-decoration: none; }

.codex-gallery { clear: both; margin: 30px 0 8px; }
.codex-gallery h2 {
  font-family: var(--font-display); font-size: 20px; font-weight: 500;
  color: var(--text-primary); margin: 0 0 12px;
  padding-bottom: 7px; border-bottom: 1px solid var(--rule);
}
.codex-gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.cdx-gal-item {
  color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  background: var(--surface-3); display: flex; flex-direction: column;
}
.cdx-gal-item:hover { border-color: var(--gold-soft); text-decoration: none; }
.cdx-gal-image img { width: 100%; height: 150px; object-fit: cover; display: block; background: #241c15; }
.cdx-gal-cap { font-size: 12px; color: var(--text-muted); padding: 7px 9px; word-break: break-word; }
.cdx-gal-doc { padding: 15px 12px; min-height: 150px; gap: 6px; align-items: center; justify-content: center; text-align: center; }
.cdx-gal-doc:hover { background: var(--gold-wash); }
.cdx-gal-ico { font-size: 32px; line-height: 1; color: var(--gold); }
.cdx-gal-name { font-weight: 500; font-size: 13.5px; word-break: break-word; }
.cdx-gal-size { color: var(--text-muted); font-size: 12px; }

/* ---- file manager ---- */
.cdx-file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--gap-md); }
.cdx-file-card {
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background: var(--surface-2); display: flex; flex-direction: column;
}
.cdx-file-thumb {
  display: flex; align-items: center; justify-content: center;
  height: 140px; background: var(--surface-3); overflow: hidden;
}
.cdx-file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cdx-file-icon { font-family: var(--font-ui); font-size: 20px; font-weight: 500; color: var(--gold); letter-spacing: 1.5px; }
.cdx-file-meta { padding: 11px 13px; display: grid; gap: 6px; }
.cdx-file-name { font-weight: 500; color: var(--text-primary); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cdx-copy-row { display: flex; gap: 6px; align-items: center; }
.cdx-copy-input { flex: 1 1 auto; min-width: 0; width: auto; padding: 5px 8px; font-size: 11px; font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--text-muted); }

/* ---- history + diffs ---- */
.codex-history { list-style: none; margin: 6px 0 0; padding: 0; }
.hist-row {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 9px 11px; border-bottom: 1px solid var(--border);
  font-family: var(--font-ui); font-size: 14px;
}
.hist-row.current { background: var(--gold-wash); }
.hist-when { font-weight: 500; color: var(--text-primary); white-space: nowrap; }
.hist-author { color: var(--text-muted); font-size: 13px; }
.hist-author::before { content: "by "; color: var(--text-muted); }
.hist-summary { color: var(--text-secondary); font-style: italic; flex: 1 1 200px; }
.hist-links { margin-left: auto; display: inline-flex; align-items: baseline; gap: 8px; }
.hist-links a { color: var(--gold); font-size: 13px; }
.hist-tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500;
  border-radius: var(--radius-sm); padding: 1px 7px; border: 1px solid currentColor;
}
.hist-tag.cur { color: var(--ok); }
.hist-tag.pending { color: var(--warn); }
.hist-tag.rejected { color: var(--danger); }
.hist-tag.hidden { color: var(--text-muted); }
.hist-row.hidden-rev { opacity: 0.6; }
.hist-row.hidden-rev .hist-when { text-decoration: line-through; }
.hist-hide-form { display: inline; margin: 0; }
.hist-hide-btn {
  border: 1px solid var(--border); background: transparent; color: var(--text-secondary);
  font-size: 12px; padding: 1px 9px; border-radius: var(--radius-sm); cursor: pointer;
}
.hist-hide-btn:hover { border-color: var(--gold-soft); color: var(--gold); }

.rev-banner { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: var(--gap-md); }
.rev-status { font-size: 10px; text-transform: uppercase; font-weight: 500; border-radius: var(--radius-sm); padding: 1px 7px; color: var(--warn); border: 1px solid var(--warn); }
.rev-status.rejected { color: var(--danger); border-color: var(--danger); }

.codex-diff-head { color: var(--text-muted); font-size: 13px; margin: 4px 0 12px; }
.codex-diff {
  white-space: pre-wrap; word-break: break-word; margin: 0;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.55;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px;
}
.codex-diff .dadd, .review-item .diff .dadd { color: var(--ok); display: block; }
.codex-diff .ddel, .review-item .diff .ddel { color: var(--danger); display: block; }
.codex-diff .dctx, .review-item .diff .dctx { color: var(--text-muted); display: block; }
.review-item header { font-size: 15px; color: var(--text-primary); margin-bottom: 8px; }
.review-item .summary { font-style: italic; color: var(--text-muted); margin: 0 0 10px; }
.review-item .diff { font-size: 12px; line-height: 1.5; font-family: ui-monospace, Menlo, Consolas, monospace; }
.review-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.review-actions input { flex: 1 1 220px; width: auto; }
.codex-review .count { font-family: var(--font-ui); font-size: 14px; border: 1px solid var(--danger); color: var(--danger); padding: 2px 11px; border-radius: var(--radius-pill); vertical-align: middle; }

/* ---- bilingual bars ---- */
.codex-langbar { display: flex; gap: 6px; align-items: center; margin: 0 0 var(--gap-md); flex-wrap: wrap; font-family: var(--font-ui); }
.codex-langbar a, .codex-langbar span {
  font-size: 13px; padding: 4px 12px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); color: var(--text-secondary);
}
.codex-langbar a:hover { border-color: var(--gold-soft); color: var(--gold); text-decoration: none; }
.codex-langbar a.active { background: var(--gold); color: #1c150f; border-color: var(--gold); font-weight: 500; }
.codex-langbar a.create { color: var(--ok); border-style: dashed; }
.codex-langbar .muted { color: var(--text-muted); border-style: dashed; }

.cdx-lang-edit {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: var(--gap-md); padding: 9px 14px;
  background: var(--gold-wash); border: 1px solid var(--border); border-radius: var(--radius);
}
.cdx-lang-label { font-family: var(--font-ui); font-weight: 500; color: var(--text-secondary); font-size: 13px; }
.cdx-lang-edit a {
  font-family: var(--font-ui); padding: 4px 15px;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  color: var(--text-secondary); background: var(--surface-3);
}
.cdx-lang-edit a.active { background: var(--gold); color: #1c150f; border-color: var(--gold); font-weight: 500; }

/* ---- link picker ---- */
.cdx-link-modal {
  position: fixed; inset: 0; z-index: 9999; display: none;
  align-items: flex-start; justify-content: center; background: rgba(28, 21, 15, 0.55);
}
.cdx-link-box {
  margin-top: 12vh; width: min(440px, 92vw);
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); padding: var(--pad-md) var(--pad-lg);
}
.cdx-link-title { font-family: var(--font-display); font-size: 17px; font-weight: 500; color: var(--text-primary); margin-bottom: 10px; }
.cdx-link-results { list-style: none; margin: 10px 0 0; padding: 0; max-height: 300px; overflow: auto; }
.cdx-link-results li {
  padding: 8px 11px; border-radius: var(--radius); cursor: pointer;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.cdx-link-results li:hover { background: var(--gold-wash); }
.cdx-link-results .r-title { font-weight: 500; color: var(--text-primary); }
.cdx-link-results .r-slug { font-size: 12px; color: var(--text-muted); font-family: ui-monospace, Menlo, Consolas, monospace; }
.cdx-link-results .r-new { color: var(--ok); font-style: italic; display: block; }
.cdx-link-results .r-empty { color: var(--text-muted); font-style: italic; cursor: default; display: block; }
.cdx-link-hint { margin-top: 10px; font-size: 12px; color: var(--text-muted); }

/* ---- templates ---- */
.tpl-name { font-weight: 500; font-size: 16px; margin-bottom: 10px; }
.tpl-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tpl-cols label { display: block; font-family: var(--font-ui); font-size: 12px; color: var(--text-muted); font-weight: 500; }
.tpl-cols textarea { margin-top: 5px; }
.tpl-actions { margin-top: 10px; display: flex; gap: 8px; }
@media (max-width: 680px) { .tpl-cols { grid-template-columns: 1fr; } }

/* ---- lightbox ---- */
body.cdx-lb-on { overflow: hidden; }
.cdx-lightbox {
  position: fixed; inset: 0; z-index: 1000; display: none;
  align-items: center; justify-content: center;
  background: rgba(13, 11, 8, 0.94); padding: 40px;
}
.cdx-lightbox.open { display: flex; }
.cdx-lb-fig { margin: 0; max-width: 90vw; max-height: 88vh; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.cdx-lb-fig img { max-width: 90vw; max-height: 78vh; object-fit: contain; border-radius: var(--radius); background: #241c15; }
.cdx-lb-fig figcaption { font-family: var(--font-prose); color: #c9bda4; font-size: 15px; text-align: center; max-width: 70ch; }
.cdx-lightbox button {
  position: absolute; width: 46px; height: 46px;
  background: rgba(0, 0, 0, 0.4); color: var(--bar-gold);
  border: 1px solid #4d4132; border-radius: var(--radius);
  cursor: pointer; font-size: 24px; line-height: 1;
}
.cdx-lightbox button:hover { background: #241c15; }
.cdx-lb-close { top: 18px; right: 18px; }
.cdx-lb-prev { left: 18px; top: 50%; transform: translateY(-50%); }
.cdx-lb-next { right: 18px; top: 50%; transform: translateY(-50%); }

@media (max-width: 760px) {
  .cdx-grid { grid-template-columns: 1fr 1fr; }
  .cdx-search { flex-direction: column; }
  .cdx-table, .cdx-table thead, .cdx-table tbody, .cdx-table th, .cdx-table td, .cdx-table tr { display: block; }
  .cdx-table thead { display: none; }
  .cdx-table tr { margin-bottom: 10px; }
  .cdx-adminbar { top: 56px; padding: 6px var(--pad-md); }
}
@media (max-width: 560px) {
  .cdx-lightbox { padding: 16px; }
  .cdx-lb-prev { left: 8px; }
  .cdx-lb-next { right: 8px; }
}

/* ---- editor shell ---- */
.cdx-ed {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: var(--gap-md);
  align-items: start;
}
.cdx-ed__main { min-width: 0; }

.cdx-ed__side {
  position: sticky;
  top: 70px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad-md);
  max-height: 660px;
  overflow-y: auto;
}
.cdx-ed__side-head {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--text-eyebrow);
  margin-bottom: var(--gap-sm);
}
.cdx-ed__outline { list-style: none; margin: 0; padding: 0; font-family: var(--font-ui); font-size: 13px; }
.cdx-ed__outline li {
  padding: 4px 7px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  border-left: 2px solid transparent;
}
.cdx-ed__outline li:hover { background: var(--gold-wash); color: var(--text-primary); border-left-color: var(--gold-soft); }
.cdx-ed__outline .lvl-1 { font-weight: 500; color: var(--text-primary); }
.cdx-ed__outline .lvl-2 { padding-left: 16px; }
.cdx-ed__outline .lvl-3 { padding-left: 28px; font-size: 12.5px; }
.cdx-ed__outline .lvl-4 { padding-left: 40px; font-size: 12.5px; }
.cdx-ed__outline-empty { color: var(--text-muted); font-style: italic; cursor: default; }

.cdx-ed__draft {
  margin-top: var(--gap-md);
  padding: 9px 11px;
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--gold-wash);
}
.cdx-ed__draft-actions { display: flex; gap: 6px; margin-top: 8px; }
.cdx-ed__draft-actions .cdx-mini-btn { padding: 3px 9px; font-size: 12px; }

/* ---- Toast UI, tinted toward the parchment palette ----
   Never set the `background` shorthand on .toastui-editor-toolbar-icons:
   the icon sprite lives in background-image and the shorthand erases it. */
.toastui-editor-defaultUI { border-color: var(--border); border-radius: var(--radius); }
.toastui-editor-defaultUI-toolbar { background-color: var(--surface-2); border-color: var(--border); }
.toastui-editor-toolbar { background-color: var(--surface-2); border-color: var(--border); }
.toastui-editor-toolbar-icons { background-color: transparent; border-color: transparent; }
.toastui-editor-toolbar-icons:not(.cdx-tb):hover { background-color: var(--gold-wash); border-color: var(--border); }
.toastui-editor-toolbar-divider { background-color: var(--border); }

.toastui-editor-md-container, .toastui-editor-ww-container { background-color: var(--surface-3); }
.toastui-editor-md-preview { background-color: var(--surface-2); }
.toastui-editor-md-preview .toastui-editor-contents { font-family: var(--font-prose); color: var(--text-secondary); }
.toastui-editor-contents h1, .toastui-editor-contents h2, .toastui-editor-contents h3 {
  font-family: var(--font-display);
  color: var(--text-primary);
  border-color: var(--border);
}
.toastui-editor-mode-switch { background-color: var(--surface-2); border-color: var(--border); }
.toastui-editor-mode-switch .tab-item { background-color: transparent; color: var(--text-muted); border-color: var(--border); }
.toastui-editor-mode-switch .tab-item.active { background-color: var(--surface-3); color: var(--gold); }

/* Custom toolbar buttons carry text, so they opt out of the sprite entirely. */
button.cdx-tb {
  width: auto;
  height: 28px;
  margin: 0 2px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
button.cdx-tb .cdx-tb__t {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  text-indent: 0;
  line-height: 1;
}
button.cdx-tb:hover { background-color: var(--gold-wash); border-color: var(--border); }
button.cdx-tb:hover .cdx-tb__t { color: var(--gold); }
button.cdx-tb-preview .cdx-tb__t { color: var(--gold); }

/* ---- preview modal ---- */
.cdx-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: none;
  align-items: flex-start;
  justify-content: center;
  background: rgba(28, 21, 15, 0.6);
  padding: 40px 20px;
}
.cdx-preview-box {
  width: min(880px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}
.cdx-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 18px;
  background: #241c15;
  color: var(--bar-gold);
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
}
.cdx-preview-close {
  background: transparent;
  border: 0;
  color: var(--bar-gold);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.cdx-preview-body { overflow-y: auto; border: 0; border-radius: 0; }

@media (max-width: 900px) {
  .cdx-ed { grid-template-columns: 1fr; }
  .cdx-ed__side { position: static; max-height: none; }
}


/* The embedded editor styles its own controls. Keep the form's rules out. */
.toastui-editor-defaultUI button,
.toastui-editor-defaultUI input,
.toastui-editor-defaultUI textarea,
.toastui-editor-defaultUI select {
  font-family: inherit;
  box-shadow: none;
}
.toastui-editor-defaultUI button:not(.cdx-tb) {
  background-color: transparent;
  border-color: transparent;
  color: inherit;
  padding: 0;
}

.cdx-ed__caption {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.cdx-ed__caption code { background: var(--gold-wash); padding: 1px 5px; border-radius: var(--radius-sm); }
