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

:root {
  --bg: #f8f9fb;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --primary: #6366f1;
  --primary-light: #eef2ff;
  --primary-dark: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --sidebar-w: 220px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  min-height: 100vh;
}

/* ====== sidebar ====== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.25s ease;
}

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

.sidebar-brand h1 {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}

.sidebar-brand span {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-nav {
  padding: 12px;
  flex-shrink: 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: all 0.15s;
}

.sidebar-nav a:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.sidebar-nav a.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-nav a .nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.sidebar-section {
  padding: 0 12px;
  margin-top: 8px;
}

.sidebar-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
  padding: 8px 12px 6px;
  font-weight: 500;
}

.sidebar-section a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 1px;
  transition: all 0.15s;
}

.sidebar-section a:hover {
  background: #f3f4f6;
  color: var(--text);
}

.sidebar-section a .s-icon {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}

.si-purple { background: #eef2ff; color: #6366f1; }
.si-teal { background: #d1fae5; color: #10b981; }
.si-amber { background: #fef3c7; color: #f59e0b; }
.si-coral { background: #ffe4e6; color: #ef4444; }
.si-blue { background: #dbeafe; color: #3b82f6; }
.si-pink { background: #fce7f3; color: #ec4899; }
.si-gray { background: #f3f4f6; color: #6b7280; }

/* ====== sidebar tree ====== */
.nav-tree { margin-bottom: 2px; }
.tree-toggle { display: flex; align-items: center; }
.nav-arrow {
  font-size: 10px; color: var(--text-light); margin-right: 6px;
  transition: transform 0.2s; transform: rotate(0deg);
  flex-shrink: 0;
}
.nav-arrow.down { transform: rotate(90deg); color: var(--primary); }
.tree-content { display: none; padding: 6px 0 4px 12px; }
.nav-tree.open .tree-content { display: block; }

.tree-group-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-light);
  padding: 10px 12px 4px;
  font-weight: 600;
}

.sub-link {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 1px;
  transition: all 0.15s;
}

.sub-link:hover {
  background: #f3f4f6;
  color: var(--text);
}

.sub-link .s-icon {
  width: 18px;
  height: 18px;
  font-size: 10px;
}

/* ====== main content ====== */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  padding: 24px 28px 100px;
}

/* ====== menu toggle (mobile) ====== */
.menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 300;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 199;
}

/* ---- page title ---- */
.page-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ---- date row ---- */
.date-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.date-row input[type="date"] {
  flex: 1;
  max-width: 200px;
}

.date-row span {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---- cards ---- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-weight: 600;
  font-size: 15px;
}

.card-header .icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.icon-purple { background: #eef2ff; color: #6366f1; }
.icon-teal { background: #d1fae5; color: #10b981; }
.icon-amber { background: #fef3c7; color: #f59e0b; }
.icon-coral { background: #ffe4e6; color: #ef4444; }
.icon-blue { background: #dbeafe; color: #3b82f6; }
.icon-pink { background: #fce7f3; color: #ec4899; }
.icon-gray { background: #f3f4f6; color: #6b7280; }

/* ---- form elements ---- */
label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

input[type="text"],
input[type="time"],
input[type="number"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: #fff;
}

textarea {
  resize: vertical;
  min-height: 60px;
}

.form-row {
  display: flex;
  gap: 10px;
}

.form-row > * { flex: 1; }

/* ---- mood selector ---- */
.mood-selector {
  display: flex;
  gap: 8px;
}

.mood-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: #fff;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mood-btn:hover { border-color: var(--primary); }
.mood-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: scale(1.08);
}

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  background: #fff;
  color: var(--text);
  font-weight: 500;
  transition: all 0.15s;
}

.btn:hover { border-color: var(--primary); color: var(--primary); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn-sm { padding: 5px 12px; font-size: 12px; }

.btn-block {
  display: block;
  width: 100%;
  padding: 12px;
  font-size: 15px;
  border-radius: 8px;
}

/* ---- todo list ---- */
.todo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}

.todo-item:last-child { border-bottom: none; }

.todo-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.todo-item .todo-content {
  flex: 1;
  border: none;
  background: transparent;
  padding: 5px 0;
  font-size: 14px;
}

.todo-item.done .todo-content {
  text-decoration: line-through;
  color: var(--text-light);
}

.todo-item .todo-del {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 18px;
  padding: 0 4px;
  visibility: hidden;
  line-height: 1;
}

.todo-item:hover .todo-del { visibility: visible; }
.todo-item .todo-del:hover { color: var(--danger); }

/* ---- finance list ---- */
.finance-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.finance-item:last-child { border-bottom: none; }

.finance-item .cat-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: #f3f4f6;
  color: #6b7280;
  white-space: nowrap;
}

.finance-item .amount {
  font-weight: 600;
  margin-left: auto;
  white-space: nowrap;
}

.finance-item .amount.expense { color: var(--danger); }

/* ---- budget bar ---- */
.budget-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.budget-bar input {
  width: 130px;
  flex-shrink: 0;
}

.budget-bar .progress {
  flex: 1;
  height: 8px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
}

.budget-bar .progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--primary);
  transition: width 0.3s;
}

/* ---- news / reading items ---- */
.news-item, .reading-item {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.news-item:last-child, .reading-item:last-child { border-bottom: none; }

.news-item .news-title { font-weight: 500; margin-bottom: 2px; }
.news-item .news-summary { font-size: 12px; color: var(--text-muted); }

.news-rank {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; border-radius: 6px;
  font-size: 11px; font-weight: 600; flex-shrink: 0; padding: 0 4px;
}
.news-rank.top-1 { background: #ef4444; color: #fff; }
.news-rank.top-2 { background: #f97316; color: #fff; }
.news-rank.top-3 { background: #eab308; color: #fff; }
.news-rank.top { background: var(--primary-light); color: var(--primary); }
.news-link { display: block; text-decoration: none; color: var(--text); padding: 3px 6px; border-radius: 6px; }
.news-link:hover { background: var(--bg); }

.reading-item .book-title { font-weight: 500; }
.reading-item .book-meta { font-size: 12px; color: var(--text-muted); }
.reading-item .book-notes { font-size: 13px; margin-top: 4px; color: var(--text-muted); }

/* ---- save bar ---- */
.save-bar {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-w);
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 14px 28px;
  z-index: 100;
  display: flex;
  gap: 12px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
}

.save-bar .btn { flex: 1; }

/* ---- stats ---- */
.chart-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.chart-box h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 20px;
}

/* ---- heatmap ---- */
.heatmap { overflow-x: auto; padding: 4px 0; }
.heatmap-table { border-collapse: separate; border-spacing: 3px; }
.heatmap-table td { width: 12px; height: 12px; border-radius: 2px; background: #e5e7eb; }
.heatmap-table td.filled { background: var(--primary); }
.heatmap-table th {
  font-size: 10px;
  color: var(--text-light);
  text-align: left;
  padding-right: 8px;
  font-weight: 400;
}

/* ---- history ---- */
.history-date {
  display: block;
  padding: 12px 18px;
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-bottom: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: all 0.15s;
}

.history-date:hover {
  border-color: var(--primary);
  transform: translateX(4px);
}

/* ---- toast ---- */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: #fff;
  padding: 12px 28px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

.toast.show { opacity: 1; }

/* ====== accordion ====== */
.card.accordion { cursor: pointer; }
.card.accordion .card-header { margin-bottom: 0; }
.card.accordion .card-body { display: none; }
.card.accordion.open .card-body { display: block; }
.card.accordion .card-header::after {
  content: '+'; font-size: 16px; margin-left: auto; color: var(--text-light);
  transition: transform 0.2s; font-weight: 400;
}
.card.accordion.open .card-header::after {
  content: '\2212'; color: var(--primary);
}
.card.accordion .card-badge {
  font-size: 10px; background: var(--primary-light); color: var(--primary);
  padding: 1px 8px; border-radius: 10px; margin-left: 6px; font-weight: 500;
}

/* ====== responsive ====== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); }

  .menu-toggle { display: flex; }

  .sidebar-overlay.show { display: block; }

  .main-wrap { margin-left: 0; }

  .main-content { padding: 20px 16px 100px; }

  .save-bar { left: 0; padding: 14px 16px; }

  .form-row { flex-direction: column; gap: 8px; }

  .mood-btn { width: 40px; height: 40px; font-size: 18px; }

  .card { padding: 16px; }

  .chart-box { padding: 16px; }
}
