/* ============================================================
   ContentEditor – Core Styles
   Drop-in compatible with Bootstrap. All classes are namespaced
   with .ce- to avoid conflicts.
   ============================================================ */

/* ── Wrapper ─────────────────────────────────────────────── */
.ce-wrapper {
  display: flex;
  flex-direction: column;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background: #fff;
  font-family: inherit;
  box-sizing: border-box;
  position: relative;
}

.ce-wrapper:focus-within {
  border-color: #86b7fe;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.18);
  outline: none;
}

/* ── Toolbar ─────────────────────────────────────────────── */
.ce-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  background: #f8f9fa;
  border-bottom: 1px solid #dee2e6;
  border-radius: 4px 4px 0 0;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Toolbar buttons ─────────────────────────────────────── */
.ce-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  color: #495057;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  flex-shrink: 0;
}

.ce-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  pointer-events: none;
}

.ce-btn:hover {
  background: #e9ecef;
  border-color: #dee2e6;
  color: #212529;
}

.ce-btn:active {
  background: #dee2e6;
}

.ce-btn--active {
  background: #d0e4ff;
  border-color: #86b7fe;
  color: #0d6efd;
}

.ce-btn:focus-visible {
  outline: 2px solid #86b7fe;
  outline-offset: 1px;
}

/* ── Dictation (recording state) ─────────────────────────── */
.ce-btn--recording {
  background: #fee2e2;
  border-color: #ef4444;
  color: #dc2626;
  animation: ce-pulse 1.2s ease-in-out infinite;
}

.ce-btn--recording:hover {
  background: #fecaca;
  border-color: #dc2626;
  color: #b91c1c;
}

@keyframes ce-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}

.ce-dictation-interim {
  color: #9ca3af;
  font-style: italic;
}

/* ── Toolbar separator ───────────────────────────────────── */
.ce-toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 22px;
  background: #dee2e6;
  margin: 0 4px;
  flex-shrink: 0;
}

/* ── Select dropdowns ────────────────────────────────────── */
.ce-select-wrap {
  display: inline-flex;
  align-items: center;
}

.ce-select {
  height: 30px;
  padding: 0 6px;
  border: 1px solid #ced4da;
  border-radius: 3px;
  background: #fff;
  font-size: 12px;
  color: #495057;
  cursor: pointer;
  max-width: 110px;
  transition: border-color 0.12s;
}

.ce-select:hover {
  border-color: #adb5bd;
}

.ce-select:focus {
  outline: none;
  border-color: #86b7fe;
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.15);
}

/* ── Editor body ─────────────────────────────────────────── */
.ce-body {
  flex: 1;
  min-height: 200px;
  padding: 14px 16px;
  outline: none;
  overflow-y: auto;
  line-height: 1.6;
  color: #212529;
  font-size: 16px;
  word-wrap: break-word;
  box-sizing: border-box;
}

.ce-body:empty:before {
  content: attr(data-placeholder);
  color: #adb5bd;
  pointer-events: none;
}

/* ── Content typography ──────────────────────────────────── */
.ce-body h1,
.ce-body h2,
.ce-body h3,
.ce-body h4,
.ce-body h5,
.ce-body h6 {
  margin-top: 0.75em;
  margin-bottom: 0.4em;
  font-weight: 600;
  line-height: 1.25;
}

.ce-body h1 { font-size: 2em; }
.ce-body h2 { font-size: 1.6em; }
.ce-body h3 { font-size: 1.3em; }

.ce-body p {
  margin-top: 0;
  margin-bottom: 0.75em;
}

.ce-body ul,
.ce-body ol {
  padding-left: 1.6em;
  margin-bottom: 0.75em;
}

.ce-body li {
  margin-bottom: 0.25em;
}

.ce-body blockquote {
  margin: 0.75em 0;
  padding: 8px 16px;
  border-left: 4px solid #0d6efd;
  background: #f0f4ff;
  color: #495057;
  border-radius: 0 4px 4px 0;
}

.ce-body code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.88em;
  background: #f1f3f5;
  border: 1px solid #dee2e6;
  border-radius: 3px;
  padding: 1px 5px;
  color: #c7254e;
}

.ce-body pre {
  background: #1e1e2e;
  color: #cdd6f4;
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  margin-bottom: 0.75em;
  font-size: 0.88em;
}

.ce-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.ce-body a {
  color: #0d6efd;
  text-decoration: underline;
}

.ce-body a:hover {
  color: #0a58ca;
}

.ce-body hr {
  border: none;
  border-top: 2px solid #dee2e6;
  margin: 1em 0;
}

.ce-body table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 0.75em;
}

.ce-body th,
.ce-body td {
  border: 1px solid #dee2e6;
  padding: 8px 12px;
  text-align: left;
}

.ce-body th {
  background: #f8f9fa;
  font-weight: 600;
}

.ce-body tr:nth-child(even) td {
  background: #f8f9fa;
}

/* ── Images ──────────────────────────────────────────────── */
.ce-body img,
.ce-img {
  max-width: 100%;
  height: auto;
  border-radius: 3px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.ce-img--selected {
  box-shadow: 0 0 0 3px #0d6efd;
  outline: none;
}

/* ── Image resize overlay ────────────────────────────────── */
.ce-img-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 10;
}

.ce-img-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #0d6efd;
  border: 2px solid #fff;
  border-radius: 2px;
  pointer-events: all;
  z-index: 11;
}

.ce-img-handle--nw { top: -5px;  left: -5px;  cursor: nw-resize; }
.ce-img-handle--ne { top: -5px;  right: -5px; cursor: ne-resize; }
.ce-img-handle--sw { bottom: -5px; left: -5px;  cursor: sw-resize; }
.ce-img-handle--se { bottom: -5px; right: -5px; cursor: se-resize; }

/* ── Status bar ──────────────────────────────────────────── */
.ce-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  font-size: 11px;
  color: #868e96;
  background: #f8f9fa;
  border-top: 1px solid #dee2e6;
  border-radius: 0 0 4px 4px;
  user-select: none;
}

.ce-statusbar-wordcount {
  font-variant-numeric: tabular-nums;
}

/* ── Modal overlay ───────────────────────────────────────── */
.ce-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ce-fade-in 0.15s ease;
}

@keyframes ce-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.ce-modal {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
  min-width: 340px;
  max-width: 520px;
  width: 90%;
  animation: ce-slide-up 0.18s ease;
  overflow: hidden;
}

@keyframes ce-slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.ce-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #dee2e6;
  font-weight: 600;
  font-size: 15px;
  color: #212529;
}

.ce-modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #868e96;
  padding: 0 4px;
  border-radius: 3px;
  transition: color 0.1s;
}

.ce-modal-close:hover {
  color: #212529;
}

.ce-modal-body {
  padding: 18px;
}

.ce-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid #dee2e6;
  background: #f8f9fa;
}

/* ── Modal form elements ─────────────────────────────────── */
.ce-form-group {
  margin-bottom: 14px;
}

.ce-form-group:last-child {
  margin-bottom: 0;
}

.ce-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #495057;
  margin-bottom: 5px;
}

.ce-input,
.ce-select-full {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #ced4da;
  border-radius: 4px;
  font-size: 14px;
  color: #212529;
  background: #fff;
  box-sizing: border-box;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.ce-input:focus,
.ce-select-full:focus {
  outline: none;
  border-color: #86b7fe;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.18);
}

.ce-tabs {
  display: flex;
  border-bottom: 1px solid #dee2e6;
  margin-bottom: 14px;
}

.ce-tab {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: #868e96;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
}

.ce-tab:hover {
  color: #495057;
}

.ce-tab--active {
  color: #0d6efd;
  border-bottom-color: #0d6efd;
}

.ce-tab-panel {
  display: none;
}

.ce-tab-panel--active {
  display: block;
}

/* ── Buttons (modal actions) ─────────────────────────────── */
.ce-action-btn {
  display: inline-flex;
  align-items: center;
  padding: 7px 16px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.ce-action-btn--primary {
  background: #0d6efd;
  color: #fff;
  border-color: #0d6efd;
}

.ce-action-btn--primary:hover {
  background: #0b5ed7;
  border-color: #0a58ca;
}

.ce-action-btn--secondary {
  background: #fff;
  color: #495057;
  border-color: #ced4da;
}

.ce-action-btn--secondary:hover {
  background: #f8f9fa;
  border-color: #adb5bd;
}

/* ── Color picker ────────────────────────────────────────── */
.ce-color-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}

.ce-color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.1s;
}

.ce-color-swatch:hover {
  transform: scale(1.2);
  border-color: #212529;
}

.ce-color-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.ce-color-custom input[type="color"] {
  width: 36px;
  height: 30px;
  border: 1px solid #ced4da;
  border-radius: 4px;
  cursor: pointer;
  padding: 2px;
}

/* ── Upload drop zone ────────────────────────────────────── */
.ce-dropzone {
  border: 2px dashed #ced4da;
  border-radius: 6px;
  padding: 24px;
  text-align: center;
  color: #868e96;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.ce-dropzone:hover,
.ce-dropzone--over {
  border-color: #0d6efd;
  background: #f0f4ff;
  color: #0d6efd;
}

.ce-dropzone input[type="file"] {
  display: none;
}

/* ── Toolbar spacer (pushes brand to far right) ──────────── */
.ce-toolbar-spacer {
  flex: 1;
}

/* ── MEK brand badge ─────────────────────────────────────── */
.ce-brand {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: 4px;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}

.ce-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: block;
}

.ce-brand-icon rect {
  fill: #0d6efd;
  transition: fill 0.15s;
}

.ce-brand:hover .ce-brand-icon rect {
  fill: #0b5ed7;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 576px) {
  .ce-toolbar {
    gap: 1px;
    padding: 4px 6px;
  }

  .ce-btn {
    width: 26px;
    height: 26px;
  }

  .ce-btn svg {
    width: 15px;
    height: 15px;
  }

  .ce-select {
    max-width: 80px;
    font-size: 11px;
  }

  .ce-modal {
    min-width: unset;
    width: 95%;
  }

  .ce-input,
  .ce-select-full {
    font-size: 16px;
  }
}
