/* ==========================================================================
   Modern Lightweight Summernote & Rich Text Editor Stylesheet
   Self-contained, zero-dependency, modern UI with Dark Mode support
   ========================================================================== */

:root {
  --sn-border: #e2e8f0;
  --sn-border-focus: #3b82f6;
  --sn-bg-toolbar: #f8fafc;
  --sn-bg-editor: #ffffff;
  --sn-bg-btn: #ffffff;
  --sn-bg-btn-hover: #f1f5f9;
  --sn-bg-btn-active: #e2e8f0;
  --sn-text-main: #1e293b;
  --sn-text-muted: #64748b;
  --sn-text-placeholder: #94a3b8;
  --sn-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --sn-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --sn-radius: 8px;
  --sn-radius-sm: 4px;
}

.dark {
  --sn-border: #334155;
  --sn-border-focus: #60a5fa;
  --sn-bg-toolbar: #0f172a;
  --sn-bg-editor: #1e293b;
  --sn-bg-btn: #1e293b;
  --sn-bg-btn-hover: #334155;
  --sn-bg-btn-active: #475569;
  --sn-text-main: #f1f5f9;
  --sn-text-muted: #94a3b8;
  --sn-text-placeholder: #64748b;
}

/* Base Editor Container */
.summernote-editor,
.note-editor,
.rich-editor-wrapper {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--sn-border);
  border-radius: var(--sn-radius);
  background: var(--sn-bg-editor);
  overflow: hidden;
  box-shadow: var(--sn-shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Kantumruy Pro", "Siemreap";
  position: relative;
  width: 100%;
}

.summernote-editor:focus-within,
.note-editor:focus-within {
  border-color: var(--sn-border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Fullscreen Mode */
.summernote-editor.is-fullscreen,
.note-editor.is-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 99999 !important;
  border-radius: 0 !important;
  border: none !important;
}

/* Toolbar */
.summernote-toolbar,
.note-toolbar,
.rich-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background-color: var(--sn-bg-toolbar);
  border-bottom: 1px solid var(--sn-border);
  user-select: none;
  z-index: 10;
}

.summernote-toolbar-group,
.note-btn-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: transparent;
  border-radius: var(--sn-radius-sm);
}

.note-divider {
  width: 1px;
  height: 20px;
  background-color: var(--sn-border);
  margin: 0 4px;
  display: inline-block;
}

/* Buttons */
.note-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--sn-text-main);
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: var(--sn-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
}

.note-btn:hover {
  background-color: var(--sn-bg-btn-hover);
  color: var(--sn-text-main);
}

.note-btn:active,
.note-btn.is-active {
  background-color: var(--sn-bg-btn-active);
  color: var(--sn-border-focus);
}

.note-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.note-btn svg,
.note-btn i {
  width: 14px;
  height: 14px;
  pointer-events: none;
}

/* Select Dropdowns */
.note-select {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
  color: var(--sn-text-main);
  background-color: var(--sn-bg-btn);
  border: 1px solid var(--sn-border);
  border-radius: var(--sn-radius-sm);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.note-select:focus {
  border-color: var(--sn-border-focus);
}

/* Custom Action Buttons */
.note-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--sn-radius-sm);
  cursor: pointer;
  border: none;
  transition: opacity 0.15s ease, transform 0.05s ease;
}

.note-action-btn:active {
  transform: scale(0.97);
}

.note-action-btn.btn-green {
  background-color: #10b981;
  color: #ffffff;
}
.note-action-btn.btn-green:hover {
  background-color: #059669;
}

.note-action-btn.btn-blue {
  background-color: #3b82f6;
  color: #ffffff;
}
.note-action-btn.btn-blue:hover {
  background-color: #2563eb;
}

.note-action-btn.btn-gold {
  background-color: #f59e0b;
  color: #ffffff;
}
.note-action-btn.btn-gold:hover {
  background-color: #d97706;
}

.note-action-btn.btn-outline {
  background-color: transparent;
  border: 1px solid var(--sn-border);
  color: var(--sn-text-main);
}
.note-action-btn.btn-outline:hover {
  background-color: var(--sn-bg-btn-hover);
}

/* Dropdown Menu */
.note-dropdown {
  position: relative;
  display: inline-block;
}

.note-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  background-color: var(--sn-bg-editor);
  border: 1px solid var(--sn-border);
  border-radius: var(--sn-radius);
  box-shadow: var(--sn-shadow-md);
  padding: 4px;
  min-width: 140px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.note-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--sn-text-main);
  border-radius: var(--sn-radius-sm);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.note-dropdown-item:hover {
  background-color: var(--sn-bg-btn-hover);
}

/* Color Palette Swatch */
.note-color-palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 6px;
  min-width: 160px;
}

.note-color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.note-color-swatch:hover {
  transform: scale(1.15);
  box-shadow: 0 0 4px rgba(0,0,0,0.3);
}

/* Content Editable Area */
.summernote-content,
.note-editable,
.rich-editor-content {
  flex: 1 1 auto;
  padding: 16px;
  min-height: 200px;
  outline: none;
  overflow-y: auto;
  color: var(--sn-text-main);
  background-color: var(--sn-bg-editor);
  font-size: 14px;
  line-height: 1.6;
}

.summernote-content[data-placeholder]:empty:before,
.note-editable[data-placeholder]:empty:before {
  content: attr(data-placeholder);
  color: var(--sn-text-placeholder);
  pointer-events: none;
  display: block;
}

/* Typography Inside Content */
.summernote-content h1, .note-editable h1 { font-size: 1.75rem; font-weight: 700; margin: 0.8rem 0 0.4rem; color: var(--sn-text-main); }
.summernote-content h2, .note-editable h2 { font-size: 1.45rem; font-weight: 700; margin: 0.7rem 0 0.35rem; color: var(--sn-text-main); }
.summernote-content h3, .note-editable h3 { font-size: 1.25rem; font-weight: 600; margin: 0.6rem 0 0.3rem; color: var(--sn-text-main); }
.summernote-content h4, .note-editable h4 { font-size: 1.1rem; font-weight: 600; margin: 0.5rem 0 0.25rem; color: var(--sn-text-main); }
.summernote-content p, .note-editable p { margin-bottom: 0.75rem; }

.summernote-content ul, .note-editable ul {
  list-style-type: disc;
  margin: 0.5rem 0 0.75rem 1.5rem;
}

.summernote-content ol, .note-editable ol {
  list-style-type: decimal;
  margin: 0.5rem 0 0.75rem 1.5rem;
}

.summernote-content li, .note-editable li {
  margin-bottom: 0.25rem;
}

.summernote-content blockquote, .note-editable blockquote {
  border-left: 4px solid var(--sn-border-focus);
  padding: 8px 16px;
  margin: 12px 0;
  color: var(--sn-text-muted);
  background: var(--sn-bg-toolbar);
  border-radius: 0 var(--sn-radius-sm) var(--sn-radius-sm) 0;
  font-style: italic;
}

.summernote-content hr, .note-editable hr {
  border: 0;
  height: 1px;
  background: var(--sn-border);
  margin: 16px 0;
}

/* Tables inside content */
.summernote-content table, .note-editable table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
}

.summernote-content th, .note-editable th,
.summernote-content td, .note-editable td {
  border: 1px solid var(--sn-border);
  padding: 8px 12px;
  text-align: left;
}

.summernote-content th, .note-editable th {
  background-color: var(--sn-bg-toolbar);
  font-weight: 600;
}

/* Images inside editor */
.summernote-content img, .note-editable img {
  max-width: 100%;
  height: auto;
  border-radius: var(--sn-radius-sm);
  margin: 8px 0;
  display: inline-block;
  cursor: pointer;
  transition: outline 0.15s ease;
}

.summernote-content img:hover, .note-editable img:hover {
  outline: 2px solid var(--sn-border-focus);
}

.summernote-content .img-float-left, .note-editable .img-float-left {
  float: left;
  margin: 0 16px 12px 0;
  max-width: 45%;
}

.summernote-content .img-float-right, .note-editable .img-float-right {
  float: right;
  margin: 0 0 12px 16px;
  max-width: 45%;
}

.summernote-content .img-center, .note-editable .img-center {
  display: block;
  margin: 12px auto;
  text-align: center;
}

/* Multi-image grid */
.summernote-content .image-grid-2, .note-editable .image-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 12px 0;
}

.summernote-content .image-grid-3, .note-editable .image-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 12px 0;
}

/* Callout Boxes */
.summernote-content .callout-box, .note-editable .callout-box {
  padding: 12px 16px;
  border-radius: var(--sn-radius);
  margin: 14px 0;
  border-left: 4px solid #3b82f6;
  background-color: rgba(59, 130, 246, 0.08);
}

.summernote-content .callout-box.info, .note-editable .callout-box.info {
  border-left-color: #3b82f6;
  background-color: rgba(59, 130, 246, 0.08);
}

.summernote-content .callout-box.success, .note-editable .callout-box.success {
  border-left-color: #10b981;
  background-color: rgba(16, 185, 129, 0.08);
}

.summernote-content .callout-box.warning, .note-editable .callout-box.warning {
  border-left-color: #f59e0b;
  background-color: rgba(245, 158, 11, 0.08);
}

/* Raw HTML Code View */
.summernote-code-view,
.note-codable {
  display: block;
  width: 100%;
  flex: 1 1 auto;
  min-height: 200px;
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #38bdf8;
  background-color: #0f172a;
  border: none;
  outline: none;
  resize: vertical;
}

/* Status Bar & Word Counter */
.summernote-statusbar,
.note-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  background-color: var(--sn-bg-toolbar);
  border-top: 1px solid var(--sn-border);
  font-size: 11px;
  color: var(--sn-text-muted);
}

.summernote-word-count {
  font-size: 11px;
  color: var(--sn-text-muted);
}

/* Modal Dialog for Links / Images */
.note-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  backdrop-filter: blur(2px);
}

.note-modal {
  background: var(--sn-bg-editor);
  border: 1px solid var(--sn-border);
  border-radius: var(--sn-radius);
  padding: 20px;
  width: 90%;
  max-width: 480px;
  box-shadow: var(--sn-shadow-md);
  color: var(--sn-text-main);
}

.note-modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
}

.note-modal-body {
  margin-bottom: 16px;
}

.note-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .summernote-toolbar {
    padding: 4px;
    gap: 2px;
  }
  .note-btn {
    min-width: 26px;
    height: 26px;
    padding: 0 4px;
  }
  .summernote-content {
    padding: 10px;
  }
}
