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

:root {
  --bg: #fafafa;
  --sidebar-bg: #f0f0f0;
  --border: #ddd;
  --text: #1a1a1a;
  --text-muted: #888;
  --accent: #2563eb;
  --tag-bg: #e0e7ff;
  --tag-text: #3730a3;
  --active-bg: #e2e8f0;
  --hover-bg: #f1f5f9;
}

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

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

/* Sidebar */
#sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  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(--border);
}

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

.sidebar-header button {
  width: 32px; height: 32px;
  border: none; border-radius: 8px;
  background: var(--accent); color: white;
  font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.sidebar-filters { padding: 12px 16px; border-bottom: 1px solid var(--border); }

#search {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: white;
  outline: none;
}
#search:focus { border-color: var(--accent); }

.folder-tabs {
  display: flex; gap: 4px; margin-top: 8px;
}

.tab {
  flex: 1; padding: 6px; border: none; border-radius: 6px;
  background: transparent; cursor: pointer;
  font-size: 13px; color: var(--text-muted);
}
.tab.active { background: white; color: var(--text); font-weight: 500; }

#tag-filter {
  display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px;
  max-height: 0; overflow: hidden; transition: max-height 0.2s;
}
#tag-filter.open { max-height: 200px; overflow-y: auto; }

#tag-toggle {
  display: block; width: 100%; margin-top: 8px; padding: 4px;
  border: none; background: transparent; cursor: pointer;
  font-size: 12px; color: var(--text-muted); text-align: center;
}
#tag-toggle:hover { color: var(--text); }

.tag-pill {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px 8px; border-radius: 12px;
  font-size: 12px; cursor: pointer;
  background: var(--tag-bg); color: var(--tag-text);
  border: none;
}
.tag-pill.active { background: var(--accent); color: white; }
.tag-pill .count { opacity: 0.7; margin-left: 2px; }

#draft-list {
  list-style: none; overflow-y: auto; flex: 1;
}

#draft-list li {
  padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
#draft-list li:hover { background: var(--hover-bg); }
#draft-list li.active { background: var(--active-bg); }

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

.draft-preview {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}

.draft-meta {
  display: flex; align-items: center; gap: 6px; margin-top: 4px;
  font-size: 11px; color: var(--text-muted);
}

.draft-meta .tag-pill { font-size: 10px; padding: 1px 6px; }

/* Editor */
#editor-pane {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

#editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}

#editor-meta { font-size: 12px; color: var(--text-muted); }
#editor-tags .tag-pill { margin-left: 4px; }

#editor-actions { display: flex; gap: 4px; }
#editor-actions button {
  width: 36px; height: 36px;
  border: none; border-radius: 8px;
  background: transparent; cursor: pointer;
  font-size: 16px;
}
#editor-actions button:hover { background: var(--hover-bg); }

#editor-container {
  flex: 1; overflow: hidden; display: none;
}

/* EasyMDE overrides */
.EasyMDEContainer { height: 100%; display: flex; flex-direction: column; border: none !important; }
.EasyMDEContainer .CodeMirror {
  flex: 1; border: none !important; border-radius: 0 !important;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 14px;
  padding: 16px;
}
.editor-toolbar { border-bottom: 1px solid var(--border) !important; }

#empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 16px;
}

/* Dialogs */
dialog {
  border: none; border-radius: 12px;
  padding: 24px; min-width: 320px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
dialog::backdrop { background: rgba(0,0,0,0.3); }
dialog h3 { margin-bottom: 16px; }

#tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
#tag-list .tag-pill { cursor: pointer; }
#tag-list .tag-pill:hover { text-decoration: line-through; }

.tag-input-row { display: flex; gap: 8px; margin-bottom: 16px; }
.tag-input-row input {
  flex: 1; padding: 8px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px;
}
.tag-input-row button, .dialog-close {
  padding: 8px 16px; border: none; border-radius: 6px;
  background: var(--accent); color: white; cursor: pointer;
  font-size: 14px;
}
.dialog-close { background: var(--sidebar-bg); color: var(--text); display: block; width: 100%; }

#version-list { list-style: none; max-height: 400px; overflow-y: auto; margin-bottom: 16px; }
#version-list li {
  padding: 8px; border-bottom: 1px solid var(--border); cursor: pointer;
  font-size: 13px;
}
#version-list li:hover { background: var(--hover-bg); }
.version-date { font-weight: 500; }
.version-preview { color: var(--text-muted); margin-top: 2px; }

/* Version detail */
#versions-dialog { max-width: 640px; width: 90vw; }
#version-detail-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
}
#version-back {
  border: none; background: none; cursor: pointer; font-size: 16px; padding: 4px 8px;
  border-radius: 6px; color: var(--accent);
}
#version-back:hover { background: var(--hover-bg); }
#version-detail-date { flex: 1; font-size: 13px; color: var(--text-muted); }
#version-detail-actions { display: flex; gap: 4px; }
.version-mode-btn {
  padding: 4px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: white; cursor: pointer; font-size: 13px;
}
.version-mode-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
#version-content {
  max-height: 60vh; overflow-y: auto; padding: 12px;
  background: white; border: 1px solid var(--border); border-radius: 8px;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px;
  white-space: pre-wrap; line-height: 1.6;
}
#version-content .diff-add { background: #d4edda; color: #155724; }
#version-content .diff-del { background: #f8d7da; color: #721c24; text-decoration: line-through; }
#version-content .diff-ctx { color: var(--text-muted); }

/* Mobile */
.mobile-only { display: none; }

@media (max-width: 768px) {
  #sidebar { position: fixed; left: -100%; top: 0; bottom: 0; width: 85%; z-index: 100; transition: left 0.2s; }
  #sidebar.open { left: 0; }
  .mobile-only { display: block; }
  #btn-sidebar-toggle {
    border: none; background: none; font-size: 24px; cursor: pointer;
  }
}
