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

:root {
  --bg: #F4ECD8;
  --accent: #005B46;
  --accent-20: rgba(0, 91, 70, 0.2);
  --code-bg: rgba(128, 128, 128, 0.15);
  --text: #1c1c1e;
  --text-secondary: #8e8e93;
  --sidebar-w: 300px;
}

html,
body {
  height: 100%;
}

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

#app {
  display: flex;
  height: 100%;
}

/* ---- Sidebar ---- */

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(0, 0, 0, 0.1);
  height: 100%;
}

.header {
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  min-height: 44px;
  flex-shrink: 0;
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
}

.header button {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header button:hover {
  background: rgba(255, 255, 255, 0.15);
}

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

.note-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
}

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

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

.note-item-content {
  flex: 1;
  min-width: 0;
}

.note-title {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-date {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.note-chevron {
  color: var(--text-secondary);
  font-size: 14px;
  margin-left: 8px;
  flex-shrink: 0;
}

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

#editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
}

#editor-header {
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 8px 16px;
  min-height: 44px;
  flex-shrink: 0;
}

#back-btn {
  display: none;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  margin-right: 4px;
  align-items: center;
  justify-content: center;
}

#editor-header-spacer {
  flex: 1;
}

#menu-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#menu-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

#menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  min-width: 160px;
  z-index: 100;
  overflow: hidden;
}

#menu-dropdown.open {
  display: block;
}

#menu-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  border: none;
  background: none;
  font-size: 15px;
  cursor: pointer;
  color: #ff3b30;
}

#menu-dropdown button:hover {
  background: #f2f2f7;
}

#editor {
  flex: 1;
  padding: 16px 12px;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.5;
  outline: none;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  caret-color: var(--accent);
  -webkit-overflow-scrolling: touch;
}

#editor ::selection {
  background: var(--accent-20);
}

#editor:empty::before {
  content: "Start typing…";
  color: var(--text-secondary);
  pointer-events: none;
}

/* Markdown styles inside editor */
#editor .md-h1 {
  font-size: 28px;
  font-weight: 700;
}

#editor .md-h2 {
  font-size: 22px;
  font-weight: 700;
}

#editor .md-h3 {
  font-size: 20px;
  font-weight: 700;
}

#editor .md-bold {
  font-weight: 700;
}

#editor .md-italic {
  font-style: italic;
}

#editor .md-code {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code-bg);
  border-radius: 3px;
  padding: 1px 3px;
}

#editor .md-line {
  min-height: 1.5em;
}

#editor .md-list {
  padding-left: 10px;
}

.header-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---- Settings modal ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.modal-content h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.modal-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.modal-content input[type="text"],
.modal-content input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  background: #fff;
  outline: none;
  margin-bottom: 16px;
  font-family: inherit;
}

.modal-content input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-20);
}

.modal-token-row {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.modal-token-row input {
  flex: 1;
  margin-bottom: 0 !important;
}

.modal-token-row button {
  background: none;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  width: 42px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-token-row button:hover {
  background: rgba(0, 0, 0, 0.05);
}

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

.modal-actions button {
  padding: 8px 20px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  cursor: pointer;
  font-weight: 500;
}

#settings-cancel {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text);
}

#settings-cancel:hover {
  background: rgba(0, 0, 0, 0.14);
}

#settings-save {
  background: var(--accent);
  color: #fff;
}

#settings-save:hover {
  opacity: 0.9;
}

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

@media (max-width: 767px) {
  #sidebar {
    width: 100%;
  }

  #editor-pane {
    width: 100%;
  }

  #app:not(.show-editor) #editor-pane {
    display: none;
  }

  #app.show-editor #sidebar {
    display: none;
  }

  #app.show-editor #back-btn {
    display: flex;
  }
}

@media (min-width: 768px) {
  #back-btn {
    display: none !important;
  }
}
