*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif;
  font-size: 15px;
  color: #37352f;
  background: #fff;
}

/* Sidebar */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: #f7f6f3;
  border-right: 1px solid #e9e8e5;
  display: flex;
  flex-direction: column;
  padding: 16px 8px;
  overflow-y: auto;
}

#sidebar h1 {
  font-size: 14px;
  font-weight: 600;
  color: #37352f;
  padding: 4px 8px 12px;
  letter-spacing: 0.01em;
}

#new-page-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #37352f;
  font-size: 14px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 8px;
  font-family: inherit;
}
#new-page-btn:hover { background: #ebe9e4; }

#tree { flex: 1; }

.tree-item {
  display: flex;
  align-items: center;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  gap: 4px;
}
.tree-item:hover { background: #ebe9e4; }
.tree-item.active { background: #e3e2de; font-weight: 500; }

.tree-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-btn {
  background: none;
  border: none;
  color: #9b9a97;
  font-size: 12px;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
  line-height: 1;
  font-family: inherit;
  flex-shrink: 0;
}
.tree-btn:hover { background: #d3d1cb; color: #37352f; }

.tree-children { margin-left: 16px; }

/* Main */
#main {
  flex: 1;
  overflow-y: auto;
  padding: 60px 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#empty-state {
  color: #9b9a97;
  font-size: 15px;
  margin-top: 40px;
}

#page-view {
  width: 100%;
  max-width: 760px;
}

#page-title {
  font-size: 40px;
  font-weight: 700;
  color: #37352f;
  outline: none;
  border: none;
  width: 100%;
  margin-bottom: 24px;
  line-height: 1.2;
  caret-color: #37352f;
}
#page-title:empty::before { content: "Untitled"; color: #c7c6c3; }

/* Blocks */
#blocks-area { width: 100%; }

.block-wrap {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 2px 0;
  position: relative;
}
.block-wrap:hover .block-type-select { opacity: 1; }

.block-type-select {
  opacity: 0;
  font-size: 11px;
  border: 1px solid #e0dfdb;
  border-radius: 3px;
  background: #fff;
  color: #9b9a97;
  padding: 1px 2px;
  cursor: pointer;
  margin-top: 3px;
  flex-shrink: 0;
  font-family: inherit;
  transition: opacity 0.1s;
}
.block-type-select:hover { opacity: 1; }

.block {
  flex: 1;
  outline: none;
  border: none;
  font-size: 15px;
  color: #37352f;
  font-family: inherit;
  line-height: 1.6;
  padding: 3px 6px;
  border-radius: 3px;
  min-height: 28px;
  word-break: break-word;
}
.block:focus { background: #f7f6f3; }
.block:empty::before { content: "Type something…"; color: #c7c6c3; pointer-events: none; }

.block.heading {
  font-size: 24px;
  font-weight: 600;
  margin-top: 12px;
}
.block.heading:empty::before { content: "Heading"; color: #c7c6c3; pointer-events: none; }

.block-divider {
  flex: 1;
  border: none;
  border-top: 2px solid #e9e8e5;
  margin: 8px 0;
}

.block-todo-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  padding: 3px 6px;
  border-radius: 3px;
}
.block-todo-wrap:focus-within { background: #f7f6f3; }

.todo-check {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #37352f;
}
.todo-text {
  flex: 1;
  outline: none;
  border: none;
  font-size: 15px;
  color: #37352f;
  font-family: inherit;
  line-height: 1.6;
  background: none;
}
.todo-text:empty::before { content: "To-do"; color: #c7c6c3; pointer-events: none; }
.todo-text.checked { text-decoration: line-through; color: #9b9a97; }

/* Quote block */
.block.quote {
  border-left: 3px solid #d3d1cb;
  font-style: italic;
  color: #6b6969;
  padding-left: 14px;
  margin-left: 2px;
}
.block.quote:empty::before { content: "Quote"; color: #c7c6c3; pointer-events: none; }

/* Bullet block */
.block.bullet {
  position: relative;
  padding-left: 22px;
}
.block.bullet::before {
  content: "•";
  position: absolute;
  left: 6px;
  color: #37352f;
  pointer-events: none;
}
.block.bullet:empty::before {
  content: "• List item";
  left: 6px;
  color: #c7c6c3;
  pointer-events: none;
}

/* Number block */
.block.number {
  position: relative;
  padding-left: 28px;
}
.block.number::before {
  content: "1.";
  position: absolute;
  left: 6px;
  color: #37352f;
  pointer-events: none;
}
.block.number:empty::before {
  content: "1. Numbered item";
  left: 6px;
  color: #c7c6c3;
  pointer-events: none;
}

/* Code block */
.block.code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  background: #f5f5f4;
  border-radius: 4px;
  padding: 10px 14px;
  white-space: pre-wrap;
  color: #37352f;
}
.block.code:empty::before { content: "Code"; color: #c7c6c3; pointer-events: none; }
.block.code:focus { background: #eeede9; }

/* Export button */
.export-md-btn {
  background: none;
  border: 1px solid #e0dfdb;
  color: #9b9a97;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  margin-top: 8px;
  margin-left: 8px;
}
.export-md-btn:hover { background: #f7f6f3; color: #37352f; }

/* Tables */
#tables-area { width: 100%; margin-top: 24px; }

.add-table-btn, .add-row-btn {
  background: none;
  border: 1px solid #e0dfdb;
  color: #9b9a97;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  margin-top: 8px;
}
.add-table-btn:hover, .add-row-btn:hover { background: #f7f6f3; color: #37352f; }

.table-block {
  margin: 16px 0;
  overflow-x: auto;
}

.table-block h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #37352f;
}

.notion-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.notion-table th, .notion-table td {
  border: 1px solid #e9e8e5;
  padding: 6px 10px;
  text-align: left;
  min-width: 120px;
}
.notion-table th {
  background: #f7f6f3;
  font-weight: 600;
  color: #37352f;
  font-size: 13px;
}
.notion-table td input[type="text"] {
  border: none;
  outline: none;
  width: 100%;
  font-size: 14px;
  font-family: inherit;
  color: #37352f;
  background: transparent;
}
.notion-table td input[type="checkbox"] {
  cursor: pointer;
  accent-color: #37352f;
}
.row-del-btn {
  background: none;
  border: none;
  color: #c7c6c3;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: inherit;
}
.row-del-btn:hover { background: #fee2e2; color: #ef4444; }

/* Error banner */
#err {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 14px;
  display: none;
  z-index: 9999;
  max-width: 400px;
  text-align: center;
}

/* Per-page color selector */
#color-bar {
  display: flex;
  gap: 8px;
  margin: -8px 0 28px;
  align-items: center;
}
.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: transform 0.1s ease, border-color 0.1s ease;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px #b8b7b3;
}

/* Sidebar search */
#page-search {
  display: block;
  width: calc(100% - 16px);
  margin: 0 8px 8px;
  padding: 6px 8px;
  background: #fff;
  border: 1px solid #e9e8e5;
  border-radius: 4px;
  font-size: 13px;
  color: #37352f;
  outline: none;
  font-family: inherit;
}
#page-search:focus { border-color: #b8b7b3; }

#search-no-match {
  padding: 8px;
  color: #9b9a97;
  font-size: 12px;
}
