html { min-height: 100%; background-color: #f3f4f6; }
html.dark { background-color: #030712; }
body { overscroll-behavior-y: contain; }

/* Toasts */
.toast-root {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
}
.toast {
  padding: 0.75rem 1rem;
  border-radius: 0.625rem;
  font-size: 0.875rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  animation: toast-in 0.25s ease;
  color: #fff;
}
.toast-success { background: #15803d; }
.toast-error { background: #dc2626; }
.toast-info { background: #1d4ed8; }
html.dark .toast { box-shadow: 0 8px 24px rgba(0,0,0,0.45); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Skeleton */
.skeleton-block.hidden { display: none !important; }
.skeleton-block:not(.hidden) { display: block; padding: 0.5rem 0; }
.skeleton-shimmer {
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  border-radius: 0.5rem;
}
html.dark .skeleton-shimmer {
  background: linear-gradient(90deg, #334155 25%, #475569 50%, #334155 75%);
  background-size: 200% 100%;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
/* Links table skeleton */
.skeleton-table { border: 1px solid #e2e8f0; border-radius: 0.75rem; overflow: hidden; }
html.dark .skeleton-table { border-color: #475569; }
.skeleton-table-header { height: 2.5rem; }
.skeleton-table-row { height: 3rem; margin-top: 1px; }
/* Content box grid skeleton — 3×3 like live layout */
.skeleton-content-boxes-wrap {
  border-radius: 1rem;
  padding: 1.5rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
}
html.dark .skeleton-content-boxes-wrap { background: #0f172a; border-color: #334155; }
.skeleton-grid-3x3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}
@media (max-width: 768px) {
  .skeleton-grid-3x3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .skeleton-grid-3x3 { grid-template-columns: 1fr; }
}
.skeleton-grid-3x3 .skeleton-card { aspect-ratio: 4/3; border-radius: 0.75rem; }
/* Pages accordion skeleton */
.skeleton-accordion { margin-bottom: 0.5rem; border: 1px solid #e2e8f0; border-radius: 0.5rem; overflow: hidden; }
html.dark .skeleton-accordion { border-color: #475569; }
.skeleton-accordion-head { height: 2.5rem; }
.skeleton-accordion-body { height: 3.5rem; margin: 0.5rem; }
/* Raw data tree skeleton */
.skeleton-tree-item { height: 2rem; margin-bottom: 0.5rem; }

/* Login */
#loginDiv input {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border-radius: 0.375rem;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  font-size: 0.9375rem;
}
#loginDiv input::placeholder { color: #94a3b8; }
html.dark #loginDiv input {
  background: #2d3139;
  border-color: #4b5563;
  color: #f1f5f9;
}
html.dark #loginDiv input::placeholder { color: #9ca3af; }
#loginDiv button[type="submit"] {
  padding: 0.625rem;
  border: none;
  border-radius: 0.375rem;
  background: #0072ce;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
#loginDiv button[type="submit"]:hover { background: #005bb5; }

/* Links views — only one visible at a time */
#linksTableWrap, #linksCards { display: none; }
#linksTableWrap.links-visible { display: block; }
#linksCards.links-visible { display: flex; flex-direction: column; gap: 0.75rem; }
@media (max-width: 767px) {
  #linksTableWrap.links-visible { display: none !important; }
}
@media (min-width: 768px) {
  #linksCards.links-visible { display: none !important; }
}

/* Links */
.links-table tbody tr:nth-child(even) { background: rgba(241,245,249,0.8); }
html.dark .links-table tbody tr:nth-child(even) { background: rgba(30,41,59,0.5); }
.links-table tbody tr:hover { background: rgba(0,114,206,0.06); }
html.dark .links-table tbody tr:hover { background: rgba(96,165,250,0.1); }
.del-link-btn {
  background: #dc2626; color: #fff; border: none; padding: 0.375rem 0.75rem;
  border-radius: 0.5rem; font-size: 0.75rem; font-weight: 600; cursor: pointer;
}
.del-link-btn:hover { background: #b91c1c; }
.btn-test-link {
  background: #475569; color: #fff; border: none; padding: 0.375rem 0.75rem;
  border-radius: 0.5rem; font-size: 0.75rem; font-weight: 600; cursor: pointer; margin-right: 0.375rem;
}
.btn-test-link:hover { background: #334155; }
.btn-edit-link {
  background: #0072ce; color: #fff; border: none; padding: 0.375rem 0.75rem;
  border-radius: 0.5rem; font-size: 0.75rem; font-weight: 600; cursor: pointer;
}
.btn-edit-link:hover { background: #005bb5; }
.url-edit-input {
  width: 100%; min-width: 8rem; padding: 0.25rem 0.5rem; border-radius: 0.375rem;
  border: 1px solid #94a3b8; background: #fff; color: #0f172a; font-size: 0.875rem;
}
html.dark .url-edit-input { background: #1e293b; color: #f8fafc; border-color: #64748b; }
.links-cards { display: none; }
.link-card {
  border: 1px solid #cbd5e1; border-radius: 0.75rem; padding: 1rem;
  background: #fff; color: #0f172a;
}
html.dark .link-card { background: #1e293b; border-color: #475569; color: #f8fafc; }
.link-card-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }

/* Dark text overrides */
html.dark .content-panel,
html.dark .panel-hint,
html.dark .db-meta,
html.dark .links-table tbody td,
html.dark .empty-msg,
html.dark .field-label,
html.dark .preview-label { color: #f8fafc; }
html.dark .panel-hint strong { color: #fff; }
html.dark .redirect-cell { color: #93c5fd; }
html.dark .url-cell a { color: #93c5fd; }
html.dark .field-hint { color: #94a3b8; }

/* Theme switcher */
.theme-switcher {
  position: relative; width: 3.5rem; height: 1.75rem;
  background: #d1d5db; border-radius: 9999px; padding: 3px; cursor: pointer;
}
html.dark .theme-switcher { background: #374151; }
.theme-switcher-knob {
  position: absolute; left: 3px; top: 3px; width: 1.25rem; height: 1.25rem;
  background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.3s;
}
html.dark .theme-switcher-knob { background: #111827; transform: translateX(29px); }
.theme-icon { position: absolute; top: 50%; transform: translateY(-50%); font-size: 0.75rem; pointer-events: none; }
.theme-icon-sun { left: 6px; color: #eab308; }
.theme-icon-moon { right: 6px; color: #e2e8f0; }

.page-edit-layout {
  align-items: stretch;
  min-height: calc(100vh - 11rem);
}
.page-edit-layout .edit-box-preview-wrap {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 11rem);
}
.page-edit-layout.preview-hidden { grid-template-columns: 1fr !important; }
.page-edit-layout.preview-hidden .edit-box-preview-wrap { display: none; }
.page-content-preview {
  border: 1px solid #cbd5e1; border-radius: 0.75rem; padding: 0;
  background: #fff; color: #0f172a;
  overflow: hidden; position: relative; display: flex; flex-direction: column;
  flex: 1 1 auto; min-height: 0; max-height: none;
}
.page-preview-frame {
  flex: 1 1 auto; width: 100%; min-height: 0; height: 100%; border: 0; display: block;
  background: #fff;
}
html.dark .page-content-preview { background: #0f172a; border-color: #475569; color: #f8fafc; }
html.dark .page-preview-frame { background: #0f172a; }
.preview-toolbar-actions { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.page-editor-field .tox-tinymce {
  border-radius: 0.5rem !important;
  border-color: #cbd5e1 !important;
  min-height: 34rem;
}
.page-edit-layout.preview-hidden .page-editor-field .tox-tinymce {
  min-height: calc(100vh - 22rem);
}
html.dark .page-editor-field .tox-tinymce {
  border-color: #475569 !important;
}
html.dark .page-editor-field .tox .tox-edit-area__iframe { background: #1e293b; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; }
.preview-toolbar .preview-label { margin: 0; }
.btn-sm { padding: 0.25rem 0.625rem !important; font-size: 0.75rem !important; margin: 0 !important; }

.pages-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.25rem; }
.pages-toolbar h2 { margin: 0; }
.section-actions, .page-row-actions { display: flex; flex-wrap: wrap; gap: 0.375rem; margin: 0.5rem 0.75rem 0.75rem; }
.section-header-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; width: 100%; }
.page-row { cursor: default; }
.page-row-main { flex: 1; cursor: pointer; min-width: 0; }
.page-row-actions .btn-secondary,
.page-row-actions .del-link-btn,
.section-actions .btn-secondary,
.section-actions .del-link-btn { font-size: 0.7rem; padding: 0.25rem 0.5rem; }

.pages-tree details { margin-bottom: 0.5rem; border: 1px solid #cbd5e1; border-radius: 0.5rem; overflow: hidden; }
html.dark .pages-tree details { border-color: #475569; }
.pages-tree summary { padding: 0.625rem 0.875rem; font-weight: 600; cursor: pointer; background: #f1f5f9; color: #0f172a; }
html.dark .pages-tree summary { background: #334155; color: #f8fafc; }
.page-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.625rem 0.875rem; border-top: 1px solid #e2e8f0;
  color: #0f172a;
}
html.dark .page-row { border-color: #475569; color: #f8fafc; }
.page-row:hover { background: rgba(0,114,206,0.06); }
html.dark .page-row:hover { background: rgba(96,165,250,0.08); }
.page-row-meta { font-size: 0.75rem; color: #64748b; }
html.dark .page-row-meta { color: #94a3b8; }

.action-group { display: flex; flex-wrap: wrap; gap: 0.375rem; justify-content: flex-end; }
