:root {
  --bg-color: #ffffff;
  --sidebar-bg: #f7f7f5;
  --text-primary: #37352f;
  --text-secondary: rgba(55, 53, 47, 0.6);
  --hover-bg: rgba(55, 53, 47, 0.08);
  --selection-bg: rgba(35, 131, 226, 0.14);
  --border-color: #e1e1e0;
  --accent-color: #2383e2;
  --danger-color: #eb5757;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  margin: 0;
  padding: 0;
  height: 100vh;
  /* Full viewport height */
  display: flex;
  color: var(--text-primary);
  background-color: var(--bg-color);
  overflow: hidden;
  /* Prevent body scroll, handle in containers */
}

/* Main Content Layout (Columns 2 & 3) */
#main-wrapper {
  flex-grow: 1;
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
  background-color: var(--bg-color);
}

/* Middle Column (Editor + Toolbar) */
#main {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  overflow: hidden;
  min-width: 0;
  /* Important for flex text wrapping */
}

/* Right Column (TOC) */
#toc-sidebar {
  width: 240px;
  /* Column 3 fixed width */
  border-left: 1px solid var(--border-color);
  background: #fafafa;
  padding: 24px 16px;
  flex-shrink: 0;
  overflow-y: auto;
  /* Independent scroll */
  display: none;
  /* Hidden by default if empty */
  height: 100%;
}

/* Toolbar Styles */
#toolbar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  z-index: 100;
  gap: 4px;
  flex-shrink: 0;
  /* Prevent toolbar shrinking */
}

/* ... (buttons styles remain) ... */

/* Editor Container */
.editor-container {
  flex-grow: 1;
  flex-basis: 0;
  /* Important for scroll in flex */
  min-height: 0;
  /* Important for scroll in flex */
  overflow-y: auto;
  padding: 40px 60px;
  max-width: 850px;
  margin: 0 auto;
  width: 100%;
}

.toolbar-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all 0.2s;
  font-family: inherit;
}

.toolbar-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.toolbar-btn[data-command="bold"] {
  font-weight: bold;
}

.toolbar-btn[data-command="italic"] {
  font-style: italic;
}

.toolbar-btn[data-command="underline"] {
  text-decoration: underline;
}

.toolbar-btn[data-command="strikeThrough"] {
  text-decoration: line-through;
}

.toolbar-separator {
  color: var(--border-color);
  margin: 0 4px;
  font-size: 14px;
}


/* Sidebar Styles */
#sidebar-toggle-btn {
  position: absolute;
  top: 600px;
  left: 12px;
  z-index: 200;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  /* Flex to center icon */
}

#sidebar-toggle-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.sidebar {
  width: 260px;
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  flex-shrink: 0;
  transition: transform 0.3s ease, width 0.3s ease;
  padding-top: 50px;
  /* Space for toggle button */
}

.sidebar.collapsed {
  width: 0;
  transform: translateX(-100%);
  padding: 0;
  border: none;
  overflow: hidden;
}

.sidebar-header {
  padding: 0 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#new-page-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}

#new-page-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.note-list {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.note-item {
  display: flex;
  justify-content: space-between;
  /* To push delete button to right */
  align-items: center;
  padding: 6px 12px;
  margin-bottom: 2px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.1s ease;
  user-select: none;
  height: 32px;
}

.note-item:hover {
  background-color: var(--hover-bg);
  color: var(--text-primary);
}

.note-item.active {
  background-color: var(--hover-bg);
  color: var(--text-primary);
  font-weight: 600;
}

.note-title-span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-grow: 1;
}

.delete-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--subtle-text);
  cursor: pointer;
  padding: 4px;
  margin-left: 8px;
  border-radius: 4px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.note-item:hover .delete-btn {
  opacity: 0.6;
}

.delete-btn:hover {
  opacity: 1 !important;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}

.toc-item:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.toc-h1 {
  margin-left: 0;
  font-weight: 500;
}

.toc-h2 {
  margin-left: 12px;
}

.toc-h3 {
  margin-left: 24px;
}


/* Editor Container */
/* OLD Editor Container rule removed/updated effectively here */
.editor-container {
  flex-grow: 1;
  flex-basis: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 40px 60px;
  max-width: 850px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 1024px) {
  #toc-sidebar {
    display: none !important;
    /* Hide TOC on tablets portrait/smaller laptops if space is tight, or maybe overlay */
  }
}

@media (max-width: 768px) {
  .editor-container {
    padding: 20px 16px;
  }

  /* Mobile Sidebar behavior */
  .sidebar {
    position: absolute;
    height: 100%;
    z-index: 150;
    transform: translateX(0);
    width: 80%;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    width: 80%;
    /* Keep width so it slides out nicely */
  }

  /* When sidebar is open on mobile, maybe dim content? */
}

/* Title Input */
#note-title {
  font-size: 40px;
  font-weight: 700;
  color: var(--text-primary);
  border: none;
  outline: none;
  width: 100%;
  margin-bottom: 24px;
  background: transparent;
  line-height: 1.2;
}

#note-title::placeholder {
  color: var(--text-secondary);
  opacity: 0.4;
}

/* Content Editor */
#note-content {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  min-height: 60vh;
  outline: none;
  white-space: pre-wrap;
  /* Preserve whitespace but wrap text */
}

#note-content:empty:before {
  content: 'Type / for commands...';
  /* Just a static placeholder for aesthetics */
  color: var(--text-secondary);
  opacity: 0.5;
}

/* Status Bar */
#status-bar {
  position: absolute;
  bottom: 0px;
  right: 20px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.8);
  pointer-events: none;
  transition: opacity 0.3s;
  opacity: 0;
}

#status-bar.visible {
  opacity: 1;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* Markdown Elements Styling */
#note-content h1,
#note-content h2,
#note-content h3 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

#note-content h1 {
  font-size: 2.0em;
}

#note-content h2 {
  font-size: 1.5em;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.3em;
}

#note-content h3 {
  font-size: 1.25em;
}

#note-content ul,
#note-content ol {
  padding-left: 1.5em;
}

#note-content blockquote {
  border-left: 3px solid var(--text-primary);
  margin: 1em 0;
  padding-left: 1em;
  color: var(--text-secondary);
  background: var(--hover-bg);
  padding: 0.5em 1em;
  border-radius: 0 4px 4px 0;
}

#note-content code {
  background: rgba(135, 131, 120, 0.15);
  color: #EB5757;
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 85%;
}

#note-content pre {
  background: #f7f6f3;
  padding: 16px;
  border-radius: 4px;
  overflow-x: auto;
}

#note-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 85%;
}

#note-content hr {
  border: 0;
  border-top: 1px solid var(--border-color);
  margin: 2em 0;
}

#note-content img {
  max-width: 100%;
  border-radius: 4px;
}

/* Checkbox specific styling */
#note-content input[type="checkbox"] {
  margin-right: 0.5em;
}

#note-content a {
  color: var(--accent-color);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

#note-content a:hover {
  border-bottom-color: var(--accent-color);
  cursor: pointer;
}