/* === CSS Variables / Theme === */
:root {
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --transition: 0.2s ease;
}

body.light {
  --bg: #fafafa;
  --bg-card: #fff;
  --bg-hover: #f5f5f5;
  --bg-input: #fff;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-hint: #999;
  --border: #e5e5e5;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --cat-bg: #f0f4ff;
  --cat-text: #2563eb;
  --overlay: rgba(0,0,0,0.3);
}

body.dark {
  --bg: #111111;
  --bg-card: #1e1e1e;
  --bg-hover: #2a2a2a;
  --bg-input: #252525;
  --text: #e5e5e5;
  --text-secondary: #999;
  --text-hint: #666;
  --border: #333;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --danger: #ef4444;
  --success: #22c55e;
  --cat-bg: #1a2740;
  --cat-text: #60a5fa;
  --overlay: rgba(0,0,0,0.6);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}

/* === Topbar === */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 18px; font-weight: 700; }
.sync-badge { font-size: 14px; cursor: pointer; opacity: 0.6; }
.sync-badge:hover { opacity: 1; }
.topbar-center { flex: 1; display: flex; justify-content: center; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* === View Switcher === */
.view-switcher { display: flex; gap: 4px; background: var(--bg); border-radius: var(--radius); padding: 3px; }
.view-btn {
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
}
.view-btn.active { background: var(--bg-card); color: var(--text); box-shadow: var(--shadow); }
.view-btn:hover:not(.active) { color: var(--text); }

/* === Buttons === */
.primary-btn {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition);
}
.primary-btn:hover { background: var(--accent-hover); }

.secondary-btn {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
}
.secondary-btn:hover { background: var(--bg-hover); }

.danger-btn {
  padding: 8px 18px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
}
.danger-btn:hover { background: var(--danger); color: #fff; }

.icon-btn {
  width: 36px; height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.hidden { display: none !important; }

/* === Main View === */
.main-view { max-width: 900px; margin: 0 auto; padding: 24px 20px; }
.view { display: none; }
.view.active { display: block; }

/* === Timeline === */
.timeline-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 20px;
}
.zoom-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.zoom-btn:hover { background: var(--bg-hover); }
.zoom-label { font-size: 13px; color: var(--text-hint); }

.timeline-group { margin-bottom: 28px; }
.timeline-group-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.timeline-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all var(--transition);
}
.timeline-item:hover { background: var(--bg-hover); transform: translateY(-1px); box-shadow: var(--shadow); }
.timeline-item-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 4px;
  font-size: 12px;
}
.timeline-item-date { color: var(--text-hint); }
.timeline-item-cat {
  background: var(--cat-bg);
  color: var(--cat-text);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
}
.timeline-item-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.timeline-item-body { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

/* === Calendar === */
.calendar-nav { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 20px; }
.cal-month { font-size: 16px; font-weight: 600; min-width: 140px; text-align: center; }
.cal-header-row, .cal-row { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-header-cell {
  text-align: center;
  font-size: 12px;
  color: var(--text-hint);
  padding: 8px 0;
}
.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  transition: background var(--transition);
  position: relative;
}
.cal-cell:hover { background: var(--bg-hover); }
.cal-cell.empty { cursor: default; }
.cal-cell.today { font-weight: 700; color: var(--accent); }
.cal-cell.has-events { font-weight: 600; }
.cal-dot { color: var(--accent); font-size: 20px; line-height: 0; }
.calendar-events { margin-top: 20px; }

/* === Search === */
.search-bar { display: flex; gap: 8px; margin-bottom: 20px; }
.search-bar input { flex: 1; }
.search-bar select { width: 140px; }
input, select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
mark { background: #fde68a; color: #1a1a1a; padding: 0 2px; border-radius: 2px; }

/* === Panel === */
.panel {
  position: fixed;
  top: 0; right: -420px;
  width: 420px; max-width: 100vw;
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 200;
  transition: right 0.3s ease;
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.panel.open { right: 0; }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.panel-header h2 { font-size: 16px; }
.panel-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.panel-body label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.panel-body label small { font-weight: 400; color: var(--text-hint); }

.category-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition);
}
.cat-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.cat-btn:hover:not(.active) { border-color: var(--accent); }

.ai-actions { display: flex; flex-direction: column; gap: 8px; }
.raw-toggle { font-size: 13px; }
.raw-toggle label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.panel-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: auto; padding-top: 16px; }

/* === Analysis === */
.analysis-range { display: flex; align-items: center; gap: 8px; }
.analysis-range label { font-size: 13px; color: var(--text-secondary); }
.analysis-range input { width: 140px; }
.analysis-result { margin-top: 16px; }
.analysis-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
}
.analysis-card-meta { font-size: 12px; color: var(--text-hint); margin-bottom: 8px; }
.analysis-card-content { font-size: 14px; line-height: 1.7; color: var(--text); }
.analysis-history { margin-top: 16px; }
.analysis-history h3 { font-size: 14px; color: var(--text-secondary); margin-bottom: 8px; }

/* === Modal === */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 150;
  transition: opacity var(--transition);
}
.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 250;
  width: 400px; max-width: 90vw;
}
.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-content h2 { font-size: 18px; }
.modal-desc { font-size: 14px; color: var(--text-secondary); }
.key-display { display: flex; gap: 8px; }
.key-display input { flex: 1; }
.hint { font-size: 13px; color: var(--text-hint); }

/* === Empty State === */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-hint); }
.empty-state p { margin-bottom: 8px; }
.loading { text-align: center; padding: 20px; color: var(--text-hint); }
.error { color: var(--danger); font-size: 14px; }

/* === Responsive === */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  .topbar-center { order: 3; width: 100%; justify-content: center; margin-top: 8px; }
  .panel { width: 100vw; right: -100vw; }
  .modal { width: 95vw; }
  .main-view { padding: 16px 12px; }
  .view-switcher { width: 100%; justify-content: center; }
  .view-btn { flex: 1; text-align: center; padding: 6px 8px; font-size: 13px; }
}