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

:root {
  --bg: #0f1117;
  --bg-surface: #1c1d27;
  --bg-hover: #262733;
  --bg-input: #14151d;
  --border: #363848;
  --border-focus: #6366f1;
  --text: #f0f0f3;
  --text-muted: #9ca3af;
  --text-dim: #71717a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 260px;
  --header-h: 56px;
}

html { font-size: 15px; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }

/* Login */
.screen { display: flex; }
.screen[hidden] { display: none; }
#login-screen { align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 2.5rem 2rem; width: 360px; text-align: center; }
.login-logo { color: var(--accent); margin-bottom: 1rem; }
.login-card h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: 0.25rem; }
.login-subtitle { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.5rem; }
.login-card input {
  width: 100%; padding: 0.65rem 0.85rem; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.9rem; margin-bottom: 1rem; outline: none; transition: border-color 0.15s;
}
.login-card input:focus { border-color: var(--border-focus); }
.login-card button {
  width: 100%; padding: 0.65rem; background: var(--accent); color: white; border: none;
  border-radius: var(--radius); font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: background 0.15s;
}
.login-card button:hover { background: var(--accent-hover); }
.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }

/* Header */
header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); z-index: 100;
  background: var(--bg-surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 1.25rem;
}
.header-left, .header-right { display: flex; align-items: center; gap: 0.75rem; }
.header-title { font-size: 1rem; font-weight: 600; }
.icon-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 6px;
  border-radius: var(--radius); transition: all 0.15s; display: flex; align-items: center;
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }

/* Layout */
.layout { display: flex; padding-top: var(--header-h); min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w); background: var(--bg-surface);
  border-right: 1px solid var(--border); padding: 1rem 0; overflow-y: auto;
  position: fixed; top: var(--header-h); bottom: 0; left: 0; transition: transform 0.2s;
}
.sidebar.collapsed { transform: translateX(-100%); }
.sidebar-section { padding: 0.5rem 0.75rem; }
.sidebar-label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); padding: 0.5rem 0.75rem 0.35rem; }
.sidebar-link {
  display: flex; align-items: center; gap: 0.5rem; width: 100%; padding: 0.45rem 0.75rem;
  background: none; border: none; color: var(--text-muted); font-size: 0.85rem;
  border-radius: var(--radius); cursor: pointer; transition: all 0.15s; text-align: left;
}
.sidebar-link:hover { color: var(--text); background: var(--bg-hover); }
.sidebar-link.active { color: var(--text); background: var(--bg-hover); }

/* Main */
main {
  flex: 1; margin-left: var(--sidebar-w); padding: 1.5rem 2rem;
  width: calc(100% - var(--sidebar-w)); min-width: 0;
  transition: margin-left 0.2s;
}
main.expanded { margin-left: 0; }

.view-header { margin-bottom: 1.5rem; }
.view-header h2 { font-size: 1.35rem; font-weight: 700; }
.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.text-danger { color: var(--danger); }

.dashboard-header { display: flex; align-items: center; justify-content: space-between; }
.dashboard-header .btn-sm { display: flex; align-items: center; gap: 0.35rem; }

.btn-text {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 0.85rem; padding: 0; margin-bottom: 0.5rem; transition: color 0.15s;
}
.btn-text:hover { color: var(--text); }

.btn-sm {
  padding: 0.35rem 0.85rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-surface); color: var(--text); font-size: 0.8rem; cursor: pointer; transition: all 0.15s;
}
.btn-sm:hover { background: var(--bg-hover); }
.btn-sm.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-sm.btn-primary:hover { background: var(--accent-hover); }

/* Breadcrumbs */
.breadcrumb { padding: 0 0 1rem; font-size: 0.8rem; color: var(--text-muted); }
.breadcrumb a { color: var(--text-muted); text-decoration: none; transition: color 0.15s; }
.breadcrumb a:hover { color: var(--text); }
.bc-sep { margin: 0 0.4rem; color: var(--text-dim); }
.bc-current { color: var(--text); }

/* Recent Files */
.recent-files-section { margin-bottom: 1.75rem; }
.recent-files-section h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--text-muted); }
.recent-files-grid { display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.5rem; }
.recent-files-grid::-webkit-scrollbar { height: 4px; }
.recent-files-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.recent-file-item {
  flex-shrink: 0; min-width: 160px; max-width: 220px; padding: 0.65rem 0.85rem;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: all 0.15s;
}
.recent-file-item:hover { border-color: var(--text-dim); background: var(--bg-hover); }
.recent-file-name { display: block; font-size: 0.8rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-file-project { display: block; font-size: 0.7rem; color: var(--text-muted); }
.recent-file-time { display: block; font-size: 0.65rem; color: var(--text-dim); }

/* Project Grid (card view) */
.project-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; width: 100%; }
@media (min-width: 1200px) { .project-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1600px) { .project-grid { grid-template-columns: repeat(4, 1fr); } }
.project-card {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.25rem; cursor: pointer; transition: all 0.2s; position: relative;
}
.project-card:hover { border-color: var(--text-dim); transform: translateY(-1px); }
.project-card h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.3rem; }
.project-card p { color: var(--text-muted); font-size: 0.8rem; line-height: 1.5; }
.card-meta { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.75rem; }
.card-badge { font-size: 0.7rem; padding: 0.15rem 0.5rem; border-radius: 99px; font-weight: 500; }
.badge-active { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-archived { background: rgba(107, 114, 128, 0.2); color: var(--text-muted); }
.card-file-count { font-size: 0.75rem; color: var(--text-muted); }

/* Card task badges */
.card-tasks { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }
.badge-overdue { font-size: 0.7rem; padding: 0.1rem 0.45rem; border-radius: 99px; background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-progress { font-size: 0.7rem; padding: 0.1rem 0.45rem; border-radius: 99px; background: rgba(99,102,241,0.15); color: var(--accent); }
.badge-todo { font-size: 0.7rem; padding: 0.1rem 0.45rem; border-radius: 99px; background: rgba(156,163,175,0.15); color: var(--text-muted); }

/* Card links */
.card-links { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.card-link {
  font-size: 0.75rem; color: var(--accent); text-decoration: none;
  padding: 0.15rem 0.5rem; border: 1px solid var(--border); border-radius: 99px;
  transition: all 0.15s;
}
.card-link:hover { border-color: var(--accent); background: rgba(99, 102, 241, 0.1); }

/* Project List (row view) */
.project-list { display: flex; flex-direction: column; gap: 0.35rem; }
.project-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.85rem 1rem; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: all 0.15s;
}
.project-row:hover { border-color: var(--text-dim); background: var(--bg-hover); }
.row-main { flex: 1; min-width: 0; }
.row-main h3 { font-size: 0.9rem; font-weight: 600; }
.row-main p { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.row-links { display: flex; gap: 0.35rem; }

/* File List */
.file-list-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.file-list-header h3 { font-size: 1rem; font-weight: 600; }
.file-list-actions { display: flex; gap: 0.5rem; align-items: center; }
.file-list { display: flex; flex-direction: column; gap: 0.25rem; }
.file-item {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.85rem;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: all 0.15s; font-size: 0.85rem;
}
.file-item:hover { border-color: var(--text-dim); background: var(--bg-hover); }
.file-item svg { color: var(--text-dim); flex-shrink: 0; }
.file-item-name { font-weight: 500; }
.file-item-path { color: var(--text-muted); font-size: 0.75rem; margin-left: auto; }

/* File Tree */
.file-tree details { margin-bottom: 0.15rem; }
.file-tree .tree-children { margin-left: 1.25rem; }
.file-tree summary {
  cursor: pointer; padding: 0.4rem 0.6rem; font-size: 0.85rem; font-weight: 500;
  color: var(--text-muted); list-style: none; display: flex; align-items: center; gap: 0.5rem;
  border-radius: var(--radius); transition: all 0.15s;
}
.file-tree summary::-webkit-details-marker { display: none; }
.file-tree summary:hover { color: var(--text); background: var(--bg-hover); }
.file-tree summary svg { flex-shrink: 0; }
.tree-file-count { font-size: 0.7rem; color: var(--text-dim); margin-left: auto; }
.tree-file { margin-left: 0; border: none; background: none; padding: 0.35rem 0.6rem; }
.tree-file:hover { background: var(--bg-hover); }

/* File Viewer */
.file-header-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.file-actions { display: flex; gap: 0.5rem; }

.markdown-body {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 2rem; line-height: 1.75; font-size: 0.9rem;
}
.markdown-body h1 { font-size: 1.6rem; font-weight: 700; margin: 0 0 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.markdown-body h2 { font-size: 1.25rem; font-weight: 600; margin: 1.5rem 0 0.75rem; }
.markdown-body h3 { font-size: 1.05rem; font-weight: 600; margin: 1.25rem 0 0.5rem; }
.markdown-body p { margin-bottom: 0.75rem; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.markdown-body li { margin-bottom: 0.25rem; }
.markdown-body code {
  background: var(--bg); padding: 0.15rem 0.4rem; border-radius: 4px;
  font-size: 0.85em; font-family: 'Consolas', 'Monaco', monospace;
}
.markdown-body pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; overflow-x: auto; margin-bottom: 1rem;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body blockquote { border-left: 3px solid var(--accent); padding-left: 1rem; color: var(--text-muted); margin-bottom: 0.75rem; }
.markdown-body table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; text-align: left; }
.markdown-body th { background: var(--bg); font-weight: 600; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* Editor */
.file-editor {
  width: 100%; min-height: 500px; padding: 1.25rem; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text);
  font-family: 'Consolas', 'Monaco', monospace; font-size: 0.85rem; line-height: 1.7;
  resize: vertical; outline: none; tab-size: 2;
}
.file-editor:focus { border-color: var(--border-focus); }
.settings-editor { min-height: 600px; }
.settings-actions { margin-top: 1rem; display: flex; align-items: center; gap: 1rem; }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.75rem; width: 400px;
}
.modal-wide { width: 480px; }
.modal h3 { margin-bottom: 1rem; font-size: 1.05rem; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 0.6rem 0.85rem; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.9rem; outline: none; margin-bottom: 1rem;
  font-family: inherit;
}
.modal input:focus, .modal select:focus, .modal textarea:focus { border-color: var(--border-focus); }
.modal textarea { resize: vertical; min-height: 60px; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.modal-field { margin-bottom: 0.75rem; }
.modal-field label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.modal-field input, .modal-field select, .modal-field textarea { margin-bottom: 0; }
.modal-row { display: flex; gap: 0.75rem; }

/* Template picker */
.template-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; margin-bottom: 1rem; }
.template-option {
  padding: 0.85rem; border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; text-align: center; font-size: 0.8rem; color: var(--text-muted);
  transition: all 0.15s;
}
.template-option:hover { border-color: var(--accent); color: var(--text); background: rgba(99,102,241,0.05); }
.template-icon { margin-bottom: 0.35rem; }
.template-icon svg { color: var(--text-dim); }

/* Task List (project view) */
.project-tasks-section { margin-top: 2rem; }
.task-list { display: flex; flex-direction: column; gap: 0.25rem; }
.task-item {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0.85rem;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
  text-decoration: none; color: var(--text); font-size: 0.85rem; transition: all 0.15s;
}
.task-item:hover { border-color: var(--text-dim); background: var(--bg-hover); }
.task-item.task-overdue { border-left: 3px solid var(--danger); }
.task-priority {
  font-size: 0.65rem; font-weight: 600; padding: 0.1rem 0.4rem; border-radius: 4px;
  flex-shrink: 0; text-transform: uppercase; letter-spacing: 0.03em;
}
.task-priority-0 { background: rgba(239,68,68,0.15); color: var(--danger); }
.task-priority-1 { background: rgba(245,158,11,0.15); color: var(--warning); }
.task-priority-2 { background: rgba(99,102,241,0.15); color: var(--accent); }
.task-priority-3 { background: rgba(156,163,175,0.15); color: var(--text-muted); }
.task-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-status {
  font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: 99px; flex-shrink: 0;
}
.task-status-todo { background: rgba(156,163,175,0.15); color: var(--text-muted); }
.task-status-in_progress { background: rgba(99,102,241,0.15); color: var(--accent); }
.task-status-done { background: rgba(16,185,129,0.15); color: var(--success); }
.task-due { font-size: 0.75rem; color: var(--text-muted); flex-shrink: 0; }
.task-subtasks { display: flex; align-items: center; gap: 0.35rem; font-size: 0.7rem; color: var(--text-dim); flex-shrink: 0; }
.subtask-bar { width: 40px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.subtask-fill { display: block; height: 100%; background: var(--success); border-radius: 2px; }

/* Toast */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1.25rem;
  font-size: 0.85rem; z-index: 300; animation: toast-in 0.2s ease; transition: opacity 0.2s;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); z-index: 50; }
  .sidebar.mobile-open { transform: translateX(0); }
  main { margin-left: 0; padding: 1rem; }
  .project-grid { grid-template-columns: 1fr !important; }
  .project-row { flex-direction: column; align-items: flex-start; }
  .row-meta { margin-top: 0.5rem; }
  .modal { width: calc(100% - 2rem); }
  .modal-wide { width: calc(100% - 2rem); }
  .modal-row { flex-direction: column; gap: 0; }
}
