/* Basic Styles & Theme */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Modern color variables */
:root {
  /* Modern color scheme - refined palette */
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #ec4899;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --border-radius: 10px;
  --transition-speed: 0.2s;
  --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

body {
  --bg-body: #f0f7ff;
  --text-body: #2b3a67;
  --bg-paper: #ffffff;
  --text-editor: #2b3a67;
  --toolbar-bg: linear-gradient(to right, #f8f9ff, #f0f7ff);
  --toolbar-border: #d4e4fa;
  --toolbar-btn-bg: #ebf5ff;
  --toolbar-btn-hover: #dcebff;
  --settings-bg: #ffffff;
  --settings-text: #2b3a67;
  --settings-border: #d4e4fa;
  --settings-tab-active: #3b82f6;
  --settings-tab-inactive: #f1f5f9;
  --settings-input-bg: #ffffff;
  --settings-input-border: #e2e8f0;
  --settings-btn-primary: #3b82f6;
  --settings-btn-danger: #ef4444;
  --shape-option-bg: #f8fafc;
  --shape-option-active: #3b82f6;
  --shape-option-text: #2b3a67;
  --shape-option-active-text: #ffffff;
  font-family: 'DM Sans', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-body);
  color: var(--text-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: background 0.3s, color 0.3s;
  position: relative;
  padding-bottom: 50px;
}

body.dark {
  --bg-body: #0f172a;
  --text-body: #f1f5f9;
  --bg-paper: #1e293b;
  --text-editor: #f1f5f9;
  --toolbar-bg: #1e293b;
  --toolbar-border: #334155;
  /* Dark mode settings panel */
  --settings-bg: #1e293b;
  --settings-text: #f1f5f9;
  --settings-border: #334155;
  --settings-tab-active: #3b82f6;
  --settings-tab-inactive: #334155;
  --settings-input-bg: #0f172a;
  --settings-input-border: #475569;
  --shape-option-bg: #334155;
  --shape-option-active: #3b82f6;
  --shape-option-text: #f1f5f9;
  --shape-option-active-text: #ffffff;
  /* Override custom buttons for better visibility in dark mode */
  --toolbar-btn-bg: #334155;
  --toolbar-btn-hover: #475569;
}

/* Top Bar */
.top-bar {
  width: 100%;
  padding: 14px 28px;
  background: var(--toolbar-bg);
  color: var(--text-body);
  border-bottom: 1px solid var(--toolbar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--box-shadow);
}

.top-bar h1 {
  font-size: 1.6rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--primary);
  display: flex;
  align-items: center;
  font-weight: 700;
  letter-spacing: -0.5px;
  gap: 10px;
}

.top-bar h1 i {
  font-size: 1.8rem;
  color: var(--primary);
}

.top-bar .buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.top-bar button {
  cursor: pointer;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--border-radius);
  transition: all var(--transition-speed);
  font-weight: 500;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.top-bar button:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

/* Toolbar Wrapper */
.toolbar-wrapper {
  width: 100%;
  max-width: 1240px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--toolbar-border);
  border-radius: 12px;
  margin: 10px auto 25px auto;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: sticky;
  top: 10px;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.02);
}

body.dark .toolbar-wrapper {
  background: rgba(30, 41, 59, 0.85);
  border-color: rgba(255, 255, 255, 0.08);
}

#toolbar {
  display: flex;
  padding: 8px 15px;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 44px;
}

/* Toolbar Divider - more subtle and modern */
.toolbar-divider {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: linear-gradient(to bottom, transparent, var(--toolbar-border), transparent);
  margin: 0 6px;
  opacity: 0.6;
  vertical-align: middle;
}

/* Style for button groups in toolbar */
#toolbar .ql-formats {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 2px;
}

.action-group,
.custom-group {
  display: flex;
  gap: 3px;
  margin: 0;
  align-items: center;
}

/* Toolbar buttons styling - refined and smaller */
#toolbar button,
.custom-btn {
  background: var(--toolbar-btn-bg);
  color: var(--text-body);
  border: 1px solid transparent;
  margin: 0;
  padding: 5px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 6px;
  height: 28px;
  width: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

#toolbar button:hover,
.custom-btn:hover {
  background: var(--toolbar-btn-hover);
  border-color: var(--toolbar-border);
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

#toolbar button.active,
#toolbar button.ql-active,
.custom-btn.active {
  background: var(--primary);
  color: white !important;
  border-color: var(--primary-hover);
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

.custom-btn {
  width: auto;
  padding: 0 8px;
  background: var(--primary);
  color: white;
}

/* Ensure icons are crisp and correctly sized */
#toolbar button i,
.custom-btn i {
  font-size: 13px;
  line-height: 1;
}

/* Native select elements in toolbar - refined */
#toolbar select {
  margin: 0 4px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--toolbar-border);
  background: var(--toolbar-btn-bg);
  color: var(--text-body);
  height: 28px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

#toolbar select:hover {
  background: var(--toolbar-btn-hover);
  border-color: var(--primary);
}

/* Specific widths for different pickers */
#toolbar .ql-font {
  width: 130px;
}

#toolbar .ql-size {
  width: 80px;
}

#toolbar .ql-header {
  width: 110px;
}

#toolbar .ql-align,
#toolbar #alignSelect {
  width: 80px;
}

/* Color pickers - refined */
#toolbar input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 3px;
  border: 1px solid var(--toolbar-border);
  border-radius: 6px;
  background: var(--toolbar-btn-bg);
  cursor: pointer;
  transition: all 0.2s;
}

#toolbar input[type="color"]:hover {
  background: var(--toolbar-btn-hover);
  border-color: var(--primary);
}

/* Custom Tools Styling - merged with general button styles */
/* Divider handling is now done via .toolbar-divider span for consistency */


/* A4 "Paper" */
.paper {
  position: relative;
  width: 210mm;
  /* Width of A4 */
  min-height: 297mm;
  /* Basic height of A4 */
  margin: 0 auto 20px;
  color: var(--text-editor);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.06),
    0 8px 24px rgba(0, 0, 0, 0.08),
    0 24px 48px rgba(0, 0, 0, 0.04);
  transition: background 0.3s, color 0.3s;
  border-radius: 2px;

  /* 1) basic background color */
  background-color: var(--bg-paper);
  background-image: repeating-linear-gradient(to bottom,
      transparent 0 296mm,
      rgba(239, 68, 68, 0.15) 296mm 297mm);
}

.dynamic-height {
  height: auto !important;
  min-height: 0 !important;
  overflow: visible !important;
}

/* Remove scrollbars inside the editor */
#editor {
  overflow: hidden !important;
  border: none !important;
  min-height: 274mm;
  outline: none;
}

/* Fix visibility of lists due to global reset */
#editor ul,
#editor ol {
  padding-left: 2em;
  margin: 0.5em 0 1em 0;
}

#editor li {
  margin-bottom: 0.25em;
  padding-left: 0.25em;
}

/* Video Embedding Styles */
.video-container {
  position: relative;
  width: 100%;
  max-width: 640px;
  margin: 20px auto;
  aspect-ratio: 16 / 9;
  background-color: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}


/* Table Styles in Editor */
#editor table {
  width: 100%;
  /* Default width */
  max-width: 100%;
  border-collapse: collapse;
  /* Better for resizing */
  border-spacing: 0;
  margin: 16px 0;
  border: 1px solid var(--settings-input-border);
  table-layout: fixed;
  /* Essential for column resizing */
  position: relative;
}

.table-selected {
  outline: 2px solid var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Resize Handles */
.table-resizer-col {
  position: absolute;
  top: 0;
  width: 5px;
  cursor: col-resize;
  background-color: transparent;
  z-index: 20;
  height: 100%;
}

.table-resizer-col:hover,
.table-resizer-col.resizing {
  background-color: var(--primary);
  opacity: 0.5;
}

.table-resizer-row {
  position: absolute;
  left: 0;
  height: 5px;
  cursor: row-resize;
  background-color: transparent;
  z-index: 20;
  width: 100%;
}

.table-resizer-row:hover,
.table-resizer-row.resizing {
  background-color: var(--primary);
  opacity: 0.5;
}


#editor th,
#editor td {
  border: 1px solid var(--settings-input-border);
  padding: 12px;
  min-width: 40px;
  word-wrap: break-word;
  transition: background 0.2s;
}

#editor th {
  background: rgba(0, 0, 0, 0.02);
  font-weight: 700;
  text-align: left;
}

body.dark #editor th {
  background: rgba(255, 255, 255, 0.05);
}

#editor td:hover {
  background: rgba(59, 130, 246, 0.05);
}

/* Make images in the editor resizable */
#editor img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 10px 0;
  border-radius: 8px;
}

/* Image resize overlay styling */
.image-resize-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 50;
  border: 1px dashed var(--primary);
}

.image-resize-handle {
  background-color: var(--primary);
  border-radius: 50%;
  cursor: nwse-resize;
  pointer-events: all;
  position: absolute;
  bottom: -10px;
  right: -10px;
  width: 20px;
  height: 20px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.image-resize-handle:hover {
  transform: scale(1.2);
}

/* Margin Handles */
.handle {
  position: absolute;
  background: rgba(67, 97, 238, 0.3);
  z-index: 10;
}

#handleTop,
#handleBottom {
  left: 0;
  right: 0;
  height: 2px;
  cursor: row-resize;
}

#handleLeft,
#handleRight {
  top: 0;
  bottom: 0;
  width: 2px;
  cursor: col-resize;
}

/* Editor Container */
#editorContainer {
  position: relative;
  box-sizing: border-box;
}

/* Drawing Canvas */
#drawingCanvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 5;
}

/* Font Size & Family Styles are now handled via inline styles by EditorCore */
/* Removed ql-size and ql-font classes */



/* Shared Panel Base */
.settings-panel {
  background: var(--settings-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  box-shadow:
    0 10px 25px -5px rgba(0, 0, 0, 0.1),
    0 8px 10px -6px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  color: var(--settings-text);
  z-index: 1000;
}

body.dark .settings-panel {
  background: rgba(30, 41, 59, 0.95);
  border-color: rgba(255, 255, 255, 0.05);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
}

@keyframes modalEntry {
  from {
    opacity: 0;
    transform: translate(-50%, -48%) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Settings Panel Specifics */
.settings-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 500px;
  width: 95%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalEntry 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Scrollable content wrapper inside panels */
.panel-content {
  flex: 1;
  overflow-y: auto;
  max-height: calc(80vh - 200px);
  padding: 0;
}

.panel-content .tab-content {
  padding: 20px 24px;
}

.panel-content .tab-content:not(.active) {
  display: none;
}

/* Drawing panel specific sizing */
.drawing-panel {
  max-width: 520px;
}

.settings-panel h2,
.modal-header {
  margin: 0;
  padding: 18px 24px;
  background: transparent;
  color: var(--settings-text);
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--settings-border);
  letter-spacing: -0.01em;
}

.modal-header h2 {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-header h2 i {
  color: var(--primary);
  font-size: 1.1em;
}

/* Tabs Navigation - Premium Look */
.settings-tabs {
  display: flex;
  padding: 8px 16px;
  gap: 8px;
  background: rgba(0, 0, 0, 0.02);
  border-bottom: 1px solid var(--settings-border);
}

.tab-btn {
  padding: 8px 16px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  opacity: 0.7;
}

.tab-btn:hover {
  background: var(--toolbar-btn-hover);
  opacity: 1;
}

.tab-btn.active {
  background: var(--primary);
  color: white;
  opacity: 1;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

/* Tab Content */
.tab-content {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.tab-content label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-body);
  opacity: 0.8;
}

.settings-panel input:not([type="checkbox"]),
.settings-panel select,
.modal-body input:not([type="checkbox"]),
.modal-body select,
.modal-body textarea {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--settings-input-border);
  border-radius: 10px;
  background: var(--settings-input-bg);
  color: var(--settings-text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
}

.settings-panel input:focus,
.settings-panel select:focus,
.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15), inset 0 1px 2px rgba(0, 0, 0, 0.02);
  outline: none;
}

.modal-body textarea {
  resize: vertical;
  min-height: 80px;
}

/* Footer Section - Fixed at bottom */
.settings-footer,
.modal-footer {
  padding: 16px 24px;
  background: var(--settings-bg);
  border-top: 1px solid var(--settings-border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
  flex-shrink: 0;
  margin-top: auto;
}

.modal-footer {
  border-radius: 0 0 20px 20px;
}

/* Modal Overlay */
.modal-panel {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.modal-content {
  width: 480px;
  max-width: 100%;
  position: relative;
  background: var(--settings-bg);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

body.dark .modal-content {
  background: rgba(30, 41, 59, 0.98);
  border-color: rgba(255, 255, 255, 0.05);
}

.modal-body {
  padding: 24px;
}



.close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-body);
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  transition: all 0.2s;
}

.close-btn:hover {
  background: var(--error);
  color: white;
}

/* Button Improvements */
.primary-btn {
  background: var(--primary);
  color: white;
  padding: 10px 20px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid var(--primary-hover);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.primary-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3);
}

.secondary-btn,
.cancel-btn {
  background: var(--toolbar-btn-bg);
  color: var(--text-body);
  padding: 10px 20px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid var(--toolbar-border);
  cursor: pointer;
  transition: all 0.2s ease;
}

body.dark .secondary-btn,
body.dark .cancel-btn {
  background: rgba(255, 255, 255, 0.1);
}

.secondary-btn:hover,
.cancel-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

.danger-btn {
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  padding: 10px 24px;
  border-radius: 12px;
  font-weight: 600;
  border: 1px solid rgba(239, 68, 68, 0.2);
  cursor: pointer;
  transition: all 0.2s;
}

.danger-btn:hover {
  background: var(--error);
  color: white;
}

/* Checkbox Style Improvement */
.checkbox-container,
.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  cursor: pointer;
}

.checkbox-container input[type="checkbox"],
.checkbox-wrapper input[type="checkbox"] {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--settings-input-border);
  border-radius: 6px;
  background: var(--settings-input-bg);
  position: relative;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.checkbox-container input[type="checkbox"]:checked,
.checkbox-wrapper input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.checkbox-container input[type="checkbox"]:checked::after,
.checkbox-wrapper input[type="checkbox"]:checked::after {
  content: '\f00c';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  color: white;
  font-size: 10px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.checkbox-wrapper label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-body);
  cursor: pointer;
}

/* Custom drawing action buttons */
.drawing-actions {
  display: flex;
  gap: 8px;
}

.drawing-actions button {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--settings-border);
  background: var(--settings-input-bg);
  color: var(--text-body);
  cursor: pointer;
  transition: all 0.2s;
}

.drawing-actions button:hover {
  background: var(--toolbar-btn-hover);
  border-color: var(--primary);
  color: var(--primary);
}

/* Table Configuration Layout */
.table-options {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.table-size-inputs {
  display: flex;
  gap: 16px;
}

.table-input-group {
  flex: 1;
}

/* Range Inputs / Sliders */
.slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 20px 0;
}

.slider {
  flex: 1;
  appearance: none;
  height: 6px;
  background: var(--settings-input-border);
  border-radius: 3px;
  outline: none;
}

.slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
  transition: all 0.2s;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 6px rgba(59, 130, 246, 0.2);
}

#penSizeValue,
#penOpacityValue,
#lineSizeValue,
#lineOpacityValue,
#eraserSizeValue,
#shapeStrokeSizeValue {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 45px;
}

/* Shape Grid Selector */
.shape-selector {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.shape-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--settings-input-bg);
  border: 2px solid var(--settings-input-border);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
  gap: 8px;
}

.shape-option i {
  font-size: 1.5rem;
  color: var(--text-body);
}

.shape-option span {
  font-size: 0.8rem;
  font-weight: 600;
}

.shape-option:hover {
  border-color: var(--primary);
  background: var(--toolbar-btn-hover);
}

.shape-option.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.shape-option.active i {
  color: white;
}

/* Mobile & Responsive Styles */
@media (max-width: 768px) {

  /* Top Bar adjustments */
  .top-bar {
    padding: 10px 15px;
    flex-direction: column;
    gap: 10px;
  }

  .top-bar h1 {
    font-size: 1.4rem;
    width: 100%;
    justify-content: center;
  }

  .top-bar .buttons {
    width: 100%;
    justify-content: center;
    gap: 8px;
  }

  .top-bar button {
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  /* Toolbar adjustments */
  .toolbar-wrapper {
    width: 100%;
    margin: 0 0 10px 0;
    border-radius: 0;
    overflow-x: auto;
    /* Allow horizontal scrolling for toolbar if needed */
    max-width: none;
  }

  #toolbar {
    width: 100%;
    padding: 8px 5px;
    justify-content: flex-start;
    /* Align left to allow scrolling */
    min-height: auto;
    flex-wrap: wrap;
    /* Allow wrapping */
  }

  /* Adjust individual tool groups for touch targets */
  .custom-btn,
  .action-group button,
  #toolbar button {
    margin: 1px;
  }

  /* Hide dividers on very small screens to save space */
  .toolbar-divider {
    margin: 0 2px;
  }

  /* Paper adjustments */
  .paper {
    width: 100%;
    margin: 0;
    box-shadow: none;
    border-radius: 0;
    min-height: calc(100vh - 150px);
  }

  /* Adjust select elements for mobile */
  #toolbar select {
    font-size: 12px;
  }

  #toolbar .ql-font {
    width: 100px;
  }

  #toolbar .ql-size {
    width: 60px;
  }

  #toolbar .ql-header {
    width: 90px;
  }
}

/* ==================== LaTeX Formula Styles ==================== */

/* LaTeX Modal specific styles */
.latex-modal .modal-content {
  max-width: 580px;
}

.latex-input-section textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.latex-size-section {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.latex-size-section label {
  font-weight: 600;
  font-size: 0.85rem;
  opacity: 0.8;
}

.latex-size-section select {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--settings-input-border);
  background-color: var(--settings-input-bg);
  color: var(--settings-text);
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: all 0.2s;
}

.latex-size-section select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.latex-preview-section {
  margin-bottom: 24px;
}

.latex-preview-section label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  opacity: 0.8;
}

.latex-preview {
  min-height: 100px;
  padding: 20px;
  background-color: rgba(0, 0, 0, 0.02);
  border: 1px solid var(--settings-input-border);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: auto;
}

body.dark .latex-preview {
  background-color: rgba(255, 255, 255, 0.02);
}

.latex-preview .placeholder {
  color: var(--text-body);
  opacity: 0.4;
  font-style: italic;
  font-size: 0.9rem;
}

.latex-preview .error {
  color: var(--error);
  font-size: 0.85rem;
  font-weight: 500;
}

/* KaTeX rendered formula styling in preview */
.latex-preview .katex {
  font-size: 1.6em;
}

.latex-examples {
  margin-bottom: 24px;
}

.example-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.latex-example-btn {
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  background-color: var(--toolbar-btn-bg);
  color: var(--text-body);
  border: 1px solid var(--toolbar-border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.latex-example-btn:hover {
  background-color: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

/* LaTeX formula in editor */
.latex-formula {
  position: relative;
  display: inline-block;
  padding: 2px 4px;
  margin: 2px 4px;
  background-color: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  vertical-align: middle;
}

.latex-formula:hover {
  background-color: rgba(59, 130, 246, 0.1);
  outline: 1px dashed var(--primary);
}

.latex-formula:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* KaTeX formula styling in editor - size comes from inline style */
.latex-formula .katex {
  font-size: inherit;
}

.latex-error {
  color: var(--error);
  font-size: 12px;
  font-style: italic;
}

/* Dark mode adjustments for LaTeX */
body.dark .latex-formula {
  background-color: transparent;
}

body.dark .latex-formula:hover {
  background-color: rgba(59, 130, 246, 0.15);
}

/* Tooltip for formula editing hint */
.latex-formula::after {
  content: 'Double-click to edit';
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  padding: 6px 12px;
  background-color: #1e293b;
  color: white;
  font-size: 10px;
  font-weight: 600;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}


/* ==================== AI Assistant Styles ==================== */
.ai-panel {
  display: none;
  flex-direction: column;
  position: fixed;
  bottom: 80px;
  right: 30px;
  width: 380px;
  height: 520px;
  min-width: 300px;
  min-height: 350px;
  max-width: 90vw;
  max-height: 85vh;
  background: var(--settings-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--toolbar-border);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
  z-index: 1500;
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  opacity: 0;
  transform: translateY(20px) scale(0.98);
  resize: both;
}

.ai-panel.visible {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
}

.ai-header-alt {
  padding: 14px 20px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(168, 85, 247, 0.08));
  border-bottom: 1px solid var(--toolbar-border);
  cursor: move;
}

.ai-header-alt h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-header-alt h3 i {
  color: #8b5cf6;
}

.close-btn-small {
  background: rgba(0, 0, 0, 0.05);
  border: none;
  color: var(--text-body);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.close-btn-small:hover {
  background: var(--error);
  color: white;
}

.ai-chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-message {
  padding: 12px 16px;
  border-radius: 14px;
  max-width: 85%;
  font-size: 0.9rem;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
  position: relative;
  word-wrap: break-word;
}

.ai-message.system,
.ai-message.assistant {
  background: rgba(99, 102, 241, 0.08);
  color: var(--text-body);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.ai-message.user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

/* AI Message Content Formatting */
.message-content h1,
.message-content h2,
.message-content h3 {
  margin: 15px 0 8px 0;
  line-height: 1.2;
}

.message-content h1 {
  font-size: 1.4rem;
}

.message-content h2 {
  font-size: 1.25rem;
}

.message-content h3 {
  font-size: 1.1rem;
}

.message-content h4,
.message-content h5,
.message-content h6 {
  margin: 12px 0 6px 0;
  font-size: 1rem;
}

.message-content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 15px 0;
  border: 1px solid var(--toolbar-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--settings-input-bg);
}

.message-content th,
.message-content td {
  padding: 10px 12px;
  border: 1px solid var(--toolbar-border);
  text-align: left;
}

.message-content th {
  background: rgba(0, 0, 0, 0.05);
  font-weight: 700;
  color: var(--text-header);
}

.message-content blockquote {
  border-left: 4px solid var(--primary);
  padding: 8px 15px;
  margin: 15px 0;
  background: rgba(59, 130, 246, 0.05);
  border-radius: 0 8px 8px 0;
  font-style: italic;
}

.message-content ul,
.message-content ol {
  padding-left: 20px;
  margin: 10px 0;
}

.message-content li {
  margin-bottom: 5px;
}

.message-content code {
  font-family: 'Fira Code', 'Courier New', monospace;
  background: rgba(0, 0, 0, 0.08);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

body.dark .message-content code {
  background: rgba(255, 255, 255, 0.1);
}

.ai-input-area {
  padding: 16px;
  background: var(--settings-bg);
  border-top: 1px solid var(--toolbar-border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ai-input-area textarea {
  flex: 1;
  background: var(--settings-input-bg);
  border: 1px solid var(--toolbar-border);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--text-body);
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
  max-height: 120px;
  transition: all 0.2s;
  outline: none;
}

.ai-input-area textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#aiSendBtn {
  background: var(--primary);
  color: white;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

#aiSendBtn:hover {
  background: var(--primary-hover);
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

/* Typing Indicator */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-body);
  border-radius: 50%;
  opacity: 0.4;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typingBounce {

  0%,
  80%,
  100% {
    transform: scale(0);
  }

  40% {
    transform: scale(1);
  }
}

/* Dark Mode Overrides */
body.dark .ai-message.system,
body.dark .ai-message.assistant {
  background: rgba(255, 255, 255, 0.05);
}

body.dark .close-btn-small:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* AI Tips Styling */
.ai-tips-container {
  margin-top: 10px;
  font-size: 0.85rem;
  border-top: 1px solid var(--settings-border);
  padding-top: 10px;
}

.ai-tips details {
  background: rgba(0, 0, 0, 0.03);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--settings-border);
}

.ai-tips summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  /* Hide default triangle */
}

.ai-tips summary::after {
  content: '+';
  font-weight: bold;
}

.ai-tips details[open] summary::after {
  content: '-';
}

.ai-tips ul {
  margin: 8px 0 0 0;
  padding-left: 20px;
  color: var(--text-body);
}

.ai-tips li {
  margin-bottom: 4px;
}

.ai-tips code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
}

body.dark .ai-tips details {
  background: rgba(255, 255, 255, 0.05);
}

body.dark .ai-tips code {
  background: rgba(255, 255, 255, 0.1);
}

/* Color Theme Sub-tabs in Settings */
.color-theme-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 12px;
}

body.dark .color-theme-tabs {
  background: rgba(255, 255, 255, 0.05);
}

.theme-tab-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0.6;
}

.theme-tab-btn:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
}

body.dark .theme-tab-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.theme-tab-btn.active {
  opacity: 1;
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.theme-tab-btn i {
  font-size: 0.9rem;
}

/* Light theme button specific styling */
.theme-tab-btn[data-color-theme="light"].active {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
}

/* Dark theme button specific styling */
.theme-tab-btn[data-color-theme="dark"].active {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

/* Color theme content sections */
.color-theme-content {
  display: none;
}

.color-theme-content.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile Responsive Styles for Color Theme Tabs */
@media (max-width: 768px) {

  /* Settings panel mobile adjustments */
  .settings-panel {
    max-width: 100%;
    width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    top: auto;
    bottom: 0;
    transform: translateX(-50%);
  }

  .settings-panel h2 {
    font-size: 1.1rem;
    padding: 16px 20px;
  }

  .settings-tabs {
    padding: 6px 12px;
    gap: 4px;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .tab-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    white-space: nowrap;
  }

  /* Color theme sub-tabs mobile */
  .color-theme-tabs {
    flex-direction: column;
    gap: 6px;
    padding: 6px;
  }

  .theme-tab-btn {
    padding: 12px 16px;
    font-size: 0.9rem;
  }

  .theme-tab-btn i {
    font-size: 1rem;
  }

  /* Form inputs mobile */
  .panel-content .tab-content {
    padding: 16px;
  }

  .settings-panel input:not([type="checkbox"]),
  .settings-panel select {
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 16px;
    /* Prevents iOS zoom on focus */
  }

  .settings-panel label {
    font-size: 0.8rem;
    margin-bottom: 6px;
  }

  /* Color inputs mobile - larger touch targets */
  .settings-panel input[type="color"] {
    height: 44px;
    padding: 4px;
  }

  /* Settings footer mobile */
  .settings-footer {
    padding: 12px 16px;
    flex-direction: column;
    gap: 8px;
  }

  .settings-footer button {
    width: 100%;
    padding: 12px;
    font-size: 0.9rem;
  }

  /* Panel content scrolling */
  .panel-content {
    max-height: calc(90vh - 180px);
  }

  /* AI Panel mobile adjustments */
  .ai-panel {
    width: calc(100% - 20px);
    height: 60vh;
    right: 10px;
    bottom: 10px;
    border-radius: 16px;
  }

  .ai-header {
    padding: 12px 16px;
  }

  .ai-chat-container {
    padding: 12px;
  }

  .ai-input-area {
    padding: 10px;
  }
}

/* AI Panel resize indicator */
.ai-panel::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  background: linear-gradient(135deg,
      transparent 0%,
      transparent 50%,
      var(--primary) 50%,
      var(--primary) 60%,
      transparent 60%,
      transparent 70%,
      var(--primary) 70%,
      var(--primary) 80%,
      transparent 80%);
  opacity: 0.5;
  pointer-events: none;
  border-radius: 0 0 16px 0;
}

.ai-panel:hover::after {
  opacity: 0.8;
}

/* AI Panel dragging state */
.ai-panel.dragging {
  opacity: 0.9;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}