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

:root {
  --sidebar-w: 260px;
  --bg: #f8f9fa;
  --sidebar-bg: #1e1e2e;
  --sidebar-text: #cdd6f4;
  --sidebar-hover: #313244;
  --sidebar-active: #45475a;
  --accent: #89b4fa;
  --border: #e0e0e0;
  --text: #1e1e2e;
  --text-muted: #6c7086;
  --danger: #f38ba8;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); }

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

/* Sidebar */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--sidebar-active);
}
.sidebar-header h1 { font-size: 18px; font-weight: 600; }
.sidebar-actions { display: flex; align-items: center; gap: 8px; }
#sidebar-toggle { display: none; }
#new-note-btn {
  background: var(--accent); color: var(--sidebar-bg); border: none; border-radius: 6px;
  width: 32px; height: 32px; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#new-note-btn:hover { opacity: 0.85; }
#note-list { flex: 1; overflow-y: auto; padding: 8px; }
.note-item {
  padding: 10px 12px; border-radius: 6px; cursor: pointer; margin-bottom: 4px;
  transition: background 0.15s;
}
.note-item:hover { background: var(--sidebar-hover); }
.note-item.active { background: var(--sidebar-active); }
.note-item-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item-date { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Main */
main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 16px; }
.hidden { display: none !important; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); background: #fff;
}
#title-input {
  flex: 1; border: none; outline: none; font-size: 16px; font-weight: 600;
  background: transparent; min-width: 0;
}
.toolbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.view-toggle button {
  border: none; background: #fff; padding: 5px 12px; font-size: 13px;
  cursor: pointer; color: var(--text-muted); transition: all 0.15s;
}
.view-toggle button.active { background: var(--accent); color: #fff; }
.view-toggle button:not(:last-child) { border-right: 1px solid var(--border); }
#save-status { font-size: 12px; color: var(--text-muted); min-width: 50px; text-align: center; }
#delete-btn { background: none; border: none; font-size: 18px; cursor: pointer; padding: 4px; opacity: 0.6; }
#delete-btn:hover { opacity: 1; }

/* Panes */
#panes { flex: 1; display: flex; overflow: hidden; }
#editor {
  flex: 1; border: none; outline: none; resize: none; padding: 20px 24px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; font-size: 14px;
  line-height: 1.7; background: #fff; color: var(--text);
}
#preview {
  flex: 1; padding: 20px 24px; overflow-y: auto; background: #fff;
  border-left: 1px solid var(--border); line-height: 1.7; font-size: 15px;
}

/* View modes */
.view-edit #preview { display: none; }
.view-edit #editor { flex: 1; }
.view-preview #editor { display: none; }
.view-preview #preview { flex: 1; border-left: none; }
.view-split #editor { flex: 1; }
.view-split #preview { flex: 1; }

/* Preview typography */
#preview h1 { font-size: 1.8em; margin: 0.6em 0 0.4em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
#preview h2 { font-size: 1.4em; margin: 0.5em 0 0.3em; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
#preview h3 { font-size: 1.2em; margin: 0.5em 0 0.3em; }
#preview h4, #preview h5, #preview h6 { font-size: 1em; margin: 0.5em 0 0.3em; }
#preview p { margin: 0.6em 0; }
#preview ul, #preview ol { margin: 0.5em 0; padding-left: 1.8em; }
#preview li { margin: 0.2em 0; }
#preview blockquote { border-left: 3px solid var(--accent); margin: 0.6em 0; padding: 0.3em 1em; color: var(--text-muted); background: #f0f4ff; border-radius: 0 4px 4px 0; }
#preview pre { background: #1e1e2e; color: #cdd6f4; padding: 14px 18px; border-radius: 6px; overflow-x: auto; margin: 0.6em 0; font-size: 13px; line-height: 1.5; }
#preview code { font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace; font-size: 0.9em; }
#preview :not(pre) > code { background: #e8ecf1; padding: 2px 6px; border-radius: 3px; }
#preview a { color: var(--accent); }
#preview hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
#preview img { max-width: 100%; border-radius: 4px; }
#preview table { border-collapse: collapse; margin: 0.6em 0; width: 100%; }
#preview th, #preview td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
#preview th { background: #f0f4ff; font-weight: 600; }

/* Mobile */
@media (max-width: 700px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; min-width: 100%; max-height: 45vh; border-bottom: 1px solid var(--sidebar-active); transition: max-height 0.25s ease; }
  #sidebar.collapsed { max-height: none; }
  #sidebar.collapsed #note-list { display: none; }
  #sidebar-toggle {
    display: flex; align-items: center; justify-content: center;
    background: none; border: 1px solid var(--sidebar-active); border-radius: 6px;
    width: 32px; height: 32px; font-size: 16px; cursor: pointer; color: var(--sidebar-text);
  }
  #sidebar-toggle:hover { background: var(--sidebar-hover); }
  #panes { flex-direction: column; }
  .view-split #preview { border-left: none; border-top: 1px solid var(--border); }
  .toolbar { flex-wrap: wrap; }
  #title-input { width: 100%; }
}
