/* Dropbits default theme — CMS edit chrome
 * Loaded only in edit mode (via cms_head injection).
 * Styles for: .db-edit-toggle, .cms-edit-wrap, .cms-save, .cms-cancel,
 * toast, status pill, draft banner, autocomplete, delete button.
 * ─────────────────────────────────────────────────────────────────── */

/* ── CMS anchor ───────────────────────────────────────────────────── */
[data-cms] { position: relative; }

/* ── Edit-mode toggle (floating badge, bottom-right corner) ─────────── */
.db-edit-chrome {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
}

.db-edit-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.55rem;
  height: 2.55rem;
  padding: 0;
  border-radius: 50%;
  font-size: 1.15rem;
  font-weight: 600;
  text-decoration: none;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  transition: opacity 0.15s, transform 0.15s, background 0.15s, border-color 0.15s;
}
.db-edit-toggle:hover { opacity: 0.9; transform: scale(1.06); }
.db-edit-toggle--off {
  background: #ececec;
  color: #888;
  border: 2px solid #b8b8b8;
}
.db-edit-toggle--off:hover { color: #666; border-color: #999; }
.db-edit-toggle--on {
  background: #22a559;
  color: #fff;
  border: 2px solid #1a8447;
}

.db-edit-logout {
  display: inline-flex;
  align-items: center;
  padding: 0.38em 0.8em;
  border-radius: 2em;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  line-height: 1;
  color: #fff;
  background: #c0392b;
  border: 1.5px solid transparent;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

.db-edit-logout:hover {
  filter: brightness(1.08);
  transform: scale(1.03);
}

/* ── Editable regions (edit mode only) ─────────────────────────────── */
html.db-edit-active [data-cms] {
  outline: 3px solid rgba(34, 165, 89, 0.55);
  outline-offset: 4px;
  border-radius: 6px;
}
html.db-edit-active .db-record[data-record-id] {
  box-shadow: inset 0 0 0 3px rgba(34, 165, 89, 0.4);
  border-radius: 6px;
  margin-bottom: 0.35rem;
}
html.db-edit-active .db-record[data-record-id] [data-field] {
  cursor: pointer;
}
html.db-edit-active .db-record[data-record-id] [data-field]:focus-visible {
  outline: 2px solid rgba(34, 165, 89, 0.75);
  outline-offset: 2px;
}

/* ── Sticky delete buttons (viewport-pinned overlay) ─────────────────── */
.cms-delete-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99990;
}
html.db-edit-active .cms-delete-btn--sticky {
  position: fixed;
  pointer-events: auto;
  z-index: 99991;
}
html.db-edit-active .cms-delete-btn--sticky[hidden] {
  display: none !important;
}
html.db-edit-active .cms-edit-btn--sticky {
  position: fixed;
  pointer-events: auto;
  z-index: 99991;
}
html.db-edit-active .cms-edit-btn--sticky[hidden] {
  display: none !important;
}
html:not(.db-edit-active) .cms-delete-overlay,
html:not(.db-edit-active) .cms-edit-btn--sticky,
html:not(.db-edit-active) .cms-delete-btn--sticky,
html:not(.db-edit-active) [data-cms-delete],
html:not(.db-edit-active) .db-create,
html:not(.db-edit-active) [data-cms-create] {
  display: none !important;
}

/* ── First-run hint banner (top of page, one-time) ───────────────────── */
#cms-first-run-hint {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: #eff6ff;
  border-bottom: 1px solid #93c5fd;
  padding: .45rem 1rem;
  font-size: .85rem;
  color: #1e3a5f;
}
#cms-first-run-hint button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .95rem;
  color: #64748b;
  padding: 0 .15rem;
  line-height: 1;
}
.cms-hint-msg { flex: 1; }

/* ── Inline edit wrap ─────────────────────────────────────────────────── */
.cms-edit-wrap {
  display: block;
  position: relative;
}
.cms-edit-wrap input[type="text"],
.cms-edit-wrap input[type="number"],
.cms-edit-wrap input[type="date"],
.cms-edit-wrap input[type="password"],
.cms-edit-wrap select {
  width: 100%;
  margin-bottom: 0.35rem;
}
.cms-edit-wrap textarea {
  width: 100%;
  min-height: 6rem;
}
.cms-edit-wrap .cms-richtext { min-height: 12rem; }
.cms-edit-wrap [data-db-richtext="1"] { min-width: 0; }

/* ── Save / Cancel buttons ──────────────────────────────────────────── */
.cms-save,
.cms-cancel {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  font-size: 0.82rem;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 0.35rem;
  margin-top: 0.35rem;
  line-height: 1.5;
}
.cms-save {
  background: var(--db-primary-color, #0b69ff);
  color: #fff;
  border: none;
}
.cms-save:hover { opacity: 0.88; }
.cms-save:disabled { opacity: 0.55; cursor: not-allowed; }
.cms-cancel {
  background: none;
  border: 1px solid #ccc;
  color: #555;
}
.cms-cancel:hover { background: #f0f0f0; }

/* ── Status pill (inline near the edited field) ──────────────────────── */
.cms-status-pill {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.8em;
  color: #555;
  vertical-align: middle;
  transition: opacity 0.4s;
}

/* ── Toast notification (bottom-right) ───────────────────────────────── */
.cms-toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 99999;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #1a1a1a;
  color: #fff;
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  font-size: 0.875rem;
  max-width: 26rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.cms-toast-msg { flex: 1; }
.cms-toast-retry {
  background: #0b69ff;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.cms-toast-close {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.1rem;
  flex-shrink: 0;
  line-height: 1;
}

/* ── Draft restore banner (top of page) ─────────────────────────────── */
.cms-draft-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #fffbe6;
  border-bottom: 1px solid #f0c040;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}
.cms-draft-label { flex: 1; }
.cms-draft-restore {
  background: #0b69ff;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
}
.cms-draft-discard {
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
}

/* ── FK autocomplete dropdown ────────────────────────────────────────── */
.cms-autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 999;
  background: #fff;
  border: 1px solid #ccc;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.cms-autocomplete-list li { padding: 4px 8px; cursor: pointer; }
.cms-autocomplete-list li:hover { background: #f0f4ff; }

/* ── Create record dialog ─────────────────────────────────────────── */
.cms-create-trigger {
  margin-top: 0.75rem;
  padding: 0.45rem 0.85rem;
  border-radius: 0.35rem;
  border: 1px dashed rgba(11, 105, 255, 0.45);
  background: rgba(11, 105, 255, 0.06);
  color: var(--db-primary-color, #0b69ff);
  font-weight: 600;
  cursor: pointer;
}

.cms-create-trigger:hover {
  background: rgba(11, 105, 255, 0.12);
}

.cms-create-dialog {
  border: none;
  border-radius: var(--db-radius, 0.5rem);
  padding: 0;
  max-width: min(92vw, 32rem);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

.cms-create-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.cms-create-dialog-form {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
}

.cms-create-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.cms-create-dialog-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.cms-create-dialog-close {
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.65;
  padding: 0.15rem 0.35rem;
}

.cms-create-dialog-close:hover { opacity: 1; }

.cms-create-dialog-body {
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cms-create-dialog-body label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.cms-create-dialog-body input,
.cms-create-dialog-body textarea,
.cms-create-dialog-body select {
  font: inherit;
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 0.35rem;
}

.cms-create-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.cms-create-dialog-body .cms-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

/* ── Admin panel chrome ──────────────────────────────────────────────
 * Admin routes wrap content in `<main class="content db-admin-body">`.
 * Override the dark `.content` theme to keep forms/tables readable.
 * ─────────────────────────────────────────────────────────────────── */
main.content.db-admin-body {
  background: var(--color-bg, #f7f4ef);
  color: var(--color-text, #2a3232);
  box-shadow: none;
  overflow: visible;
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 0;
  min-height: 0;
}

main.content.db-admin-body::before {
  display: none !important;
}

.db-admin-panel {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2.5rem;
  box-sizing: border-box;
}

.db-admin-panel h1:first-child {
  margin: 0 0 0.75rem;
  font-size: 1.75rem;
  color: var(--color-primary, #384848);
}

.db-admin-panel h2 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-primary, #384848);
}

.db-admin-panel p {
  margin: 0.35rem 0;
  line-height: 1.5;
}

.db-admin-panel a:not(.db-btn):not(.db-edit-toggle) {
  color: var(--color-primary, #384848);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.db-admin-panel a:not(.db-btn):not(.db-edit-toggle):hover {
  color: var(--color-accent, #a89868);
}

.db-admin-panel .db-listing table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
}

.db-admin-panel .db-listing th,
.db-admin-panel .db-listing td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
  text-align: left;
  vertical-align: top;
}
