:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3248;
  --accent: #7c6af7;
  --accent-dim: #5a4fcf;
  --text: #e8eaf0;
  --text-dim: #8b90a8;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;
  --radius: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* Layout */
#app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
  text-decoration: none;
}

nav {
  display: flex;
  gap: 2px;
  margin-left: 8px;
}

nav button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

nav button:hover { background: var(--surface2); color: var(--text); }
nav button.active { background: var(--surface2); color: var(--accent); }

.header-search {
  margin-left: auto;
  position: relative;
  width: 280px;
}

.header-search input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 36px 7px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.header-search input:focus { border-color: var(--accent); }
.header-search input::placeholder { color: var(--text-dim); }

.header-search .search-icon {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 14px;
  pointer-events: none;
}

main { flex: 1; max-width: 820px; margin: 0 auto; width: 100%; padding: 24px 20px; }

/* Capture bar */
#capture-section { margin-bottom: 24px; }

.capture-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s;
}

.capture-wrap:focus-within { border-color: var(--accent); }

#capture-input {
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  resize: none;
  outline: none;
  min-height: 48px;
  line-height: 1.5;
  width: 100%;
  font-family: inherit;
}

#capture-input::placeholder { color: var(--text-dim); }

.capture-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.capture-hint { color: var(--text-dim); font-size: 12px; }

#capture-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

#capture-btn:hover { background: var(--accent-dim); }
#capture-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Search result panel */
#search-panel {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
  display: none;
}

#search-panel.visible { display: block; }
.search-answer { color: var(--text); line-height: 1.6; margin-bottom: 12px; }
.search-refs { display: flex; flex-direction: column; gap: 6px; }
.search-ref-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }

#search-panel .close-btn {
  float: right;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 0 8px 8px;
}

/* View title */
.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.view-title { font-size: 16px; font-weight: 600; }

.filter-btns { display: flex; gap: 4px; margin-left: auto; }

.filter-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active { border-color: var(--accent); color: var(--accent); background: var(--surface2); }

/* Entry cards */
.entries-list { display: flex; flex-direction: column; gap: 8px; }

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: border-color 0.15s;
}

.entry-card:hover { border-color: var(--accent); }
.entry-card.done { opacity: 0.5; }
.entry-card.done .entry-title { text-decoration: line-through; }

.entry-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 1px;
}

.icon-task { background: rgba(124, 106, 247, 0.15); color: var(--accent); }
.icon-note { background: rgba(251, 191, 36, 0.15); color: var(--amber); }
.icon-bookmark { background: rgba(96, 165, 250, 0.15); color: var(--blue); }
.icon-event { background: rgba(74, 222, 128, 0.15); color: var(--green); }

.entry-body { flex: 1; min-width: 0; }

.entry-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.entry-url {
  color: var(--blue);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
  display: inline-block;
}

.entry-url:hover { text-decoration: underline; }

.tag {
  background: var(--surface2);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.due-badge {
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 500;
}

.due-overdue { background: rgba(248, 113, 113, 0.15); color: var(--red); }
.due-today { background: rgba(251, 191, 36, 0.15); color: var(--amber); }
.due-soon { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.due-future { background: var(--surface2); color: var(--text-dim); }

.entry-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.entry-card:hover .entry-actions { opacity: 1; }

.action-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}

.action-btn:hover { background: var(--surface2); color: var(--text); }
.action-btn.done-btn:hover { color: var(--green); }
.action-btn.delete-btn:hover { color: var(--red); }

/* Calendar */
#calendar-view { display: none; }
#calendar-view.active { display: block; }

.cal-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.cal-nav button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
}

.cal-nav button:hover { border-color: var(--accent); }
.cal-month-label { font-size: 15px; font-weight: 600; flex: 1; text-align: center; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day-header {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cal-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 80px;
  padding: 6px;
  position: relative;
  vertical-align: top;
}

.cal-cell.empty { background: transparent; border-color: transparent; }
.cal-cell.today { border-color: var(--accent); }

.cal-date {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-weight: 500;
}

.cal-cell.today .cal-date { color: var(--accent); font-weight: 700; }

.cal-entry {
  font-size: 11px;
  border-radius: 4px;
  padding: 2px 5px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
}

.cal-entry.task { background: rgba(124, 106, 247, 0.2); color: var(--accent); }
.cal-entry.event { background: rgba(74, 222, 128, 0.2); color: var(--green); }
.cal-entry.note { background: rgba(251, 191, 36, 0.15); color: var(--amber); }
.cal-entry.bookmark { background: rgba(96, 165, 250, 0.15); color: var(--blue); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
}

.empty-icon { font-size: 32px; margin-bottom: 12px; }
.empty-text { font-size: 14px; }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  transition: transform 0.25s ease;
  z-index: 100;
  pointer-events: none;
  white-space: nowrap;
}

#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--red); color: var(--red); }
#toast.success { border-color: var(--green); color: var(--green); }
