/* Editor-specific styles */

/* Note Editor */
.note-editor {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  backdrop-filter: blur(var(--backdrop-blur));
  -webkit-backdrop-filter: blur(var(--backdrop-blur));
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow-x: hidden;
  transition: transform 0.24s ease;
  transform: translateY(100%);
  box-sizing: border-box;
}

/* Vary shimmer direction for editor controls */
.back-btn::after { background:
  conic-gradient(from 140deg at 50% 50%,
    rgba(255,255,255,0.55) 0deg,
    rgba(255,255,255,0.10) 70deg,
    rgba(0,0,0,0.18) 140deg,
    rgba(255,255,255,0.12) 220deg,
    rgba(255,255,255,0.55) 360deg);
}
.delete-btn::after { background:
  conic-gradient(from 200deg at 50% 50%,
    rgba(255,255,255,0.55) 0deg,
    rgba(255,255,255,0.10) 70deg,
    rgba(0,0,0,0.18) 140deg,
    rgba(255,255,255,0.12) 220deg,
    rgba(255,255,255,0.55) 360deg);
}
.ai-rewrite-btn::after { background:
  conic-gradient(from 260deg at 50% 50%,
    rgba(255,255,255,0.55) 0deg,
    rgba(255,255,255,0.10) 70deg,
    rgba(0,0,0,0.18) 140deg,
    rgba(255,255,255,0.12) 220deg,
    rgba(255,255,255,0.55) 360deg);
}
.export-btn::after { background:
  conic-gradient(from 290deg at 50% 50%,
    rgba(255,255,255,0.55) 0deg,
    rgba(255,255,255,0.10) 70deg,
    rgba(0,0,0,0.18) 140deg,
    rgba(255,255,255,0.12) 220deg,
    rgba(255,255,255,0.55) 360deg);
}
.save-btn::after { background:
  conic-gradient(from 320deg at 50% 50%,
    rgba(255,255,255,0.55) 0deg,
    rgba(255,255,255,0.10) 70deg,
    rgba(0,0,0,0.18) 140deg,
    rgba(255,255,255,0.12) 220deg,
    rgba(255,255,255,0.55) 360deg);
}

/* Keep the editor in view once opened */
.note-editor.open {
  transform: translateY(0);
}

.editor-header {
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px; /* tighter header to save vertical space */
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  overflow: visible; /* allow buttons to be fully visible */
}

/* Make editor action icons consistent in size */
.editor-header .icon-btn svg,
.save-btn svg,
.delete-btn svg,
.ai-rewrite-btn svg,
.export-btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2; /* bump stroke so save matches visual weight */
}

/* removed header shimmer per request */

.back-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg-primary); /* stronger contrast */
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
  isolation: isolate;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  line-height: 0;
  box-sizing: border-box;
}

/* Strong focus ring for back button on dark bg */
.back-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.9), 0 0 0 5px rgba(0,122,255,0.55);
}

#noteTitleHeader {
  flex: 1;
  min-width: 0; /* allow title to shrink */
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid transparent;
  outline: none;
  padding: 10px 12px;
  border-radius: 14px;
  transition: box-shadow 160ms ease, border-color 160ms ease, background 160ms ease, color 120ms ease;
  box-sizing: border-box; /* prevent layout shift on focus */
  position: relative;
  isolation: isolate;
}

#noteTitleHeader:focus-visible,
#noteTitleHeader:focus {
  border-color: transparent;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.06);
}

/* Compact editor tweaks */
html[data-compact="1"] .editor-header {
  gap: 6px;
}

html[data-compact="1"] .editor-header .icon-btn svg,
html[data-compact="1"] .save-btn svg,
html[data-compact="1"] .delete-btn svg,
html[data-compact="1"] .ai-rewrite-btn svg,
html[data-compact="1"] .list-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.1;
}

html[data-compact="1"] .save-btn span {
  display: none; /* icon-only to avoid overflow */
}

html[data-compact="1"] .save-btn {
  padding: 6px 8px;
  min-width: 28px;
  border-radius: 50%;
}

.back-btn:hover {
  background: var(--bg-primary);
  transform: translateY(-1px);
}

.back-btn:active {
  transform: translateY(0);
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0; /* prevent pushing title off-screen */
  min-width: 0; /* allow flex items to shrink below their content size */
  overflow: visible; /* ensure buttons aren't cut off */
  flex-wrap: nowrap; /* prevent buttons from wrapping */
}

.save-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  gap: 4px;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  isolation: isolate;
  flex: 0 0 auto;
  line-height: 1;
  box-sizing: border-box;
}

.save-btn:hover {
  background: var(--bg-primary);
  transform: translateY(-1px);
}

.save-btn:active {
  transform: translateY(0);
}

/* Make the save icon green to mirror destructive red of delete */
.save-btn svg {
  color: var(--success-green);
  stroke: var(--success-green);
  transform: scale(1.08); /* slightly larger to match visual weight */
}

/* Ensure save button text is visible */
.save-btn span {
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

/* Strong focus-visible rings for editor action buttons on dark surfaces */
.save-btn:focus-visible,
.delete-btn:focus-visible,
.ai-rewrite-btn:focus-visible,
.export-btn:focus-visible,
.list-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.9), 0 0 0 5px rgba(0,122,255,0.55);
}

.delete-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg-primary); /* stronger contrast */
  border: 1px solid var(--border-color);
  color: #ff4757;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
  isolation: isolate;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  line-height: 0;
  box-sizing: border-box;
}

.delete-btn:hover {
  background: rgba(255, 71, 87, 0.1);
  transform: translateY(-1px);
}

.delete-btn:active {
  transform: translateY(0);
}

.ai-rewrite-btn {
  width: auto;
  min-width: 60px;
  height: 28px;
  border: none;
  border-radius: 14px;
  background: var(--bg-primary); /* stronger contrast */
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
  isolation: isolate;
  flex: 0 0 auto;
  line-height: 0;
  box-sizing: border-box;
  padding: 0 6px;
}

.ai-rewrite-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.ai-rewrite-btn:active {
  transform: translateY(0);
}

/* Style for AI rewrite button text */
.ai-rewrite-btn .btn-text {
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-secondary);
  transition: color 0.2s ease;
  line-height: 1;
}

.ai-rewrite-btn:hover .btn-text {
  color: var(--text-primary);
}

.export-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg-primary); /* stronger contrast */
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
  isolation: isolate;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  line-height: 0;
  box-sizing: border-box;
}

.export-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.export-btn:active {
  transform: translateY(0);
}

.ai-summary-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
  isolation: isolate;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  line-height: 0;
  box-sizing: border-box;
}

.ai-summary-btn:hover {
  background: var(--bg-primary);
  transform: translateY(-1px);
}

.ai-summary-btn:active {
  transform: translateY(0);
}

.list-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  position: relative;
  isolation: isolate;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  line-height: 0;
  box-sizing: border-box;
}

.list-btn:hover {
  background: var(--bg-primary);
  transform: translateY(-1px);
}

.list-btn:active {
  transform: translateY(0);
}

/* Editor Content */
.editor-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  max-height: 100%;
  contain: content;
}

.note-content-input {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-secondary);
  backdrop-filter: blur(var(--backdrop-blur));
  -webkit-backdrop-filter: blur(var(--backdrop-blur));
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  resize: none;
  line-height: 1.5;
  font-family: inherit;
  box-shadow: inset 0 1px 0 var(--shadow-light);
  overflow-y: auto;
  max-height: 100%;
  position: relative;
  isolation: isolate;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background-clip: padding-box;
}

.note-content-input::-webkit-scrollbar { /* Chrome/Safari */
  width: 0;
  height: 0;
}

/* Remove decorative glass overlay on the editor input to prevent moving line artifacts */
.note-content-input::after { content: none !important; }

.note-content-input:focus-visible,
.note-content-input:focus {
  border-color: var(--border-color);
  box-shadow: inset 0 1px 0 var(--shadow-light), 0 0 0 2px rgba(255, 255, 255, 0.06);
}

.note-content-preview {
  flex: 1;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--bg-secondary);
  padding: 12px;
  font-size: 14px;
  color: var(--text-primary);
  position: relative;
  isolation: isolate;
}

/* Editor Meta */
.note-meta {
display: flex;
align-items: flex-end;
justify-content: flex-start;
margin-top: 10px;
padding-top: 10px;
padding-bottom: 6px;
border-top: 1px solid var(--border-color);
min-height: 28px; /* room for bottom-right counter */
position: relative;
gap: 8px;
}

/* Tag bar bottom-left and styled */
.note-editor .note-tags {
  display: flex !important;
  flex-wrap: wrap;
  gap: 6px;
  order: 1;
  margin-right: auto; /* stick to left */
  align-self: flex-end; /* align to bottom */
  flex: 1 1 auto; /* take more horizontal space */
}
.note-editor .tags-input {
  display: block !important;
  min-width: 200px;
  max-width: 80%;
  width: 100%;
  padding: 6px 10px;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  box-shadow: inset 0 1px 0 var(--shadow-light);
  position: relative;
  isolation: isolate;
}

/* Save button text styling */
.save-btn span { 
  display: inline; 
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

/* Shimmering glass outline around editor controls & fields */
.back-btn::after,
.delete-btn::after,
.ai-rewrite-btn::after,
.save-btn::after,
.note-editor .tags-input::after,
.note-content-input::after,
.note-content-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  padding: 1px;
  background:
    conic-gradient(from 200deg at 50% 50%,
      rgba(255,255,255,0.55) 0deg,
      rgba(255,255,255,0.10) 70deg,
      rgba(0,0,0,0.18) 140deg,
      rgba(255,255,255,0.12) 220deg,
      rgba(255,255,255,0.55) 360deg);
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  mix-blend-mode: normal;
  opacity: 0.9;
}
.note-editor .tags-input:hover {
  background: color-mix(in oklab, var(--bg-primary) 85%, white 15%);
}
.note-editor .tags-input:focus-visible {
  border-color: var(--border-color);
  box-shadow: inset 0 1px 0 var(--shadow-light), 0 0 0 2px rgba(255, 255, 255, 0.06);
}

.tags-input:focus {
  border-color: var(--border-color);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.06);
}

.tags-input::placeholder {
  color: var(--placeholder);
}

.note-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  order: 2;
  margin-left: auto; /* keep info on the right */
}

.note-chars {
  color: var(--text-tertiary);
  position: absolute;
  right: 0;
  bottom: 6px; /* aligns with meta bottom padding */
}

/* Rich text editor styles */
.note-content-input[contenteditable="true"] {
  min-height: 0; /* flex will determine height */
}

.note-content-input[contenteditable="true"]:empty::before {
  content: attr(placeholder);
  color: var(--placeholder);
  pointer-events: none;
}

.note-content-input[contenteditable="true"] p {
  margin: 0 0 8px 0;
}

.note-content-input[contenteditable="true"] p:last-child {
  margin-bottom: 0;
}

.note-content-input[contenteditable="true"] strong {
  font-weight: 600;
}

.note-content-input[contenteditable="true"] em {
  font-style: italic;
}

.note-content-input[contenteditable="true"] a {
  color: var(--accent-primary);
  text-decoration: underline;
}

.note-content-input[contenteditable="true"] a:hover {
  text-decoration: none;
}

.note-content-input[contenteditable="true"] ul,
.note-content-input[contenteditable="true"] ol {
  margin: 8px 0;
  padding-left: 20px;
}

.note-content-input[contenteditable="true"] li {
  margin: 4px 0;
}

.note-content-input[contenteditable="true"] blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--accent-primary);
  background: var(--bg-tertiary);
  border-radius: 0 8px 8px 0;
}

.note-content-input[contenteditable="true"] code {
  background: var(--bg-tertiary);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.9em;
}

.note-content-input[contenteditable="true"] pre {
  background: var(--bg-tertiary);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.note-content-input[contenteditable="true"] pre code {
  background: none;
  padding: 0;
}

/* Formatting Toolbar Styles - Liquid Glass Design */
.formatting-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--bg-secondary) 30%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid color-mix(in srgb, var(--border-color) 40%, transparent);
  gap: 8px;
  transition: all 0.2s ease;
}

.format-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  background: color-mix(in srgb, var(--bg-primary) 20%, transparent);
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--border-color) 30%, transparent);
  backdrop-filter: saturate(160%) blur(6px);
  -webkit-backdrop-filter: saturate(160%) blur(6px);
}

.format-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid color-mix(in srgb, var(--border-color) 50%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--bg-primary) 25%, rgba(0, 0, 0, 0.4));
  backdrop-filter: saturate(160%) blur(8px);
  -webkit-backdrop-filter: saturate(160%) blur(8px);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 var(--shadow-light);
}

.format-btn:hover {
  background: color-mix(in srgb, var(--bg-primary) 40%, rgba(0, 0, 0, 0.3));
  color: white;
  transform: translateY(-1px) scale(1.05);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 var(--shadow-light);
  border-color: color-mix(in srgb, var(--border-color) 70%, transparent);
}

.format-btn:active {
  transform: translateY(0) scale(1.02);
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.2),
    inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.format-btn.active {
  background: color-mix(in srgb, var(--accent-primary) 80%, rgba(0, 0, 0, 0.2));
  color: white;
  border-color: var(--accent-primary);
  box-shadow:
    0 2px 8px color-mix(in srgb, var(--accent-primary) 40%, transparent),
    inset 0 1px 0 color-mix(in srgb, white 20%, transparent);
}

.format-btn svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

/* Style for text-based format buttons */
.format-btn .btn-text {
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-primary);
  transition: color 0.2s ease;
  line-height: 1;
}

.format-btn:hover .btn-text {
  color: white;
}

/* Adjust width for text-based format buttons */
.format-btn:has(.btn-text) {
  width: auto;
  min-width: 60px;
  padding: 0 6px;
  border-radius: 14px;
}

/* Color picker specific styles */
.color-picker-container {
  position: relative;
}

.color-btn {
  position: relative;
}

.color-indicator {
  width: 14px;
  height: 2px;
  border-radius: 2px;
  border: 1px solid color-mix(in srgb, var(--border-color) 60%, transparent);
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.color-wheel-popup {
  position: fixed;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
  background: color-mix(in srgb, var(--bg-secondary) 90%, rgba(0, 0, 0, 0.1));
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border: 1px solid color-mix(in srgb, var(--border-color) 50%, transparent);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 var(--shadow-light);
  z-index: 9999999999;
  min-width: 180px;
  animation: popup-fade-in 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes popup-fade-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.color-preset-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  justify-content: center;
}

.color-preset-row:last-of-type {
  margin-bottom: 16px;
}

.color-preset {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid color-mix(in srgb, var(--border-color) 40%, transparent);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.color-preset:hover {
  border-color: var(--accent-primary);
  transform: scale(1.15);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.15),
    0 0 0 2px color-mix(in srgb, var(--accent-primary) 30%, transparent);
}

.color-preset[data-color="#ffffff"] {
  border-color: var(--text-tertiary);
}

.custom-color-section {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid color-mix(in srgb, var(--border-color) 30%, transparent);
  justify-content: center;
}

.custom-color-section label {
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.02em;
}

#customColorInput {
  width: 28px;
  height: 28px;
  border: 2px solid color-mix(in srgb, var(--border-color) 40%, transparent);
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#customColorInput:hover {
  border-color: var(--accent-primary);
  transform: scale(1.1);
}

#customColorInput::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

#customColorInput::-webkit-color-swatch-wrapper {
  padding: 0;
  border: none;
  border-radius: 50%;
}

#customColorInput::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}