:root {
  --primary: #4a90d9;
  --primary-light: #6ba3e0;
  --primary-dark: #3570b0;
  --positive: #34c759;
  --positive-bg: #e8f5e9;
  --negative: #ff3b30;
  --negative-bg: #fce4ec;
  --warning: #ff9500;
  --warning-bg: #fff3e0;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #aeaeb2;
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --bg-card-hover: #fafafa;
  --border: #e5e5ea;
  --border-light: #f0f0f5;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-hover: 0 2px 8px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --header-h: 56px;
  --nav-w: 220px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "Fira Code", Consolas, monospace;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --primary: #5a9fef;
  --primary-light: #7ab4f3;
  --primary-dark: #4a8bcf;
  --positive: #4cd964;
  --positive-bg: #1a3a1a;
  --negative: #ff453a;
  --negative-bg: #3a1a1a;
  --warning: #ff9f0a;
  --warning-bg: #3a2a0a;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --text-tertiary: #636366;
  --bg: #1c1c1e;
  --bg-card: #2c2c2e;
  --bg-card-hover: #333336;
  --border: #38383a;
  --border-light: #2c2c2e;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-hover: 0 2px 8px rgba(0,0,0,0.4);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; font-size: inherit; color: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
input:focus, textarea:focus, select:focus { outline: none; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-tertiary); border-radius: 3px; }

.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-score {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--primary);
}

.theme-toggle, .menu-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background var(--transition);
}
.theme-toggle:hover, .menu-toggle:hover { background: var(--border-light); }

.menu-toggle { display: none; }

/* Sidebar Navigation */
.app-nav {
  width: var(--nav-w);
  height: 100vh;
  padding-top: var(--header-h);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  transition: transform var(--transition);
}

.nav-section { padding: 8px 0; }
.nav-section + .nav-section { border-top: 1px solid var(--border-light); }
.nav-section-title {
  padding: 6px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  font-size: 14px;
  color: var(--text-secondary);
  border-radius: 0;
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
}
.nav-item:hover { background: var(--border-light); color: var(--text); }
.nav-item.active {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  font-weight: 500;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}
.nav-item .nav-icon { width: 20px; text-align: center; font-size: 16px; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* Main Content */
.app-main {
  flex: 1;
  padding-top: var(--header-h);
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(var(--header-h) + 20px) 24px 24px;
  min-height: 100vh;
}

.page { display: none; max-width: 960px; margin: 0 auto; }
.page.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 8px;
}
.page-title { font-size: 22px; font-weight: 700; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-hover); }
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.card-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}
.card-label {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-positive { background: var(--positive); color: white; }
.btn-positive:hover { filter: brightness(0.9); }
.btn-negative { background: var(--negative); color: white; }
.btn-negative:hover { filter: brightness(0.9); }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { filter: brightness(0.9); }
.btn-ghost { background: var(--border-light); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-ghost2 { color: var(--text-secondary); }
.btn-ghost2:hover { background: var(--border-light); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); }
.btn-danger { background: var(--negative); color: white; }
.btn-danger:hover { filter: brightness(0.85); }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent);
}
.form-textarea { resize: vertical; min-height: 60px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-title { font-size: 17px; font-weight: 600; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* List items */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.list-item:hover { background: var(--border-light); }
.list-item + .list-item { border-top: 1px solid var(--border-light); }
.list-item-info { flex: 1; min-width: 0; }
.list-item-title { font-size: 14px; font-weight: 500; }
.list-item-sub { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.list-item-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Color tag */
.color-tag {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.color-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.color-opt {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition);
}
.color-opt:hover { transform: scale(1.15); }
.color-opt.selected { border-color: var(--text); transform: scale(1.15); }

/* Date picker */
.date-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.date-nav button { padding: 4px 10px; }
.date-display { font-size: 15px; font-weight: 500; min-width: 120px; text-align: center; }

/* Progress bar */
.progress-bar {
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--primary);
  transition: width 0.3s ease;
}
.progress-fill.positive { background: var(--positive); }
.progress-fill.negative { background: var(--negative); }
.progress-fill.warning { background: var(--warning); }

/* Timer */
.timer-display {
  font-size: 56px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 20px 0;
  font-family: var(--mono);
}
.timer-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 16px 0;
}
.timer-setup { display: flex; gap: 8px; align-items: center; justify-content: center; margin-bottom: 16px; }
.timer-setup .form-input { width: 70px; text-align: center; }

/* Chip / Tag */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  background: var(--border-light);
}
.chip.positive { background: var(--positive-bg); color: var(--positive); }
.chip.negative { background: var(--negative-bg); color: var(--negative); }

/* Random picker */
.picker-wheel {
  text-align: center;
  padding: 40px;
  font-size: 32px;
  font-weight: 600;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 14px; }

/* Search */
.search-bar {
  position: relative;
  margin-bottom: 12px;
}
.search-bar input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  transition: border-color var(--transition);
}
.search-bar input:focus { border-color: var(--primary); }
.search-bar .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
}

/* Checkbox */
.checkbox {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.checkbox.checked { background: var(--positive); border-color: var(--positive); }
.checkbox.checked::after { content: '✓'; color: white; font-size: 12px; font-weight: 700; }

/* Habit grid */
.habit-card {
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  margin-bottom: 8px;
}
.habit-header { display: flex; align-items: center; gap: 10px; }
.habit-name { font-weight: 500; flex: 1; }
.habit-stats { font-size: 12px; color: var(--text-tertiary); display: flex; gap: 12px; margin-top: 6px; }

/* Wish item */
.wish-item {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  margin-bottom: 10px;
}
.wish-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.wish-name { font-weight: 600; flex: 1; font-size: 15px; }
.wish-score { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.wish-actions { display: flex; gap: 6px; margin-top: 8px; }

/* Responsive */
@media (max-width: 768px) {
  .app-nav {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 150;
    transform: translateX(-100%);
    box-shadow: var(--shadow-hover);
    width: 260px;
  }
  .app-nav.open { transform: translateX(0); }
  .menu-toggle { display: flex; }
  .nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 140;
    display: none;
  }
  .nav-overlay.open { display: block; }
  .app-main { padding: calc(var(--header-h) + 16px) 16px 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .form-row { grid-template-columns: 1fr; }
  .card-value { font-size: 22px; }
  .timer-display { font-size: 40px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .page-title { font-size: 18px; }
}
/* Record list for diet */
.record-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.record-item:hover { background: var(--border-light); }
.record-label { font-size: 13px; font-weight: 500; min-width: 48px; }
.record-detail { flex: 1; font-size: 14px; }
.record-extra { font-size: 12px; color: var(--text-tertiary); }
.record-actions { display: flex; gap: 4px; }
/* Draggable task list */
.task-list { min-height: 60px; }
.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: grab;
  background: var(--bg-card);
  margin-bottom: 4px;
  border: 1px solid var(--border-light);
}
.task-item:active { cursor: grabbing; }
.task-item.dragging { opacity: 0.5; }
.task-item.drag-over { border-top: 2px solid var(--primary); }
.task-done { opacity: 0.6; }
.task-done .task-title { text-decoration: line-through; }
.task-title { flex: 1; font-size: 14px; }
.task-meta { font-size: 12px; color: var(--text-tertiary); display: flex; gap: 8px; }
/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: center;
}
/* Import/Export buttons area */
.data-tools {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.wish-progress { margin: 8px 0 4px; }
.wish-progress .progress-fill.bg-positive { background: var(--positive); }
.wish-progress .progress-fill.bg-warning { background: var(--warning); }
/* Goal card */
.goal-card {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  margin-bottom: 8px;
}
.goal-status { font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.goal-status.active { background: var(--positive-bg); color: var(--positive); }
.goal-status.done { background: var(--border-light); color: var(--text-tertiary); }
/* Inspiration card */
.inspo-card {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  margin-bottom: 8px;
}
.inspo-date { font-size: 11px; color: var(--text-tertiary); }
.inspo-body { font-size: 14px; margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
/* Group list for random picker */
.group-card {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  margin-bottom: 10px;
}
.group-items { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.group-item-tag {
  padding: 2px 10px;
  border-radius: 12px;
  background: var(--border-light);
  font-size: 13px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }
.score-display { display: inline-flex; align-items: center; gap: 4px; }
.score-positive { color: var(--positive); }
.score-negative { color: var(--negative); }
.score-neutral { color: var(--text-secondary); }
/* Tab content panels */
.tab-content { display: none; }
.tab-content.active { display: block; }
.section-spacer { height: 24px; }
.inline-flex { display: inline-flex; align-items: center; gap: 6px; }
.text-muted { color: var(--text-tertiary); }
.text-sm { font-size: 13px; }
.mt-8 { margin-top: 8px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.w-full { width: 100%; }
