:root {
  --sidebar-bg: #f4f2ee;
  --content-bg: #ffffff;
  --list-bg: #fbfaf8;
  --ink: #1c1c1e;
  --ink-soft: #6e6e73;
  --accent: #ffb400;      /* Apple's folder-icon yellow */
  --select: #cfe4ff;      /* macOS list selection blue */
  --select-text: #0a3d7a;
  --line: #e2e1de;
  --danger: #ff3b30;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--content-bg);
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--ink-soft); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }
.info { color: #1e7d3c; font-size: 13px; min-height: 18px; }

.link-btn {
  background: none;
  border: none;
  color: #007aff;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 0;
}
.link-btn:hover { opacity: 0.7; }
.link-btn.danger { color: var(--danger); }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--ink-soft);
  padding: 2px 6px;
  border-radius: 6px;
  line-height: 1;
}
.icon-btn:hover { background: rgba(0,0,0,0.06); }
.icon-btn.active { color: var(--accent); }
.icon-btn.danger:hover { color: var(--danger); background: rgba(255,59,48,0.08); }

/* Auth page */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--sidebar-bg);
}
.auth-card {
  width: 100%;
  max-width: 340px;
  background: var(--content-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 700; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.auth-card input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
  background: #fff;
}
.auth-card input:focus { border-color: #007aff; box-shadow: 0 0 0 3px rgba(0,122,255,0.15); }
.auth-card button[type="submit"] {
  background: #007aff;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.auth-card button[type="submit"]:hover { background: #0064d6; }
.auth-card button[type="submit"]:disabled { opacity: 0.6; }

/* App layout */
.layout {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
}
.sidebar-header { padding: 18px 16px 10px; }
.sidebar-header h1 { margin: 0; font-size: 20px; font-weight: 700; }

.folder-nav { flex: 1; overflow-y: auto; padding: 4px 8px; }
.folder-row { display: flex; align-items: center; }
.folder-item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  background: none;
  border: none;
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
}
.folder-item span:last-child { overflow: hidden; text-overflow: ellipsis; }
.folder-icon { flex-shrink: 0; filter: saturate(1.3); }
.folder-item:hover { background: rgba(0,0,0,0.05); }
.folder-item.active { background: var(--select); color: var(--select-text); font-weight: 600; }
.folder-delete {
  background: none;
  border: none;
  color: rgba(28,28,30,0.3);
  cursor: pointer;
  padding: 0 8px;
  font-size: 16px;
}
.folder-delete:hover { color: var(--danger); }

.new-folder-row { padding: 4px 12px 8px; }
.new-folder-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 14px;
  outline: none;
}
.new-folder-input:focus { border-color: #007aff; }

.sidebar-footer {
  border-top: 1px solid var(--line);
  padding: 10px 16px;
}
.sidebar-footer p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.note-list {
  width: 300px;
  flex-shrink: 0;
  background: var(--list-bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.note-list-header {
  padding: 16px 16px 4px;
}
.note-list-header h2 { margin: 0; font-size: 22px; font-weight: 700; }

.search-row { padding: 8px 12px 8px; }
.search-wrap { position: relative; display: flex; align-items: center; }
.search-icon {
  position: absolute;
  left: 10px;
  font-size: 12px;
  opacity: 0.5;
  pointer-events: none;
}
.search-input {
  width: 100%;
  border: none;
  border-radius: 9px;
  padding: 7px 10px 7px 28px;
  font-size: 13px;
  outline: none;
  background: rgba(120,120,128,0.12);
}
.search-input:focus { background: rgba(120,120,128,0.18); }

.note-list-items { flex: 1; overflow-y: auto; }

.note-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  cursor: pointer;
  position: relative;
}
.note-item:hover { background: rgba(0,0,0,0.03); }
.note-item.active { background: var(--select); }
.note-item.active .preview { color: var(--select-text); opacity: 0.75; }
.note-item .title-row { display: flex; align-items: center; gap: 5px; }
.note-item .pin-mark { font-size: 10px; }
.note-item .title { font-size: 14px; font-weight: 600; margin: 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.note-item .preview { font-size: 12px; color: var(--ink-soft); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  gap: 4px;
}
.note-item:hover .note-item-actions { display: flex; }
.quick-action {
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  color: var(--ink-soft);
}
.quick-action.active { color: var(--accent); }
.quick-action.danger:hover { color: var(--danger); }
.empty-note { padding: 24px 16px; color: var(--ink-soft); font-size: 14px; }

.note-list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
}
.compose-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: #007aff;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
}
.compose-btn:hover { background: rgba(0,122,255,0.1); }

.editor {
  flex: 1;
  background: var(--content-bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.editor-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(28,28,30,0.3);
  font-size: 14px;
}
.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
}
.editor-actions { display: flex; align-items: center; gap: 6px; }
.editor-actions select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  background: #fff;
  color: var(--ink);
  margin-right: 4px;
}

.format-toolbar {
  display: flex;
  gap: 2px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--line);
}
.fmt-btn {
  background: rgba(120,120,128,0.08);
  border: none;
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
}
.fmt-btn:hover { background: rgba(120,120,128,0.16); }

.note-title {
  border: none;
  outline: none;
  font-size: 22px;
  font-weight: 700;
  padding: 18px 24px 4px;
  color: var(--ink);
}
.note-title::placeholder { color: rgba(28,28,30,0.3); }
.note-content {
  flex: 1;
  outline: none;
  font-size: 15px;
  line-height: 1.55;
  padding: 4px 24px 16px;
  font-family: inherit;
  white-space: pre-wrap;
  overflow-y: auto;
  color: var(--ink);
}
.note-content ul, .note-content ol { padding-left: 22px; margin: 6px 0; }
.note-content:empty:before {
  content: attr(data-placeholder);
  color: rgba(28,28,30,0.3);
}

.attachments {
  border-top: 1px solid var(--line);
  padding: 10px 24px 20px;
}
.attachments-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.attachment-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.attachment-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(120,120,128,0.08);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.attachment-list a { color: var(--ink); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-list a:hover { color: #007aff; text-decoration: underline; }
.attachment-list .size { color: var(--ink-soft); font-size: 11px; white-space: nowrap; }
.attachment-list button {
  background: none;
  border: none;
  color: rgba(28,28,30,0.35);
  cursor: pointer;
  font-size: 13px;
}
.attachment-list button:hover { color: var(--danger); }

.back-btn {
  display: none;
  background: none;
  border: none;
  color: #007aff;
  font-size: 15px;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 2px;
}

@media (max-width: 860px) {
  html, body { height: 100%; overflow: hidden; }

  .layout {
    position: relative;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .sidebar, .note-list, .editor {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
  }

  .sidebar.mobile-hidden,
  .note-list.mobile-hidden,
  .editor.mobile-hidden {
    display: none;
  }

  .back-btn { display: inline-block; }

  .note-list-header { display: flex; flex-direction: column; align-items: flex-start; }

  .editor-toolbar { flex-wrap: wrap; row-gap: 8px; }
  .editor-toolbar .back-btn { flex-basis: 100%; }

  /* Touch targets need more room than mouse-driven hover affordances */
  .note-item-actions { display: flex; }
  .quick-action { width: 30px; height: 30px; font-size: 14px; }
  .icon-btn { font-size: 19px; padding: 6px 8px; }
  .fmt-btn { padding: 7px 13px; font-size: 14px; }
  .compose-btn { width: 38px; height: 38px; font-size: 20px; }
  .folder-item { padding: 9px 8px; }

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