:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --line: #dfe4ee;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #3a7bd5;
  --accent-soft: #dbe7ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  --danger: #9f1f1f;
  --danger-line: #e2b4b4;
}

/* =========================
   THEMES
========================= */

:root.light {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #1f2430;
  --line: #dfe4ee;
}

:root.dark {
  --bg: #12141a;
  --panel: #1b1f2a;
  --text: #e6e9f0;
  --line: #2a2f3a;
}

:root.crema {
  --bg: #f6f1e8;
  --panel: #fffaf3;
  --text: #2b2b2b;
  --line: #e6dfd3;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
}

.hidden {
  display: none !important;
}

/* =========================
   HEADER
========================= */

.app-header {
  height: 58px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 18px;
}

.app-header-left,
.app-header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.app-header-right {
  justify-content: flex-end;
}

.app-header-title {
  font-size: 16px;
  font-weight: 800;
  text-align: center;
}

/* =========================
   BUTTONS
========================= */

.primary-btn,
.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
}

.primary-btn:hover {
  opacity: 0.92;
}

.nav-btn {
  border: 1px solid #c7cfdb;
  background: #fff;
  color: var(--text);
}

.nav-btn:hover {
  border-color: var(--accent);
}

.nav-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.nav-btn.small,
.small {
  height: 36px;
  min-width: 36px;
  padding: 0 10px;
}

.uniform-btn {
  min-width: 170px;
}

.danger-btn {
  border-color: var(--danger-line);
  color: var(--danger);
  background: #fff;
}

.danger-btn:hover {
  border-color: #c44;
  background: #fff5f5;
}

/* =========================
   INPUTS
========================= */

.search-input,
.editor-input {
  width: 100%;
  height: 44px;
  border-radius: 10px;
  border: 1px solid #bfc7d5;
  padding: 0 12px;
  font-size: 15px;
  background: #fff;
}

.editor-textarea {
  width: 100%;
  min-height: 420px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid #bfc7d5;
  padding: 12px;
  font-size: 15px;
  line-height: 1.5;
  background: #fff;
}

.editor-label {
  display: block;
  font-weight: 700;
  margin: 10px 0 8px 0;
}

/* =========================
   HOME
========================= */

.home-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.home-container {
  width: 100%;
  max-width: 980px;
  text-align: center;
}

.home-title {
  margin: 0;
  font-size: 42px;
  font-weight: 800;
  color: var(--text);
}

.home-subtitle {
  margin: 10px 0 28px 0;
  font-size: 16px;
  color: var(--muted);
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.home-card {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 18px;
  padding: 28px 22px;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow);
  transition: 0.18s ease;
}

.home-card:hover {
  transform: translateY(-2px);
  border-color: #b7c6df;
  background: #fafcff;
}

.home-card-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

.home-card-desc {
  font-size: 15px;
  color: var(--muted);
  line-height: 1.5;
}

/* =========================
   INDEX / BIBLIOTECA
========================= */

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 58px);
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 24px 18px;
}

.sidebar-title {
  margin: 0 0 18px 0;
  font-size: 24px;
  font-weight: 800;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.category-item,
.category-btn {
  padding: 14px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  transition: 0.15s ease;
  font-size: 16px;
  text-align: left;
}

.category-item:hover,
.category-btn:hover {
  border-color: #b8c4d8;
  background: #fafcff;
}

.category-item.active,
.category-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.main-area,
.content {
  padding: 18px 20px 28px 20px;
  min-width: 0;
}

.topbar {
  margin-bottom: 18px;
}

.search-wrap,
.search-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}

.cards-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cards-empty {
  color: #8a8f98;
  padding: 8px 2px;
}

.entry-card {
  background: #ffffff;
  border: 1px solid #e6e8ee;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.entry-card-main {
  cursor: pointer;
}

.entry-card-title {
  font-size: 20px;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 10px;
}

.entry-card-preview {
  color: #475467;
  line-height: 1.6;
  margin-bottom: 12px;
}

.entry-card-meta {
  font-size: 14px;
  color: #98a2b3;
}

.entry-card-children-wrap {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #eceef3;
}

.toggle-children-btn {
  border: none;
  background: transparent;
  color: #475467;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.toggle-children-btn:hover {
  color: #1f2937;
}

.card-children-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.child-card-link {
  width: 100%;
  text-align: left;
  border: 1px solid #e6e8ee;
  background: #fafbfe;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}

.child-card-link:hover {
  background: #f4f6fb;
}

.child-card-title {
  font-weight: 600;
  color: #344054;
}

.child-card-preview {
  font-size: 14px;
  color: #667085;
}

/* =========================
   READER
========================= */

.reader-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
}

.reader-sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.reader-main {
  min-width: 0;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.reader-title {
  margin: 0 0 8px 0;
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
}

.reader-meta {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 12px;
  font-style: italic;
}

.reader-separator {
  border: none;
  border-top: 1px solid var(--line);
  margin: 0 0 22px 0;
}

.reader-body {
  line-height: 1.7;
  counter-reset: h2;
  display: flow-root;
}

.reader-body h2,
.reader-body h3,
.reader-body h4,
.reader-heading {
  font-weight: 800;
  color: var(--text);
  clear: both;
  line-height: 1.35;
}

.reader-body h2,
.reader-heading {
  font-size: 24px;
  margin: 22px 0 10px 0;
  padding-left: 0;
  counter-reset: h3;
}

.reader-body h3 {
  font-size: 20px;
  margin: 14px 0 8px 0;
  padding-left: 18px;
  counter-reset: h4;
}

.reader-body h4 {
  font-size: 17px;
  margin: 10px 0 6px 0;
  padding-left: 36px;
}

.reader-body h2::before {
  counter-increment: h2;
  content: counter(h2) ". ";
}

.reader-body h3::before {
  counter-increment: h3;
  content: counter(h2) "." counter(h3) " ";
}

.reader-body h4::before {
  counter-increment: h4;
  content: counter(h2) "." counter(h3) "." counter(h4) " ";
}

.reader-body p,
.reader-paragraph {
  margin: 0 0 18px 0;
  line-height: 1.68;
  text-align: justify;
  color: #2b3240;
  font-size: 16px;
  max-width: 78ch;
}

.reader-body a {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

/* =========================
   READER: COVER / INFOBOX / TOC
========================= */

.cover-card,
.wiki-box,
.toc-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.cover-image-large,
.cover-image {
  width: 100%;
  display: block;
  border-radius: 12px;
}

.cover-image-caption,
.cover-caption {
  margin-top: 10px;
  text-align: center;
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}

.wiki-box-inner {
  display: flex;
  flex-direction: column;
}

.wiki-box-section,
.wiki-section-title,
.wiki-box-title {
  text-align: center;
  font-weight: 800;
  font-size: 18px;
  color: var(--text);
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
  background: #f7f8fb;
}

.wiki-box-row,
.wiki-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--line);
}

.wiki-box-row:last-child,
.wiki-row:last-child {
  border-bottom: none;
}

.wiki-box-label,
.wiki-label {
  font-weight: 700;
  color: var(--text);
}

.wiki-box-value,
.wiki-value {
  color: #344054;
  word-break: break-word;
}

.toc-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 10px;
}

#readerTocItems {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toc-link {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 6px 0;
  color: #344054;
  cursor: pointer;
  font: inherit;
}

.toc-link:hover {
  text-decoration: underline;
}

/* =========================
   READER: EMBEDDED IMAGES
========================= */

.reader-media {
  margin: 18px 0 22px 0;
}

.reader-media-left,
.reader-media-right {
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.reader-media-right {
  flex-direction: row-reverse;
}

.reader-media-center {
  text-align: center;
}

.reader-media-text {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.reader-image {
  margin: 0;
  flex-shrink: 0;
  width: 180px;
}

.reader-image img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

.reader-image figcaption {
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

.reader-media-center .reader-image {
  width: min(520px, 100%);
  margin: 0 auto;
}

.reader-media .reader-paragraph,
.reader-media p {
  margin: 0;
  max-width: none;
  text-align: left;
}

.img-row,
.img-box,
.img-float {
  all: unset;
}

.img-row,
.img-box,
.img-float {
  display: block;
}

/* =========================
   EDITOR
========================= */

.editor-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  padding: 24px;
  min-height: calc(100vh - 58px);
}

.editor-sidebar {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.editor-sidebar.hidden {
  display: none !important;
}

.editor-sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.editor-sidebar-title {
  font-size: 22px;
  font-weight: 800;
}

.editor-sidebar-actions {
  display: flex;
  gap: 8px;
}

.editor-entry-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editor-entry-item {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  background: #fff;
}

.editor-entry-item:hover {
  border-color: #b7c6df;
  background: #fafcff;
}

.editor-entry-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.editor-entry-empty {
  color: var(--muted);
  padding: 10px 2px;
}

.editor-entry-item-title {
  font-weight: 600;
}

.editor-entry-item-meta {
  margin-top: 4px;
  font-size: 12px;
  color: #8a8f98;
}

.editor-main {
  min-width: 0;
}

.editor-workspace {
  display: grid;
  grid-template-columns: 1.15fr 360px;
  gap: 22px;
}

.editor-primary-column {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
}

.editor-assets-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.editor-form-card,
.editor-preview-card,
.asset-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 22px;
  box-shadow: var(--shadow);
}

.editor-form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

.editor-form-actions button {
  width: 100%;
  height: 48px;
}

.editor-meta-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: end;
  margin-top: 8px;
}

.editor-meta-block {
  min-width: 0;
}

.editor-check-wrap {
  padding-bottom: 10px;
  white-space: nowrap;
}

.editor-status {
  margin-top: 14px;
  min-height: 20px;
  font-size: 14px;
  color: var(--muted);
}

.editor-preview-title,
.asset-card-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 12px;
}

.asset-card-head,
.infobox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.editor-preview-card .reader-body p,
.editor-preview-card .reader-paragraph {
  text-align: justify;
}

/* =========================
   CATEGORY MENU
========================= */

.category-control-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.category-gear-wrap {
  position: relative;
}

.gear-btn {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  font-size: 18px;
}

.category-menu {
  position: absolute;
  top: 50px;
  right: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  padding: 8px;
  z-index: 40;
}

.category-menu-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
}

.category-menu-item:hover {
  background: #f5f7fb;
}

.category-menu-item.danger {
  color: #a12626;
}

.category-menu-item.danger:hover {
  background: #fff3f3;
}

/* =========================
   STRUCTURE
========================= */

.editor-structure-card {
  margin: 18px 0 16px 0;
  padding: 14px;
  border: 1px solid #e6e8ee;
  border-radius: 14px;
  background: #fafbfe;
}

.structure-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  cursor: pointer;
}

.editor-structure-title {
  font-weight: 700;
  color: #374151;
}

.structure-toggle-clean {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.structure-toggle-icon {
  font-size: 18px;
  color: #667085;
  line-height: 1;
}

.structure-panel[hidden] {
  display: none !important;
}

.editor-structure-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.editor-check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: #374151;
}

.editor-structure-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-structure-help {
  margin-top: 10px;
  font-size: 13px;
  color: #6b7280;
}

.structure-children-box {
  margin-top: 16px;
  border-top: 1px solid #e6e8ee;
  padding-top: 14px;
}

.structure-children-title {
  font-weight: 700;
  color: #374151;
  margin-bottom: 10px;
}

.children-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.children-empty {
  color: #8a8f98;
  font-size: 14px;
}

.child-entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid #e6e8ee;
  border-radius: 16px;
  background: #fafbfe;
}

.child-entry-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  text-align: left;
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid #dfe3ea;
  border-radius: 12px;
  background: #ffffff;
  cursor: pointer;
}

.child-entry-main:hover {
  background: #f8f9fc;
}

.child-entry-title {
  font-weight: 700;
  color: #344054;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.child-entry-meta {
  margin-top: 4px;
  font-size: 12px;
  color: #98a2b3;
}

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

.child-entry-actions .nav-btn.small,
.child-entry-actions .danger-btn.small,
.child-entry-actions .small {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* =========================
   COVER / GALLERY
========================= */

.cover-preview-box,
.selected-image-box,
.gallery-preview-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbfe;
  min-height: 180px;
  padding: 12px;
}

.gallery-preview-box {
  min-height: 320px;
}

.cover-preview-box.empty,
.selected-image-box.empty,
.gallery-preview-box.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

.cover-preview-image,
.selected-image-preview,
.gallery-preview-image {
  width: 100%;
  display: block;
  border-radius: 10px;
}

.cover-preview-caption,
.selected-image-name,
.gallery-preview-title {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.asset-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.asset-actions .primary-btn,
.asset-actions .nav-btn {
  width: 100%;
  height: 48px;
  min-width: 0;
}

.gallery-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.gallery-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  max-height: 320px;
  overflow: auto;
}

.gallery-list.large {
  max-height: 70vh;
}

.gallery-item {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  background: #fff;
}

.gallery-item:hover {
  border-color: #b7c6df;
  background: #fafcff;
}

.gallery-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.gallery-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.gallery-item-title {
  font-size: 14px;
  font-weight: 700;
}

.gallery-item-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.gallery-empty,
.link-empty,
.infobox-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 8px 0;
}

/* =========================
   LINKS
========================= */

.link-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  max-height: 280px;
  overflow: auto;
}

.link-insert-btn {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.link-insert-btn:hover {
  border-color: var(--accent);
  background: #fafcff;
}

/* =========================
   INFOBOX EDITOR
========================= */

.infobox-top-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.infobox-top-actions .primary-btn,
.infobox-top-actions .nav-btn,
.infobox-top-actions .small-action-btn {
  width: 100%;
  height: 48px;
  min-width: 0;
  padding: 0 16px;
  justify-content: center;
}

.small-action-btn {
  font-size: 14px;
}

.infobox-editor-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.infobox-block-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid #e6e8ee;
  border-radius: 12px;
  background: #fafbfe;
}

.infobox-block-main.section input {
  width: 100%;
  height: 48px;
  text-align: center;
  font-weight: 700;
}

.infobox-block-main.item {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.infobox-block-main.item .editor-input {
  height: 48px;
}

.infobox-row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.infobox-row-actions .nav-btn.small,
.infobox-row-actions .small {
  width: 48px;
  min-width: 48px;
  height: 48px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.asset-card .primary-btn,
.asset-card .nav-btn {
  border-radius: 12px;
}

/* =========================
   GALLERY PAGE
========================= */

.gallery-page {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  padding: 24px;
  min-height: calc(100vh - 58px);
}

.gallery-page-sidebar,
.gallery-page-main {
  min-width: 0;
}

/* =========================
   BOARDS BROWSER
========================= */

.boards-page {
  padding: 24px;
}

.boards-page-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}

.boards-page-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.boards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.board-browser-card,
.board-thumb-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  padding: 14px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: 0.18s ease;
}

.board-browser-card:hover,
.board-thumb-card:hover {
  background: #fafcff;
  border-color: #b7c6df;
  transform: translateY(-1px);
}

.board-browser-card.active,
.board-thumb-card.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.board-browser-title,
.board-thumb-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.board-thumb-desc {
  font-size: 13px;
  color: var(--muted);
}

.board-thumb-canvas {
  position: relative;
  height: 140px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f9fbff;
  overflow: hidden;
  margin-bottom: 12px;
}

.board-thumb-note {
  position: absolute;
  width: 48px;
  border: 1px solid;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

.board-thumb-empty {
  height: 140px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f9fbff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  margin-bottom: 12px;
  font-size: 13px;
}

.board-thumb-card {
  position: relative;
}

.board-card-main {
  width: 100%;
  border: none;
  background: transparent;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.board-card-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

.board-select-btn {
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
}

.board-select-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* =========================
   BOARD WORKSPACE
========================= */

.board-workspace-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 22px;
  padding: 24px;
  min-height: calc(100vh - 58px);
}

.board-workspace-main {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.board-workspace-toolbar-card,
.board-workspace-canvas-card,
.board-workspace-rightbar .asset-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.board-workspace-toolbar-card,
.board-workspace-canvas-card {
  padding: 18px;
}

.board-workspace-toolbar-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: end;
}

.board-title-block {
  min-width: 0;
}

.board-toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.board-workspace-canvas-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.board-workspace-canvas-title {
  font-size: 20px;
  font-weight: 800;
}

.board-workspace-rightbar {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.board-canvas {
  position: relative;
  min-height: 720px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f9fbff;
  overflow: auto;
}

.board-canvas.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

.board-empty-text {
  color: var(--muted);
  text-align: center;
  padding-top: 160px;
}

.board-note {
  position: absolute;
  width: 180px;
  min-height: 120px;
  border: 1px solid;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  cursor: move;
  user-select: none;
  transition: box-shadow 0.15s ease;
}

.board-note:hover {
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.10);
}

.board-note.selected {
  outline: 2px solid #7aa2e3;
  outline-offset: 2px;
}

.board-note-minihead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: #667085;
  font-weight: 700;
  margin-bottom: 8px;
}

.board-note-text-preview {
  font-size: 14px;
  line-height: 1.4;
  color: #344054;
  word-break: break-word;
  white-space: pre-wrap;
}

.selected-note-panel,
.board-summary-preview {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbfe;
  padding: 14px;
}

.selected-note-panel.empty,
.board-summary-preview.empty {
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
}

.selected-note-textarea {
  min-height: 180px;
}

.groups-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.group-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbfe;
  padding: 10px 12px;
}

.group-row-title {
  font-weight: 700;
  color: var(--text);
}

.group-row-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.board-summary-text {
  margin: 0;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.55;
  color: #344054;
}

/* =========================
   SUMMARY (TABLEROS)
========================= */

.summary-actions {
  display: flex;
  gap: 10px;
  margin: 10px 0 14px 0;
}

.summary-actions button {
  height: 40px;
  min-width: 140px;
}

/* =========================
   RESPONSIVE
========================= */

@media (max-width: 1280px) {
  .board-workspace-layout {
    grid-template-columns: 1fr;
  }

  .editor-workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1100px) {
  .reader-shell {
    grid-template-columns: 1fr;
  }

  .reader-sidebar {
    order: 2;
  }

  .reader-main {
    order: 1;
  }
}

@media (max-width: 900px) {
  .reader-media-left,
  .reader-media-right {
    display: block;
  }

  .reader-image {
    width: min(320px, 100%);
    margin-bottom: 14px;
  }

  .reader-media-center .reader-image {
    width: min(420px, 100%);
  }

  .editor-layout,
  .gallery-page,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .editor-structure-grid,
  .editor-meta-row,
  .boards-page-toolbar,
  .board-workspace-toolbar-top {
    grid-template-columns: 1fr;
  }

  .home-grid {
    grid-template-columns: 1fr;
  }

  .asset-actions {
    grid-template-columns: 1fr;
  }

  .infobox-top-actions {
    grid-template-columns: 1fr;
  }

  .infobox-block-editor {
    grid-template-columns: 1fr;
  }

  .infobox-block-main.item {
    grid-template-columns: 1fr;
  }

  .infobox-row-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 720px) {
  .child-entry-row {
    grid-template-columns: 1fr;
  }

  .child-entry-actions {
    justify-content: flex-end;
  }
}

/* =========================
   EDITOR SIDEBAR COLLAPSE REAL
========================= */

.editor-layout.sidebar-collapsed {
  grid-template-columns: 1fr;
}

.editor-layout.sidebar-collapsed .editor-main {
  width: 100%;
}

.editor-layout.sidebar-collapsed .editor-workspace {
  grid-template-columns: minmax(0, 1fr) 360px;
}

@media (max-width: 1280px) {
  .editor-layout.sidebar-collapsed .editor-workspace {
    grid-template-columns: 1fr;
  }
}

.home-theme-wrap {
  margin: 0 0 22px 0;
  display: flex;
  justify-content: center;
}

.home-theme-wrap select {
  min-width: 170px;
}

/* =========================
   DARK THEME OVERRIDES
========================= */

:root.dark body,
:root.dark {
  --bg: #0f1117;
  --panel: #171a22;
  --text: #e8ecf3;
  --muted: #a7b0c0;
  --line: #2a3140;
  --accent: #4c8dff;
  --accent-soft: #1a2742;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  --danger: #ff8a8a;
  --danger-line: #6a2f2f;
}

:root.dark body {
  background: var(--bg);
  color: var(--text);
}

:root.dark .app-header,
:root.dark .reader-main,
:root.dark .cover-card,
:root.dark .wiki-box,
:root.dark .toc-card,
:root.dark .editor-sidebar,
:root.dark .editor-form-card,
:root.dark .editor-preview-card,
:root.dark .asset-card,
:root.dark .board-workspace-toolbar-card,
:root.dark .board-workspace-canvas-card,
:root.dark .board-workspace-rightbar .asset-card,
:root.dark .entry-card,
:root.dark .home-card,
:root.dark .board-browser-card,
:root.dark .board-thumb-card {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
}

:root.dark .sidebar {
  background: var(--panel);
  border-right-color: var(--line);
}

:root.dark .search-input,
:root.dark .editor-input,
:root.dark .editor-textarea,
:root.dark .category-item,
:root.dark .category-btn,
:root.dark .editor-entry-item,
:root.dark .child-card-link,
:root.dark .child-entry-main,
:root.dark .gallery-item,
:root.dark .link-insert-btn,
:root.dark .board-canvas,
:root.dark .selected-note-panel,
:root.dark .board-summary-preview,
:root.dark .cover-preview-box,
:root.dark .selected-image-box,
:root.dark .gallery-preview-box,
:root.dark .editor-structure-card,
:root.dark .child-entry-row,
:root.dark .group-row,
:root.dark .infobox-block-editor {
  background: #1d2230;
  color: var(--text);
  border-color: var(--line);
}

:root.dark .app-header-title,
:root.dark .home-title,
:root.dark .home-card-title,
:root.dark .sidebar-title,
:root.dark .reader-title,
:root.dark .editor-sidebar-title,
:root.dark .editor-preview-title,
:root.dark .asset-card-title,
:root.dark .entry-card-title,
:root.dark .board-browser-title,
:root.dark .board-thumb-title,
:root.dark .board-workspace-canvas-title,
:root.dark .editor-structure-title,
:root.dark .structure-children-title,
:root.dark .child-entry-title,
:root.dark .group-row-title,
:root.dark .toc-title,
:root.dark .wiki-box-section,
:root.dark .wiki-section-title,
:root.dark .wiki-box-title {
  color: var(--text);
}

:root.dark .reader-meta,
:root.dark .home-subtitle,
:root.dark .home-card-desc,
:root.dark .entry-card-preview,
:root.dark .entry-card-meta,
:root.dark .child-card-preview,
:root.dark .gallery-item-sub,
:root.dark .cover-preview-caption,
:root.dark .selected-image-name,
:root.dark .gallery-preview-title,
:root.dark .wiki-box-value,
:root.dark .wiki-value,
:root.dark .editor-status,
:root.dark .editor-structure-help,
:root.dark .children-empty,
:root.dark .gallery-empty,
:root.dark .link-empty,
:root.dark .infobox-empty,
:root.dark .cards-empty,
:root.dark .board-empty-text,
:root.dark .board-summary-text,
:root.dark .board-note-minihead,
:root.dark .board-note-text-preview {
  color: var(--muted);
}

:root.dark .reader-body p,
:root.dark .reader-paragraph,
:root.dark .wiki-box-label,
:root.dark .wiki-label,
:root.dark .child-card-title,
:root.dark .toc-link,
:root.dark .editor-label,
:root.dark .editor-check-line {
  color: var(--text);
}

:root.dark .reader-separator,
:root.dark .entry-card-children-wrap,
:root.dark .structure-children-box,
:root.dark .wiki-box-row,
:root.dark .wiki-row {
  border-color: var(--line);
}

:root.dark .primary-btn {
  background: var(--accent);
  color: #ffffff;
}

:root.dark .nav-btn {
  background: #1b2130;
  color: var(--text);
  border-color: var(--line);
}

:root.dark .nav-btn:hover,
:root.dark .category-item:hover,
:root.dark .category-btn:hover,
:root.dark .gallery-item:hover,
:root.dark .link-insert-btn:hover,
:root.dark .child-card-link:hover,
:root.dark .child-entry-main:hover,
:root.dark .editor-entry-item:hover,
:root.dark .home-card:hover,
:root.dark .board-browser-card:hover,
:root.dark .board-thumb-card:hover {
  background: #22293a;
  border-color: #3c4961;
}

:root.dark .nav-btn.active,
:root.dark .category-item.active,
:root.dark .category-btn.active,
:root.dark .gallery-item.active,
:root.dark .editor-entry-item.active,
:root.dark .board-browser-card.active,
:root.dark .board-thumb-card.active,
:root.dark .board-select-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

:root.dark .danger-btn {
  background: #24181a;
  color: #ff9b9b;
  border-color: #5f3131;
}

:root.dark .danger-btn:hover {
  background: #311d20;
  border-color: #a14a4a;
}

:root.dark .board-thumb-canvas,
:root.dark .board-thumb-empty {
  background: #161c28;
  border-color: var(--line);
  color: var(--muted);
}

:root.dark .board-canvas.empty {
  background: #161c28;
  color: var(--muted);
}

/* =========================
   CREMA THEME OVERRIDES
========================= */

:root.crema body,
:root.crema {
  --bg: #f4ecdf;
  --panel: #fffaf1;
  --text: #332b22;
  --muted: #7a6d5f;
  --line: #e4d8c6;
  --accent: #9a6b2f;
  --accent-soft: #f1e2cb;
  --shadow: 0 1px 2px rgba(60, 45, 25, 0.08);
  --danger: #a94442;
  --danger-line: #d7b0a8;
}

:root.crema body {
  background: var(--bg);
  color: var(--text);
}

:root.crema .app-header,
:root.crema .reader-main,
:root.crema .cover-card,
:root.crema .wiki-box,
:root.crema .toc-card,
:root.crema .editor-sidebar,
:root.crema .editor-form-card,
:root.crema .editor-preview-card,
:root.crema .asset-card,
:root.crema .board-workspace-toolbar-card,
:root.crema .board-workspace-canvas-card,
:root.crema .board-workspace-rightbar .asset-card,
:root.crema .entry-card,
:root.crema .home-card,
:root.crema .board-browser-card,
:root.crema .board-thumb-card {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
}

:root.crema .sidebar {
  background: var(--panel);
  border-right-color: var(--line);
}

:root.crema .search-input,
:root.crema .editor-input,
:root.crema .editor-textarea,
:root.crema .category-item,
:root.crema .category-btn,
:root.crema .child-card-link,
:root.crema .child-entry-main,
:root.crema .gallery-item,
:root.crema .link-insert-btn,
:root.crema .board-canvas,
:root.crema .selected-note-panel,
:root.crema .board-summary-preview,
:root.crema .cover-preview-box,
:root.crema .selected-image-box,
:root.crema .gallery-preview-box,
:root.crema .editor-structure-card,
:root.crema .child-entry-row,
:root.crema .group-row,
:root.crema .infobox-block-editor {
  background: #fff8ee;
  color: var(--text);
  border-color: var(--line);
}

:root.crema .primary-btn {
  background: var(--accent);
  color: #fff;
}

:root.crema .nav-btn {
  background: #fffaf1;
  color: var(--text);
  border-color: var(--line);
}

:root.crema .nav-btn.active,
:root.crema .category-item.active,
:root.crema .category-btn.active,
:root.crema .gallery-item.active,
:root.crema .editor-entry-item.active,
:root.crema .board-browser-card.active,
:root.crema .board-thumb-card.active,
:root.crema .board-select-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* =========================
   MODAL
========================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 9999;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
  padding: 22px;
}

.modal-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 18px;
}

:root.dark .modal-backdrop {
  background: rgba(0, 0, 0, 0.58);
}

:root.dark .modal-card {
  background: var(--panel);
  border-color: var(--line);
}

:root.crema .modal-card {
  background: var(--panel);
  border-color: var(--line);
}

/* =========================
   PAGE TRANSITIONS
========================= */

html {
  background: var(--bg);
}

body {
  opacity: 0;
  transition: opacity 0.18s ease;
}

body.page-ready {
  opacity: 1;
}
