﻿* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Arial', sans-serif;
}

:root {
  --accent-color: #ff5555;
  --secondary-color: #117688;
  --secondary-color-rgb: 17, 122, 202;
  --line-height: 1.5;
}

body {
  background-color: #f5f5f5;
  color: #333;
  transition: all 0.3s ease;
  line-height: var(--line-height);
  position: relative;
  padding-top: 36px;
}

body.dark-mode {
  background-color: #1e1e1e;
  color: #e0e0e0;
  --accent-color: #ff9999;
}

.app-container {
  display: flex;
  height: calc(100vh - 36px);
  overflow: hidden;
}

.sidebar-toggle-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #333;
  font-size: 18px;
  cursor: pointer;
  padding: 5px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
  z-index: 1000;
}

body.dark-mode .sidebar-toggle-btn {
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #e0e0e0;
}

.sidebar-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

body.dark-mode .sidebar-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar {
  position: relative;
  min-width: 0;
  max-width: 400px;
  width: 250px;
  background: #f0f0f0;
  padding: 10px;
  padding-top: 12px;
  height: 100%;
  transition: width 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
  will-change: width, padding, opacity;
  opacity: 1;
  display: flex;
  flex-direction: column;
}

body.dark-mode .sidebar {
  background: #333;
}

.sidebar.collapsed {
  width: 0px !important;
  padding: 0;
  opacity: 0;
  overflow: hidden;
}

.sidebar.collapsed * {
  display: none;
}

.sidebar.collapsed .note-container {
  display: none; /* Hide contents when collapsed */
}

.note-container {
  flex: 1; /* Takes up remaining space */
  overflow-y: auto; /* Scroll when content overflows */
  overflow-x: hidden;
  background: #f0f0f0;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 5px;
  margin-bottom: 10px;
  min-height: 100px; /* Minimum height to avoid collapsing too small */
}

body.dark-mode .note-container {
  background: #333;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.note-container::-webkit-scrollbar {
  width: 8px;
}

.note-container::-webkit-scrollbar-track {
  background: transparent;
}

.note-container::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.note-container::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.4);
}

body.dark-mode .note-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
}

body.dark-mode .note-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

.main-content {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  padding-top: 50px;
  transition: all 0.3s ease;
  overflow: hidden;
}

.resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 5px;
  height: 100%;
  cursor: ew-resize;
  background: transparent;
}

.resize-handle:hover {
  background: var(--accent-color);
}

.note-list {
  list-style: none;
  padding: 0px;
}

.note-list ul {
  padding-left: 20px;
  margin: 0;
}

.note-list > li {
  margin-bottom: 1px;
}

.note-item {
  padding: 2px;
  font-size: 14px;
  line-height: 16px;
  cursor: pointer;
  position: relative;
}

.note-content {
  display: flex;
  align-items: center;
}

.note-item > .note-list {
  padding-left: 20px;
}

.note-item:hover {
  background: #e0e0e0;
}

body.dark-mode .note-item:hover {
  background: #444;
}

.note-item.active {
  border-left: 4px solid var(--accent-color);
}

.note-title-input {
  background: transparent;
  border: 1px solid var(--accent-color);
  border-radius: 3px;
  color: inherit;
  font: inherit;
  font-size: 14px;
  outline: none;
  padding: 1px 3px;
  width: 100%;
  box-sizing: border-box;
}

.note-item.dragging {
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  opacity: 0.8;
  background: rgba(0, 0, 0, 0.1);
}

body.dark-mode .note-item.dragging {
  background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .note-title-input {
  border-color: var(--accent-color);
  color: inherit;
}

.note-item.drag-over {
  background: rgba(var(--secondary-color-rgb), 0.2);
  border: 2px dashed var(--secondary-color);
}

.expand-icon {
  margin-right: 3px;
  width: 5px;
  cursor: pointer;
}

.note-icon {
  margin-right: 5px;
}

.drop-zone {
  height: 5px;
  padding: 0;
  background: transparent;
  margin: 0;
  transition: background 0.2s ease, border 0.2s ease;
}

.drop-zone.drag-over {
  background: rgba(var(--secondary-color-rgb), 0.3);
  border-top: 2px dashed var(--secondary-color);
  border-bottom: 2px dashed var(--secondary-color);
}

.drop-zone.top {
  top: -2px;
}

.drop-zone.bottom {
  bottom: -2px;
}

.note-header {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
}

.add-note-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 4px;
}

.add-note-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

body.dark-mode .add-note-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.use-template-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.7;
  margin-left: auto;
}
.use-template-btn:hover { opacity: 1; background: rgba(0,0,0,0.07); }
body.dark-mode .use-template-btn:hover { background: rgba(255,255,255,0.1); }

.menu-zone {
  position: absolute;
  top: 0;
  width: 90%;
  max-width: var(--editor-max-width, 1200px);
  left: 50%;
  transform: translateX(-50%);
  height: 50px;
  background: transparent;
  z-index: 999;
}

.toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: var(--editor-max-width, 1200px);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: opacity 0.2s ease, transform 0.2s ease;
  opacity: 0;
  transform: translateX(-50%) translateY(-100%);
  z-index: 1000;
}

body:not(.dark-mode) .toolbar {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

body.toolbar-always-visible .toolbar {
  opacity: 1 !important;
  transform: translateX(-50%) translateY(0) !important;
}

.toolbar.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toolbar button {
  background: transparent;
  border: none;
  padding: 6px;
  cursor: pointer;
  font-size: 16px;
  color: inherit;
  border-radius: 6px;
  transition: background 0.2s, transform 0.1s;
  min-width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toolbar button:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

body:not(.dark-mode) .toolbar button:hover {
  background: rgba(0, 0, 0, 0.15);
}

.toolbar button.dragging {
  opacity: 0.5;
  transform: scale(1.1);
}

.editor {
  width: 90%;
  max-width: var(--editor-max-width, 1200px);
  margin: 20px auto;
  background: #fff;
  padding: 80px 80px 0 80px;
  border-radius: 15px;
  min-height: 85vh;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  outline: none;
  position: relative;
  font-size: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  line-height: var(--line-height);
}

.editor::after {
  content: '';
  display: block;
  height: var(--editor-bottom-padding, 200px);
  pointer-events: none;
}

body.dark-mode .editor {
  background: #2c2c2c;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
}

.editor[contenteditable]:empty:before {
  content: 'Your thoughts go here...';
  color: #aaa;
}

.editor::-webkit-scrollbar {
  width: 8px;
}

.editor::-webkit-scrollbar-track {
  background: transparent;
}

.editor::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  transition: background 0.2s ease;
}

.editor::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.4);
}

body.dark-mode .editor::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
}

body.dark-mode .editor::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

.editor.no-scroll::-webkit-scrollbar {
  display: none;
}

.editor {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

body.dark-mode .editor {
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.editor.no-scroll {
  scrollbar-width: none;
}

.editor-footer {
  position: absolute;
  bottom: 10px;
  right: 15px;
  font-size: 12px;
  color: #888;
  transition: color 0.3s;
}

body.dark-mode .editor-footer {
  color: #bbb;
}

.dragging {
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.drop-placeholder {
  height: 2px;
  background: var(--secondary-color);
  transition: all 0.2s ease;
}

#slash-menu {
  position: absolute;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  flex-direction: column;
  width: 200px;
}

body.dark-mode #slash-menu {
  background: #333;
  border: 1px solid #555;
}

#slash-menu button {
  background: none;
  border: none;
  padding: 8px 12px;
  text-align: left;
  color: #333;
  cursor: pointer;
}

body.dark-mode #slash-menu button {
  color: #e0e0e0;
}

#slash-menu button:hover {
  background: #f0f0f0;
}

body.dark-mode #slash-menu button:hover {
  background: #444;
}

/* Table Grid Styles */
.table-grid {
  display: none; /* Hidden by default */
  position: absolute;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1001;
}

body.dark-mode .table-grid {
  background: #333;
  border: 1px solid #555;
}

.table-grid .grid {
  display: grid;
  grid-template-columns: repeat(10, 20px);
  grid-template-rows: repeat(6, 20px);
  gap: 2px;
}

.table-grid .cell {
  background: #e0e0e0;
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.1s;
}

body.dark-mode .table-grid .cell {
  background: #444;
}

.table-grid .cell:hover,
.table-grid .cell.highlighted {
  background: var(--secondary-color);
}

.table-grid .size-indicator {
  margin-top: 5px;
  text-align: center;
  font-size: 12px;
  color: #666;
}

body.dark-mode .table-grid .size-indicator {
  color: #bbb;
}

/* ---------------------------------------------------------------------------
   Tables — enhanced with column/row resize + selection
   ------------------------------------------------------------------------- */

.table-wrap {
  position: relative;
  margin: 15px 0;
}

.table-wrap > table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  position: relative;
}

td, th {
  border: 1px solid #ddd;
  padding: 5px;
  text-align: left;
  background: #fafafa;
  position: relative;
  transition: background 0.2s;
  line-height: var(--line-height);
  min-height: 30px;
  word-wrap: break-word;
  word-break: break-word;
  white-space: normal;
}

body.dark-mode th,
body.dark-mode td {
  border: 1px solid #9a9a9a;
  background: #383838;
}

th {
  background: #e5e5e5;
  font-weight: bold;
}

body.dark-mode th {
  background: #4a4a4a;
}

td[contenteditable="true"] {
  outline: none;
  min-width: 80px;
  min-height: 30px;
  cursor: text;
}

td[contenteditable="true"]:hover,
td[contenteditable="true"]:focus {
  background: rgba(0, 0, 0, 0.05);
}

body.dark-mode td[contenteditable="true"]:hover,
body.dark-mode td[contenteditable="true"]:focus {
  background: rgba(255, 255, 255, 0.05);
}

td[contenteditable="true"]:empty:before {
  content: '\00a0';
}

/* ---- Column resize handles ---- */
.col-resize-strip {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  pointer-events: none;
}

.col-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 7px;
  cursor: col-resize;
  z-index: 20;
  margin-left: -3px;
  background: transparent;
  user-select: none;
  pointer-events: all;
}

.col-resize-handle::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: transparent;
  transition: background 0.12s;
}

.col-resize-handle:hover::after,
.col-resize-handle.resizing::after {
  background: var(--secondary-color, #4a90d9);
  width: 2px;
  left: 2px;
}

/* ---- Row resize handles ---- */
.row-resize-strip {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  pointer-events: none;
}

.row-resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  height: 7px;
  cursor: row-resize;
  z-index: 20;
  margin-top: -3px;
  background: transparent;
  user-select: none;
  pointer-events: all;
}

.row-resize-handle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 0;
  right: 0;
  height: 1px;
  background: transparent;
  transition: background 0.12s;
}

.row-resize-handle:hover::after,
.row-resize-handle.resizing::after {
  background: var(--secondary-color, #4a90d9);
  height: 2px;
  top: 2px;
}

/* ---- Column / Row header selection ---- */
th.select-cursor {
  cursor: pointer;
}

.col-header-hit {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  cursor: pointer;
}

.col-header-hit:hover + .col-resize-handle::after {
  /* Keep handle visible */
}

/* ---- Selection visual ---- */
.selected-cell {
  border: 2px solid var(--secondary-color) !important;
  background-color: rgba(var(--secondary-color-rgb), 0.15) !important;
  position: relative;
  z-index: 2;
}

.col-selected {
  background-color: rgba(var(--secondary-color-rgb), 0.08) !important;
}

.row-selected {
  background-color: rgba(var(--secondary-color-rgb), 0.08) !important;
}

.table-dragging {
  user-select: none;
}

/* ---- Resizing cursor on body ---- */
body.col-resizing {
  cursor: col-resize !important;
  user-select: none;
}
body.col-resizing td,
body.col-resizing th {
  cursor: col-resize !important;
}
body.row-resizing {
  cursor: row-resize !important;
  user-select: none;
}
body.row-resizing td,
body.row-resizing th {
  cursor: row-resize !important;
}

/* ---- Row number indicator ---- */
.row-number {
  display: inline-block;
  width: 24px;
  min-width: 24px;
  color: #999;
  font-size: 11px;
  text-align: center;
  user-select: none;
  position: absolute;
  left: -28px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

tr { position: relative; }

.context-menu {
  position: absolute;
  background: #444;
  border: 1px solid #666;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: none;
  flex-direction: column;
  width: 220px;
  animation: contextFadeIn 0.2s ease;
}

@keyframes contextFadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

body.dark-mode .context-menu {
  background: #444;
  border: 1px solid #666;
}

.context-menu button {
  background: transparent;
  border: none;
  padding: 10px 15px;
  text-align: left;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  transition: background 0.2s;
}

.context-menu button:hover {
  background: rgba(255, 255, 255, 0.15);
}

ul.checklist {
  list-style: none;
  padding-left: 20px;
  margin: 8px 0;
}

ul.checklist li {
  margin: 2px 0;
  line-height: var(--line-height);
}

ul.checklist input[type="checkbox"] {
  margin-right: 8px;
  vertical-align: middle;
  cursor: pointer;
  flex-shrink: 0;
}

ul.checklist ul.checklist {
  margin: 0;
  padding-left: 15px;
}

ul.checklist li:empty:not(:focus)::before,
ul.checklist li:empty:focus::before {
  content: "Item";
  color: #aaa;
  font-style: italic;
  display: inline-block;
  margin-left: 5px;
}

body.dark-mode ul.checklist li:empty:not(:focus)::before,
body.dark-mode ul.checklist li:empty:focus::before {
  color: #888;
}

td ul.checklist,
th ul.checklist {
  padding-left: 10px;
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}

td ul.checklist li,
th ul.checklist li {
  padding-left: 0;
}

/* Timestamp Lists */
ul.timestamp-list {
  list-style: none;
  padding-left: 20px;
  margin: 8px 0;
}

ul.timestamp-list li {
  margin: 2px 0;
  line-height: var(--line-height);
}

ul.timestamp-list li .ts {
  color: var(--secondary-color);
  font-family: 'Courier New', monospace;
  font-size: 0.85em;
  margin-right: 4px;
  user-select: none;
}

ul.timestamp-list ul.timestamp-list {
  margin: 0;
  padding-left: 15px;
}

td ul.timestamp-list,
th ul.timestamp-list {
  padding-left: 10px;
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}

td ul.timestamp-list li,
th ul.timestamp-list li {
  padding-left: 0;
}

/* Bullet Lists */
ul.bullets {
  list-style: disc;
  padding-left: 25px;
  margin: 8px 0;
}

ul.bullets ul.bullets {
  list-style: circle;
  padding-left: 15px;
  margin: 0;
}

ul.bullets ul.bullets ul.bullets {
  list-style: square;
  padding-left: 15px;
  margin: 0;
}

ol {
  list-style: decimal;
  padding-left: 25px;
  margin: 8px 0;
}

ol ol {
  list-style: lower-alpha;
  padding-left: 15px;
  margin: 0;
}

ol ol ol {
  list-style: lower-roman;
  padding-left: 15px;
  margin: 0;
}

ul ul,
ol ol,
ul ol,
ol ul {
  padding-left: 15px;
}

ul.bullets li,
ol li {
  margin: 4px 0;
  line-height: var(--line-height);
}

td ul.bullets,
th ul.bullets,
td ol,
th ol {
  padding-left: 10px;
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}

td ul.bullets ul.bullets,
th ul.bullets ul.bullets,
td ol ol,
th ol ol {
  padding-left: 15px;
  margin: 0;
}

/* Placeholder for empty list items */
ul.bullets li:empty:not(:focus)::before,
ol li:empty:not(:focus)::before {
  content: "List item";
  color: #aaa;
  font-style: italic;
}

body.dark-mode ul.bullets li:empty:not(:focus)::before,
body.dark-mode ol li:empty:not(:focus)::before {
  color: #888;
}

.notification {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  z-index: 2000;
  animation: fadeInOut 2s ease;
}

@keyframes fadeInOut {
  0% { opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { opacity: 0; }
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1000;
}

.modal.show {
  display: flex;
  opacity: 1;
}

.modal-content {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  min-width: 300px;
  min-height: 200px;
  width: 90%;
  max-width: 800px;
  height: auto;
  max-height: 80vh;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow-y: auto;
}

body.dark-mode .modal-content {
  background-color: #2c2c2c;
  color: #e0e0e0;
}

.close-button {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 24px;
  cursor: pointer;
}

.modal-content h2 {
  margin-bottom: 15px;
  font-size: 20px;
}

.modal label {
  display: block;
  margin-bottom: 5px;
}

.modal input {
  width: 100%;
  padding: 8px;
  margin-bottom: 15px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.modal input[type="file"] {
  padding: 3px;
}

.modal button {
  background-color: var(--secondary-color);
  color: white;
  padding: 10px 15px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
}

.modal button:hover {
  filter: brightness(0.9);
}

.modal-content p {
  margin-bottom: 15px;
  font-size: 14px;
}

.modal-content button {
  flex: 1;
}

ul.checklist li.checked {
  text-decoration: line-through;
  color: #888;
}

body.dark-mode ul.checklist li.checked {
  color: #666;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.tabs {
  display: flex;
  gap: 1px;
  margin-bottom: 15px;
}

.tab-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  color: #888;
  transition: color 0.15s;
}
.tab-btn.active {
  color: var(--accent-color);
}
.tab-btn:hover {
  color: #333;
}

body.dark-mode .tab-btn {
  color: #888;
}
body.dark-mode .tab-btn.active {
  color: var(--accent-color);
}
body.dark-mode .tab-btn:hover {
  color: #e0e0e0;
}

.tab-content {
  padding: 6px 0;
}

.settings-grid {
  display: grid;
  gap: 6px;
  padding: 6px;
}

#general .settings-grid,
#editor .settings-grid,
#appearance .settings-grid {
  grid-template-columns: repeat(3, 1fr);
}

#toolbar .settings-grid,
#contextmenu .settings-grid {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.settings-grid .setting-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 6px 8px;
}

.tab-btn {
  background: none;
  border: none;
  padding: 10px 20px;
  margin: 5px;
  cursor: pointer;
  font-size: 16px;
  color: #666;
  transition: color 0.2s, background 0.2s;
}

.tab-btn.active {
  color: var(--accent-color);
  border-bottom: 2px solid var(--accent-color);
}

.tab-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

body.dark-mode .tab-btn {
  color: #bbb;
}

body.dark-mode .tab-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.tab-content {
  padding: 10px 0;
}

.tab-content h3 {
  margin-bottom: 15px;
  font-size: 16px;
  color: #333;
}

body.dark-mode .tab-content h3 {
  color: #e0e0e0;
}

.settings-grid {
  display: grid;
  gap: 8px;
  padding: 10px;
}

/* General / Editor / Appearance: 3-column grid */
#general .settings-grid,
#editor .settings-grid,
#appearance .settings-grid {
  grid-template-columns: repeat(3, 1fr);
}

/* Toolbar / Contextmenu: 7-column compact grid */
#toolbar .settings-grid,
#contextmenu .settings-grid {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

/* Default setting-item (general/editor/appearance) */
.settings-grid .setting-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 8px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 6px;
  transition: background 0.2s ease;
}

body.dark-mode .settings-grid .setting-item {
  background: rgba(255, 255, 255, 0.05);
}

.settings-grid .setting-item:hover {
  background: rgba(0, 0, 0, 0.08);
}

body.dark-mode .settings-grid .setting-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Default checkbox label (general/editor/appearance) */
.settings-grid .checkbox-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  font-size: 13px;
  color: #333;
  gap: 6px;
  cursor: pointer;
  width: 100%;
}

body.dark-mode .settings-grid .checkbox-label {
  color: #e0e0e0;
}

.settings-grid .checkbox-label input[type="checkbox"] {
  margin: 0;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  accent-color: var(--accent-color);
}

.settings-grid .checkbox-label .icon {
  font-size: 16px;
  color: #666;
  flex-shrink: 0;
}

body.dark-mode .settings-grid .checkbox-label .icon {
  color: #bbb;
}

/* Compact items for toolbar/contextmenu tabs */
#toolbar .settings-grid .setting-item,
#contextmenu .settings-grid .setting-item {
  flex-direction: row;
  align-items: center;
  padding: 3px 4px;
  gap: 3px;
  min-width: 0;
}

#toolbar .settings-grid .checkbox-label,
#contextmenu .settings-grid .checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  min-width: 0;
  overflow: hidden;
}

#toolbar .settings-grid .checkbox-label input[type="checkbox"],
#contextmenu .settings-grid .checkbox-label input[type="checkbox"] {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
}

#toolbar .settings-grid .checkbox-label .icon,
#contextmenu .settings-grid .checkbox-label .icon {
  font-size: 12px;
  flex-shrink: 0;
}

#toolbar .settings-grid .checkbox-label span:last-child,
#contextmenu .settings-grid .checkbox-label span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  line-height: 1.2;
}

.settings-grid .input-label {
  display: flex;
  flex-direction: column;
  font-size: 14px;
  color: #333;
  margin-bottom: 0;
  padding: 2px 0;
}

body.dark-mode .settings-grid .input-label {
  color: #e0e0e0;
}

.settings-grid .input-label span {
  margin-bottom: 5px;
}

.settings-grid .input-label span i {
  margin-left: 5px;
  color: #666;
}

body.dark-mode .settings-grid .input-label span i {
  color: #bbb;
}

.settings-grid .input-label input,
.settings-grid .input-label select {
  width: 100%;
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #333;
  font-size: 14px;
}

.settings-grid .input-label input[type="range"] {
  width: 100%;
  margin-top: 5px;
  cursor: pointer;
}

.settings-grid .input-label #editor-width-value {
  margin-top: 5px;
  font-size: 12px;
  color: #666;
  text-align: center;
}

body.dark-mode .settings-grid .input-label #editor-width-value {
  color: #bbb;
}

.settings-grid .input-label #sidebar-width-value {
  margin-top: 5px;
  font-size: 12px;
  color: #666;
  text-align: center;
}

body.dark-mode .settings-grid .input-label #sidebar-width-value {
  color: #bbb;
}

body.dark-mode .settings-grid .input-label input,
body.dark-mode .settings-grid .input-label select {
  background: #333;
  color: #e0e0e0;
  border-color: #555;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 6px 16px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  background: #fff;
  color: #333;
  transition: background 0.15s;
}

body.dark-mode .modal-actions button {
  background: transparent;
  border-color: rgba(255,255,255,0.15);
  color: #ccc;
}

.modal-actions button:hover {
  background: rgba(0,0,0,0.06);
}

body.dark-mode .modal-actions button:hover {
  background: rgba(255,255,255,0.08);
}

.modal-actions .save-btn {
  background: var(--secondary-color);
  color: #fff;
  border-color: var(--secondary-color);
}

.modal-actions .save-btn:hover {
  filter: brightness(0.9);
}

#quick-edit-menu {
  display: none;
  position: absolute;
  background: #1f1f1f;
  border: 1px solid #555;
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  padding: 5px;
  width: 300px;
}

body:not(.dark-mode) #quick-edit-menu {
  background: #fff;
  border: 1px solid #ccc;
}

.quick-edit-buttons,
.table-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 70px;
  overflow: hidden;
}

.table-buttons {
  max-height: 35px;
  margin-top: 5px;
}

.menu-separator {
  height: 1px;
  background: rgba(255, 255, 255, 0.2);
  margin: 5px 0;
}

body:not(.dark-mode) .menu-separator {
  background: rgba(0, 0, 0, 0.2);
}

.quick-edit-buttons button,
.table-buttons button {
  background: none;
  border: none;
  padding: 5px;
  cursor: pointer;
  font-size: 14px;
  color: #e0e0e0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s, transform 0.1s;
}

body:not(.dark-mode) .quick-edit-buttons button,
body:not(.dark-mode) .table-buttons button {
  color: #333;
}

.quick-edit-buttons button:hover,
.table-buttons button:hover {
  background: rgba(255, 255, 255, 0.1);
}

body:not(.dark-mode) .quick-edit-buttons button:hover,
body:not(.dark-mode) .table-buttons button:hover {
  background: rgba(0, 0, 0, 0.1);
}

.quick-edit-buttons button.dragging,
.table-buttons button.dragging {
  opacity: 0.5;
  transform: scale(1.1);
}

.quick-edit-buttons i,
.table-buttons i {
  font-size: 16px;
}

/* Calendar Styles */
.calendar-container {
  background: #f0f0f0;
  padding: 10px;
  padding-top: 0px;
  border-radius: 8px;
  margin-bottom: 10px;
  flex-shrink: 0;
  transition: height 0.3s ease;
}

body.dark-mode .calendar-container {
  background: #333;
}

.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.day-header {
  text-align: center;
  font-size: 12px;
  color: #666;
  padding: 2px;
}

body.dark-mode .day-header {
  color: #bbb;
}

.day {
  text-align: center;
  padding: 5px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.2s;
}

.day.empty {
  background: transparent;
  cursor: default;
}

.day:hover:not(.empty) {
  background: rgba(0, 0, 0, 0.1);
}

body.dark-mode .day:hover:not(.empty) {
  background: rgba(255, 255, 255, 0.1);
}

.day.today {
  border: 1px solid var(--accent-color);
}

.day.selected {
  background: var(--secondary-color);
  color: white;
}

.day.has-note {
  position: relative;
}

.day.has-note::after {
  content: '';
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 4px;
  height: 4px;
  background: var(--accent-color);
  border-radius: 50%;
}

/* Template Modal Styles */
/* Template Panel — left-side panel inside the modal overlay */
/* ── Template Picker (small modal for new note from template) ── */
#template-picker {
  position: fixed; inset: 0; z-index: 950;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.25);
}
#template-picker.show { display: flex; }

.template-picker-panel {
  background: #f5f5f5; border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  width: 260px; max-height: 70vh;
  display: flex; flex-direction: column;
}
body.dark-mode .template-picker-panel { background: #2a2a2a; }

.template-picker-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #ddd;
  font-size: 14px; font-weight: 600;
}
body.dark-mode .template-picker-header { border-bottom-color: #444; }

.template-picker-header .close-button {
  font-size: 18px; cursor: pointer; opacity: 0.6; line-height: 1;
}
.template-picker-header .close-button:hover { opacity: 1; }

.template-picker-list { overflow-y: auto; padding: 6px 0; }

.template-picker-item {
  padding: 8px 14px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.template-picker-item:hover { background: rgba(0,0,0,0.07); }
body.dark-mode .template-picker-item:hover { background: rgba(255,255,255,0.07); }

/* ── Template panel (left overlay, no dim) ── */
#template-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 900;
  background: transparent;
}
#template-modal.show { display: block; }

.template-panel {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 280px;
  background: var(--bg-surface, #f5f5f5);
  border-right: 1px solid #ddd;
  display: flex; flex-direction: column;
  z-index: 910;
  box-shadow: 2px 0 12px rgba(0,0,0,0.15);
}
body.dark-mode .template-panel {
  background: #2a2a2a;
  border-right-color: #444;
}

/* ── Header ── */
.template-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #ddd;
}
body.dark-mode .template-panel-header { border-bottom-color: #444; }

.template-panel-header h2 {
  font-size: 15px; font-weight: 600; margin: 0;
  display: flex; align-items: center; gap: 6px;
}
.template-panel-header .close-button {
  font-size: 20px; cursor: pointer; opacity: 0.6; line-height: 1;
}
.template-panel-header .close-button:hover { opacity: 1; }

/* ── Scrollable list (matches .note-list styling) ── */
.template-list { flex: 1; overflow-y: auto; padding: 0; }

/* ── Item row (matches .note-item styling) ── */
.template-item {
  padding: 2px;
  font-size: 14px;
  line-height: 16px;
  cursor: pointer;
  position: relative;
}
.template-item:hover { background: #e0e0e0; }
body.dark-mode .template-item:hover { background: #444; }

.template-item.active {
  border-left: 4px solid var(--accent-color);
}

.template-name {
  display: block;
  padding: 2px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Add button at bottom of list ── */
.add-template-btn {
  display: block; width: calc(100% - 8px); margin: 6px 4px 4px;
  background: transparent;
  border: 1px dashed #888; color: #888;
  padding: 4px 7px;
  border-radius: 4px; cursor: pointer;
  font-size: 13px;
}
.add-template-btn:hover { background: rgba(0,0,0,0.07); }
body.dark-mode .add-template-btn { border-color: #bbb; color: #bbb; }
body.dark-mode .add-template-btn:hover { background: rgba(255,255,255,0.07); }

/* ── Floating Save button (above editor) ── */
.save-template-btn {
  position: fixed; top: 40px; left: 50%; transform: translateX(-50%);
  z-index: 500;
  background: var(--secondary-color); color: #fff; border: none;
  padding: 8px 18px; border-radius: 8px; cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: opacity 0.2s;
}
.save-template-btn:hover { opacity: 0.85; }

/* Template Button Styles */
.delete-dropdown {
  position: absolute;
  background: #1f1f1f;
  border: 1px solid #555;
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  z-index: 1001;
  display: none;
  flex-direction: column;
  width: 150px;
  right: 0;
  top: 100%;
}

body:not(.dark-mode) .delete-dropdown {
  background: #fff;
  border: 1px solid #ccc;
}

.delete-dropdown button {
  background: transparent;
  border: none;
  padding: 8px 12px;
  text-align: left;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
  transition: background 0.2s;
}

body:not(.dark-mode) .delete-dropdown button {
  color: #333;
}

.delete-dropdown button:hover {
  background: rgba(255, 255, 255, 0.1);
}

body:not(.dark-mode) .delete-dropdown button:hover {
  background: rgba(0, 0, 0, 0.1);
}

.delete-dropdown button i {
  font-size: 14px;
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  padding: 0 5px;
}

.calendar-title {
  flex-grow: 1;
  text-align: center;
}

.calendar-nav-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 5px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.calendar-nav-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

body.dark-mode .calendar-nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.calendar-toggle-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 5px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.calendar-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.1);
}

body.dark-mode .calendar-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* -------------------------------------------------------------------------
   Dialog modals above all other modals (including template editor)
   ------------------------------------------------------------------------- */
#input-modal,
#about-modal {
  z-index: 2100;
}

/* -------------------------------------------------------------------------
   Custom frameless titlebar
   ------------------------------------------------------------------------- */

#titlebar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 36px;
  background: #252525;
  display: flex;
  align-items: center;
  z-index: 9000;
  -webkit-app-region: drag;
  user-select: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

body:not(.dark-mode) #titlebar {
  background: #e4e4e4;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

.tb-no-drag {
  -webkit-app-region: no-drag;
}

#titlebar-sidebar-toggle {
  width: 38px;
  height: 100%;
  background: none;
  border: none;
  color: #999;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-app-region: no-drag;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

#titlebar-sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

body:not(.dark-mode) #titlebar-sidebar-toggle {
  color: #555;
}

body:not(.dark-mode) #titlebar-sidebar-toggle:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #111;
}

#titlebar-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 0 2px;
  font-size: 13px;
  font-weight: 600;
  color: #bbb;
  white-space: nowrap;
  flex-shrink: 0;
}

.titlebar-icon {
  font-size: 15px;
}

body:not(.dark-mode) #titlebar-brand {
  color: #444;
}

/* Menubar */
#titlebar-menubar {
  display: flex;
  height: 100%;
  -webkit-app-region: no-drag;
}

.tb-menu {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
}

.tb-menu-btn {
  height: 100%;
  padding: 0 11px;
  background: none;
  border: none;
  color: #aaa;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.tb-menu-btn:hover,
.tb-menu.open > .tb-menu-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

body:not(.dark-mode) .tb-menu-btn {
  color: #555;
}

body:not(.dark-mode) .tb-menu-btn:hover,
body:not(.dark-mode) .tb-menu.open > .tb-menu-btn {
  background: rgba(0, 0, 0, 0.09);
  color: #111;
}

/* Dropdown */
.tb-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 230px;
  background: #2a2a2a;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  list-style: none;
  padding: 4px 0;
  z-index: 9500;
}

.tb-menu.open > .tb-dropdown {
  display: block;
}

body:not(.dark-mode) .tb-dropdown {
  background: #f2f2f2;
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.15);
}

.tb-item {
  padding: 7px 16px;
  font-size: 13px;
  color: #ccc;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  transition: background 0.1s;
  white-space: nowrap;
}

.tb-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

body:not(.dark-mode) .tb-item {
  color: #333;
}

body:not(.dark-mode) .tb-item:hover {
  background: rgba(0, 0, 0, 0.07);
  color: #000;
}

.tb-kbd {
  font-size: 11px;
  color: #555;
  font-family: monospace;
  flex-shrink: 0;
}

body:not(.dark-mode) .tb-kbd {
  color: #999;
}

.tb-sep {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 3px 0;
  pointer-events: none;
}

body:not(.dark-mode) .tb-sep {
  background: rgba(0, 0, 0, 0.09);
}

/* Window controls */
#titlebar-controls {
  display: flex;
  margin-left: auto;
  height: 100%;
  -webkit-app-region: no-drag;
  flex-shrink: 0;
}

.tb-ctrl {
  width: 46px;
  height: 100%;
  background: none;
  border: none;
  color: #999;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.tb-ctrl:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

body:not(.dark-mode) .tb-ctrl {
  color: #555;
}

body:not(.dark-mode) .tb-ctrl:hover {
  background: rgba(0, 0, 0, 0.09);
  color: #111;
}

.tb-close:hover {
  background: #c42b1c !important;
  color: #fff !important;
}

/* -------------------------------------------------------------------------
   Word count floating badge (outside contenteditable editor)
   ------------------------------------------------------------------------- */
.word-count-display {
  position: fixed;
  bottom: 14px;
  right: 22px;
  font-size: 11px;
  font-family: monospace;
  background: rgba(0, 0, 0, 0.55);
  color: #e0e0e0;
  padding: 3px 10px;
  border-radius: 10px;
  z-index: 500;
  pointer-events: none;
  user-select: none;
}

body:not(.dark-mode) .word-count-display {
  background: rgba(0, 0, 0, 0.12);
  color: #444;
}

/* -------------------------------------------------------------------------
   Image modal — file picker tab and drop zone
   ------------------------------------------------------------------------- */
.img-src-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #ccc;
  margin-bottom: 14px;
}

body.dark-mode .img-src-tabs {
  border-bottom-color: #555;
}

.img-src-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 16px;
  cursor: pointer;
  font-size: 13px;
  color: #666;
  transition: color 0.15s, border-color 0.15s;
  width: auto;
}

.img-src-btn.active {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
}

body.dark-mode .img-src-btn {
  color: #bbb;
}

#img-url-section label,
#img-file-section label:not(.img-browse-btn) {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.img-drop-zone {
  border: 2px dashed #aaa;
  border-radius: 8px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: transparent;
}

.img-drop-zone.drag-over {
  border-color: var(--accent-color);
  background: rgba(var(--secondary-color-rgb), 0.08);
}

.img-drop-zone p {
  margin: 4px 0;
  font-size: 13px;
  color: #888;
}

body.dark-mode .img-drop-zone {
  border-color: #666;
}

body.dark-mode .img-drop-zone p {
  color: #aaa;
}

.img-browse-btn {
  display: inline-block;
  padding: 6px 16px;
  background: var(--secondary-color);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  margin-top: 6px;
  transition: filter 0.15s;
  width: auto !important;
}

.img-browse-btn:hover {
  filter: brightness(1.15);
}

/* Sync titlebar appearance with dark-mode toggle */
body:not(.dark-mode) .tb-dropdown {
  background: #f2f2f2;
}

/* -------------------------------------------------------------------------
   Sidebar autohide mode — sidebar is fixed/overlaid and slides in on hover
   ------------------------------------------------------------------------- */

body.sidebar-autohide .sidebar {
  position: fixed;
  left: 0;
  top: 36px;
  height: calc(100vh - 36px);
}

body.titlebar-autohide.sidebar-autohide .sidebar {
  top: 0;
  height: 100vh;
  z-index: 500;
  transform: translateX(-100%);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  width: 250px;
}

body.sidebar-autohide .sidebar.hover-visible {
  transform: translateX(0);
  box-shadow: 4px 0 28px rgba(0, 0, 0, 0.35);
}

body.sidebar-autohide .resize-handle {
  display: none;
}

#sidebar-hover-zone {
  position: fixed;
  left: 0;
  top: 36px;
  bottom: 0;
}

body.titlebar-autohide #sidebar-hover-zone {
  top: 0;
  width: 8px;
  z-index: 600;
  cursor: e-resize;
}

/* -------------------------------------------------------------------------
   Titlebar autohide — slides up until hover zone is activated
   ------------------------------------------------------------------------- */

body.titlebar-autohide {
  padding-top: 0;
}

body.titlebar-autohide .app-container {
  height: 100vh;
}

body.titlebar-autohide #titlebar {
  transform: translateY(-100%);
  transition: transform 0.2s ease;
}

body.titlebar-autohide #titlebar.revealed {
  transform: translateY(0);
}

/* Autohide sidebar top offset when titlebar is hidden */
body.titlebar-autohide .sidebar-autohide .sidebar,
body.titlebar-autohide #sidebar-hover-zone {
  top: 0;
  height: 100vh;
}

#titlebar-top-zone {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  z-index: 9100;
}

body.titlebar-autohide #titlebar-top-zone {
  display: block;
}

/* -------------------------------------------------------------------------
   Dialog modals (input, color, comment, about)
   Replace browser prompt() with polished in-app dialogs
   ------------------------------------------------------------------------- */

.dialog-modal-content {
  max-width: 420px;
  min-height: unset;
  padding: 28px 28px 22px;
}

.dialog-modal-content h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.dialog-btn-row {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.dialog-btn-row button {
  flex: 1;
  padding: 9px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: filter 0.15s;
}

.dialog-btn-row button:first-child {
  background-color: var(--secondary-color);
  color: #fff;
}

.dialog-btn-row button:first-child:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background-color: #888 !important;
  color: #fff;
}

/* Note Title Display */
#note-title-display {
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  padding: 15px 10px;
  margin-bottom: 10px;
  border-bottom: 2px solid rgba(0, 0, 0, 0.1);
  outline: none;
  min-height: 40px;
  word-break: break-word;
  white-space: normal;
}

body.dark-mode #note-title-display {
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

#note-title-display:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

body.dark-mode #note-title-display:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

/* Heading Selector Popup */
#heading-selector-popup .heading-option {
  transition: background 0.15s;
}

#heading-selector-popup .heading-option:hover {
  background-color: rgba(var(--secondary-color-rgb), 0.1) !important;
}

body.dark-mode #heading-selector-popup {
  background: #2c2c2c;
  border-color: #444;
}

body.dark-mode #heading-selector-popup .heading-option:hover {
  background-color: rgba(var(--secondary-color-rgb), 0.15) !important;
}

.btn-secondary:hover {
  filter: brightness(1.1) !important;
}

/* Textarea inside modals */
.modal textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 90px;
  box-sizing: border-box;
  line-height: 1.5;
  color: #333;
  background: #fff;
  outline: none;
  transition: border-color 0.2s;
}

.modal textarea:focus {
  border-color: var(--secondary-color);
}

body.dark-mode .modal textarea {
  background: #3a3a3a;
  color: #e0e0e0;
  border-color: #555;
}

body.dark-mode .modal textarea:focus {
  border-color: var(--secondary-color);
}

/* Color hex input */
#color-hex-input {
  display: block;
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 6px;
  cursor: text;
  padding: 6px 8px;
  background: transparent;
  font-family: monospace;
  font-size: 13px;
  text-transform: uppercase;
  box-sizing: border-box;
}

body.dark-mode #color-hex-input {
  border-color: #555;
}


/* -------------------------------------------------------------------------
   Toolbar table-context group — only visible when cursor is in a table cell
   ------------------------------------------------------------------------- */

.toolbar-table-ctx {
  display: none;
  align-items: center;
  gap: 3px;
}

body.in-table-edit .toolbar-table-ctx {
  display: flex;
}

.toolbar-table-sep {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.3);
  margin: 0 4px;
  flex-shrink: 0;
}

body:not(.dark-mode) .toolbar-table-sep {
  background: rgba(0, 0, 0, 0.2);
}

/* -------------------------------------------------------------------------
   Image selection and floating edit bar
   ------------------------------------------------------------------------- */

.editor img {
  cursor: pointer;
  transition: outline 0.1s;
}

.editor img:hover {
  outline: 2px solid rgba(var(--secondary-color-rgb), 0.5);
}

.selected-img {
  outline: 2px solid var(--secondary-color) !important;
}

.img-edit-bar {
  position: fixed;
  z-index: 2000;
  background: #252525;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  pointer-events: all;
}

body:not(.dark-mode) .img-edit-bar {
  background: #fff;
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.img-edit-bar button {
  background: none;
  border: none;
  color: #ccc;
  padding: 4px 7px;
  cursor: pointer;
  font-size: 13px;
  border-radius: 5px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

body:not(.dark-mode) .img-edit-bar button {
  color: #444;
}

.img-edit-bar button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

body:not(.dark-mode) .img-edit-bar button:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #000;
}

.img-edit-bar .img-bar-group {
  display: flex;
  gap: 2px;
}

.img-bar-sep {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.15);
  margin: 0 4px;
  flex-shrink: 0;
}

body:not(.dark-mode) .img-bar-sep {
  background: rgba(0, 0, 0, 0.12);
}

/* Trash button in image bar — accent color on hover */
.img-edit-bar button[title="Delete image"]:hover {
  color: var(--accent-color);
  background: rgba(255, 85, 85, 0.12);
}
/* -------------------------------------------------------------------------
   Definition modal
   ------------------------------------------------------------------------- */
#def-content h2 { font-size: 22px; margin-bottom: 4px; }
#def-content .def-phonetic { color: #888; font-style: italic; margin-bottom: 12px; font-size: 14px; }
#def-content h3.def-pos {
  font-size: 13px; font-style: italic; color: var(--secondary-color);
  text-transform: capitalize; margin: 12px 0 6px; border-bottom: 1px solid #eee; padding-bottom: 4px;
}
body.dark-mode #def-content h3.def-pos { border-bottom-color: #444; }
#def-content .def-item { margin-bottom: 8px; font-size: 14px; line-height: 1.5; }
#def-content .def-num { font-weight: bold; margin-right: 4px; color: var(--accent-color); }
#def-content .def-example { color: #888; font-style: italic; font-size: 13px; margin-top: 3px; padding-left: 12px; }

/* -------------------------------------------------------------------------
   Media modal
   ------------------------------------------------------------------------- */
.media-modal-content {
  min-width: 380px;
  max-width: 520px;
  width: 90%;
}

.media-type-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.media-type-btn {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.media-type-btn.active {
  background: var(--secondary-color);
  border-color: var(--secondary-color);
  color: #fff;
}

body.dark-mode .media-type-btn { border-color: #555; }
body.dark-mode .media-type-btn.active { color: #fff; }

.media-src-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #ddd;
  margin-bottom: 14px;
}

body.dark-mode .media-src-tabs { border-bottom-color: #555; }

.media-src-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  color: #666;
  transition: color 0.15s, border-color 0.15s;
  width: auto;
}

.media-src-btn.active {
  color: var(--accent-color);
  border-bottom-color: var(--accent-color);
}

body.dark-mode .media-src-btn { color: #bbb; }

.rec-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}

.rec-timer {
  font-size: 24px;
  font-family: monospace;
  font-weight: bold;
  min-width: 70px;
  color: inherit;
}

.rec-start-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--secondary-color);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  transition: filter 0.15s;
  width: auto !important;
}

.rec-start-btn.recording {
  background: var(--accent-color);
  animation: recPulse 1s infinite;
}

@keyframes recPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

.rec-start-btn:hover { filter: brightness(1.1); }

.media-insert-btn {
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  background: var(--secondary-color);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: filter 0.15s;
}
.media-insert-btn:hover { filter: brightness(1.08); }

/* ── Audio / Video elements inside editor ── */
.editor audio, .editor video {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin: 8px 0;
}
.editor video { background: #000; }
/* ── Table-context group labels (toolbar + context menu) ── */
.tbl-group-label,
.tbl-ctx-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #888;
  padding: 0 2px;
  user-select: none;
  white-space: nowrap;
  align-self: center;
}

body.dark-mode .tbl-group-label,
body.dark-mode .tbl-ctx-label {
  color: #666;
}

/* Toolbar label inside toolbar-table-ctx flex container */
.toolbar-table-ctx .tbl-group-label {
  margin-left: 4px;
}
.toolbar-table-ctx .tbl-group-label:first-of-type {
  margin-left: 2px;
}

/* Context menu table section — wrap onto multiple rows with label alignment */
.table-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  max-height: none;    /* remove old 35px cap */
  margin-top: 4px;
  padding: 2px 0;
}

.tbl-ctx-label {
  width: 100%;        /* each label forces a new row */
  margin-top: 4px;
  margin-bottom: 1px;
  padding-left: 2px;
}
.tbl-ctx-label:first-child {
  margin-top: 0;
}
/* ── Unified modal divider ("or paste a URL") ── */
.unified-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 10px;
  color: #999;
  font-size: 12px;
}
.unified-divider::before,
.unified-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #ddd;
}
body.dark-mode .unified-divider::before,
body.dark-mode .unified-divider::after {
  background: #444;
}
body.dark-mode .unified-divider { color: #666; }

/* Dark-mode URL input in image modal */
body.dark-mode #image-url,
body.dark-mode #image-url:focus {
  background: #333;
  color: #e0e0e0;
  border-color: #555;
}
#image-url:focus {
  outline: 2px solid var(--secondary-color);
  border-color: transparent;
}

/* Dark-mode color picker popup */
body.dark-mode #color-picker-popup {
  background: #2c2c2c;
  border-color: #444;
}
body.dark-mode #color-picker-popup #color-hex-input {
  background: #333;
  color: #e0e0e0;
  border-color: #555;
}
body.dark-mode #color-picker-popup #color-preview {
  border-color: #555;
}
body.dark-mode #color-picker-popup #color-sb-canvas {
  border-color: #444;
}

/* Dark-mode video modal URL input */
body.dark-mode #vid-url,
body.dark-mode #vid-url:focus {
  background: #333;
  color: #e0e0e0;
  border-color: #555;
}
#vid-url:focus {
  outline: 2px solid var(--secondary-color);
  border-color: transparent;
}