:root {
  --sidebar-bg: #f5f1ea;
  --list-bg: #faf8f4;
  --editor-bg: #ffffff;
  --border: #e0dcd3;
  --text-primary: #2b2b2b;
  --text-secondary: #8a8578;
  --accent: #e8a83c;
  --accent-selected: #f0c060;
  --danger: #d1453b;
  --hover: #efe9df;
  --shadow: rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --sidebar-bg: #232320;
    --list-bg: #292824;
    --editor-bg: #1f1f1c;
    --border: #37362f;
    --text-primary: #ece8df;
    --text-secondary: #8f8a7c;
    --accent: #e8a83c;
    --accent-selected: #6b5322;
    --danger: #e5726a;
    --hover: #322f28;
    --shadow: rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background: var(--editor-bg);
}

.app {
  display: grid;
  grid-template-columns: 220px 280px 1fr;
  height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.18s ease;
}

.app.sidebar-hidden {
  grid-template-columns: 0px 280px 1fr;
}

.app.sidebar-hidden .sidebar {
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Sidebar (projects) ---------- */

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-header {
  padding: 18px 16px 8px;
}

.sidebar-header h1 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.folder-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.folder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  margin-bottom: 1px;
}

.folder-item:hover {
  background: var(--hover);
}

.folder-item.active {
  background: var(--accent-selected);
  color: #2b2b2b;
}

.folder-item .folder-name {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-item .folder-icon {
  font-size: 14px;
  opacity: 0.85;
}

.folder-item .folder-count {
  font-size: 12px;
  color: var(--text-secondary);
}

.folder-item.active .folder-count {
  color: #4a4a4a;
}

.folder-item input.rename-input {
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  outline: none;
  width: 100%;
}

.folder-action {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 0 2px;
}

.folder-item:hover .folder-action {
  display: inline-block;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  text-align: left;
  padding: 4px 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-text .icon {
  color: var(--accent);
  font-weight: 700;
}

.sidebar-io {
  display: flex;
  gap: 8px;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 5px 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-icon:hover {
  background: var(--hover);
}

.btn-icon.danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* ---------- Notes list ---------- */

.notes-list {
  background: var(--list-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.notes-list-header {
  padding: 14px 14px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.notes-list-header .search-box {
  flex: 1;
}

#toggleSidebarBtn {
  flex-shrink: 0;
}

.search-box input {
  width: 100%;
  padding: 6px 10px;
  border-radius: 8px;
  border: none;
  background: var(--hover);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.notes-list-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px 8px;
}

.notes-list-title-row h2 {
  font-size: 22px;
  margin: 0;
  font-weight: 700;
}

.btn-round {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.notes-items {
  list-style: none;
  margin: 0;
  padding: 0 8px 12px;
  overflow-y: auto;
  flex: 1;
}

.note-item {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  border: 1px solid transparent;
}

.note-item:hover {
  background: var(--hover);
}

.note-item.active {
  background: var(--accent-selected);
}

.note-item .note-item-title {
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item .note-item-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.note-item .note-item-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.note-item .note-item-date {
  flex-shrink: 0;
}

.note-item .note-item-activity {
  font-size: 11px;
  color: var(--accent);
  margin-top: 2px;
}

.notes-empty-state {
  padding: 24px 14px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}

/* ---------- Editor ---------- */

.editor {
  background: var(--editor-bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
}

.editor-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 18px 34px;
  overflow-y: auto;
  min-height: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.editor-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mobile-back-btn {
  display: none;
  flex-shrink: 0;
}

.editor-date {
  font-size: 12px;
  color: var(--text-secondary);
}

.editor-actions {
  display: flex;
  gap: 8px;
}

.activity-date-input {
  align-self: flex-start;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--list-bg);
  color: var(--text-primary);
  padding: 4px 6px;
  font-size: 12px;
}

.note-title {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  font-weight: 700;
  resize: none;
  overflow: hidden;
  font-family: inherit;
  padding: 4px 0;
}

.note-body {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14.5px;
  line-height: 1.55;
  resize: none;
  font-family: inherit;
  padding: 4px 0;
  min-height: 200px;
}

/* ---------- Scrollbars ---------- */

.folder-list::-webkit-scrollbar,
.notes-items::-webkit-scrollbar,
.editor-content::-webkit-scrollbar {
  width: 8px;
}

.folder-list::-webkit-scrollbar-thumb,
.notes-items::-webkit-scrollbar-thumb,
.editor-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .app {
    grid-template-columns: 170px 240px 1fr;
  }
  .editor-content {
    padding: 16px 20px;
  }
}

/* Below this width the app switches to a single-panel, drill-down layout:
   Projects -> Notes -> Editor, each shown one at a time via the app's
   data-mobile-view attribute (set in app.js), like the Apple Notes app. */
@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
  }

  .app.sidebar-hidden {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .notes-list,
  .editor {
    display: none;
    width: 100%;
    border-right: none;
  }

  .app[data-mobile-view="projects"] .sidebar {
    display: flex;
  }

  .app[data-mobile-view="list"] .notes-list {
    display: flex;
  }

  .app[data-mobile-view="editor"] .editor {
    display: flex;
  }

  .mobile-back-btn {
    display: inline-flex;
  }

  #toggleSidebarBtn {
    display: none;
  }

  .sidebar-header {
    padding: 20px 16px 10px;
  }

  .sidebar-header h1 {
    font-size: 15px;
  }

  .notes-list-title-row h2 {
    font-size: 26px;
  }

  /* Larger touch targets */
  .folder-item {
    padding: 13px 10px;
    font-size: 15.5px;
  }

  .folder-action {
    display: inline-block;
    font-size: 19px;
    padding: 4px 8px;
  }

  .note-item {
    padding: 14px 12px;
  }

  .note-item .note-item-title {
    font-size: 15.5px;
  }

  .note-item .note-item-meta,
  .note-item .note-item-activity {
    font-size: 13px;
  }

  .btn-icon {
    padding: 8px 12px;
    font-size: 14px;
  }

  .btn-round {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .editor-content {
    padding: 16px;
  }

  .note-title {
    font-size: 24px;
  }

  .editor-toolbar {
    flex-wrap: wrap;
  }

  /* Inputs need >=16px font-size or iOS Safari auto-zooms in on focus */
  .search-box input,
  .note-body,
  .activity-date-input,
  .rename-input {
    font-size: 16px;
  }

  /* Clear the home indicator / gesture bar on notched phones */
  .sidebar-footer {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .editor-content {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}
