/* ===== CSS Custom Properties ===== */
:root {
  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-hover: #f1f3f5;
  --bg-active: #e8ecef;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --text: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #a0aec0;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: #eff6ff;
  --success: #22c55e;
  --success-light: #f0fdf4;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --sidebar-width: 240px;
  --transition: 150ms ease;
}

[data-theme='dark'] {
  --bg: #121212;
  --bg-secondary: #1e1e1e;
  --bg-hover: #2d2d2d;
  --bg-active: #3d3d3d;
  --border: #333333;
  --border-hover: #4d4d4d;
  --text: #ffffff;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-light: #1e3a8a;
  --success: #10b981;
  --success-light: #064e3b;
  --warning: #f59e0b;
  --warning-light: #78350f;
  --danger: #ef4444;
  --danger-light: #7f1d1d;
  --shadow: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.5);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

ul, ol {
  list-style: none;
}

img {
  max-width: 100%;
}

/* ===== Utility ===== */
.hidden { display: none !important; }

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-accent { color: var(--accent); }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: #16a34a;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

.btn-lg {
  padding: 10px 20px;
  font-size: 16px;
}

.btn-full {
  width: 100%;
  justify-content: center;
}

.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
}

/* ===== Forms ===== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group textarea,
.form-group select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  padding: 8px 12px;
  background: var(--danger-light);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

/* ===== Auth Screen ===== */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0f7ff 0%, #e8f4f8 100%);
  padding: 20px;
}

.auth-container {
  background: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.auth-logo h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.auth-logo p {
  font-size: 14px;
  color: var(--text-muted);
}

.auth-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}

.auth-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.auth-tab:hover:not(.active) {
  color: var(--text-secondary);
}

.auth-form {
  display: flex;
  flex-direction: column;
}

/* ===== Main App Layout ===== */
.main-app {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-size: 20px;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-toggle {
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-radius: 0;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all var(--transition);
  cursor: pointer;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-label {
  font-size: 14px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.username-display {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  padding: 0;
  background: var(--bg);
}

/* ===== Page Header ===== */
.page-header {
  padding: 24px 32px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.page-header p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.page-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.page-body {
  padding: 24px 32px;
}

/* ===== Cards ===== */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

/* ===== Dashboard ===== */
.dashboard-greeting {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.dashboard-date {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}

.score-card {
  text-align: center;
}

.score-ring-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.score-ring {
  position: relative;
  width: 120px;
  height: 120px;
}

.score-ring svg {
  transform: rotate(-90deg);
  width: 120px;
  height: 120px;
}

.score-ring circle {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.score-ring .ring-bg {
  stroke: var(--border);
}

.score-ring .ring-fill {
  stroke: var(--accent);
  transition: stroke-dashoffset 0.6s ease;
}

.score-number {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-number span:first-child {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.score-number span:last-child {
  font-size: 12px;
  color: var(--text-muted);
}

.score-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.score-sublabel {
  font-size: 13px;
  color: var(--text-muted);
}

.score-stats {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 12px;
}

.score-stat {
  text-align: center;
}

.score-stat .stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.score-stat .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Habit Checklist */
.habit-checklist {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.habit-check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid transparent;
}

.habit-check-item:hover {
  background: var(--bg-hover);
}

.habit-check-item.completed {
  opacity: 0.7;
}

.habit-checkbox {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  font-size: 12px;
}

.habit-check-item.completed .habit-checkbox {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.habit-check-info {
  flex: 1;
  min-width: 0;
}

.habit-check-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.habit-check-item.completed .habit-check-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

.habit-check-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.habit-icon {
  font-size: 14px;
}

.habit-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.section-divider {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 8px 12px 4px;
}

/* ===== Habits Page ===== */
.habits-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.habit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: all var(--transition);
}

.habit-row:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.habit-row-color {
  width: 4px;
  height: 36px;
  border-radius: 2px;
  flex-shrink: 0;
}

.habit-row-icon {
  font-size: 18px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.habit-row-info {
  flex: 1;
  min-width: 0;
}

.habit-row-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.habit-row-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
}

.badge-required {
  background: #fef3c7;
  color: #92400e;
}

.badge-optional {
  background: var(--bg-secondary);
  color: var(--text-muted);
}

.badge-category {
  background: var(--accent-light);
  color: var(--accent);
}

.habit-row-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.habit-row:hover .habit-row-actions {
  opacity: 1;
}

/* Emoji Picker & Categories */
.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  padding: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.emoji-picker .emoji-btn {
  padding: 4px;
  font-size: 18px;
  border-radius: var(--radius-sm);
}

.category-group-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 12px 12px 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-group-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ===== Calendar View ===== */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.calendar-month-label {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.calendar-nav {
  display: flex;
  gap: 8px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  max-width: 800px;
  margin: 0 auto;
}

.calendar-day-name {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 6px 0;
}

.calendar-day {
  aspect-ratio: 1;
  max-width: 100px;
  margin: 0 auto;
  width: 100%;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  position: relative;
  min-height: 40px;
}

.calendar-day:hover {
  border-color: var(--border-hover);
  background: var(--bg-hover);
}

.calendar-day.today {
  border: 2px solid var(--accent);
}

.calendar-day.empty {
  cursor: default;
  pointer-events: none;
}

.calendar-day.future {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.calendar-day-num {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1;
}

.calendar-day.today .calendar-day-num {
  color: var(--accent);
  font-weight: 700;
}

.calendar-day-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-top: 3px;
}

/* Score color classes */
.score-100 { background: #16a34a; }
.score-80 { background: #65a30d; }
.score-60 { background: #d97706; }
.score-40 { background: #ea580c; }
.score-low { background: #dc2626; }
.score-none { background: var(--bg-active); }

.calendar-day.score-100-day { background: #f0fdf4; }
.calendar-day.score-80-day { background: #f7fee7; }
.calendar-day.score-60-day { background: #fffbeb; }
.calendar-day.score-40-day { background: #fff7ed; }
.calendar-day.score-low-day { background: #fef2f2; }

/* Calendar Detail Panel */
.calendar-detail {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.calendar-detail-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

/* ===== Schedule View ===== */
.schedule-day-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.day-tab {
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.day-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.day-tab:hover:not(.active) {
  background: var(--bg-hover);
}

.timeline {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.timeline-block {
  display: flex;
  align-items: stretch;
  gap: 12px;
  border-radius: var(--radius);
  padding: 10px 14px;
  border-left: 4px solid;
  background: var(--bg-secondary);
  transition: all var(--transition);
  cursor: pointer;
}

.timeline-block:hover {
  box-shadow: var(--shadow);
}

.timeline-block.is-optional {
  opacity: 0.7;
}

.timeline-time {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 90px;
  flex-shrink: 0;
}

.timeline-info {
  flex: 1;
}

.timeline-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.timeline-category {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.timeline-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.timeline-block:hover .timeline-actions {
  opacity: 1;
}

/* ===== Settings ===== */
.settings-section {
  margin-bottom: 32px;
}

.settings-section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.settings-section-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.settings-section hr {
  border: none;
  border-top: 1px solid var(--border);
  margin-bottom: 16px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.settings-row-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.settings-row-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.code-block {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  color: var(--text-secondary);
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: 8px;
}

.code-block span {
  flex: 1;
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.template-item-info h4 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.template-item-info p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.template-item-actions {
  display: flex;
  gap: 6px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  font-size: 22px;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.modal-body {
  padding: 20px 24px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ===== Toast Notifications ===== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  pointer-events: all;
  animation: slideInRight 0.2s ease;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.toast-success { background: #166534; }
.toast.toast-error { background: #991b1b; }
.toast.toast-warning { background: #92400e; }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ===== Loading ===== */
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13px;
  margin-bottom: 16px;
}

/* ===== Color Picker ===== */
.color-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-option {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition);
}

.color-option.selected,
.color-option:hover {
  border-color: var(--text);
  transform: scale(1.1);
}

/* ===== Checkbox toggle ===== */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
}

.toggle-input {
  width: 36px;
  height: 20px;
  appearance: none;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}

.toggle-input:checked {
  background: var(--accent);
}

.toggle-input::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-input:checked::after {
  transform: translateX(16px);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block !important;
  }

  .sidebar-overlay.hidden {
    display: none !important;
  }

  .main-content {
    margin-left: 0;
  }

  .page-header {
    padding: 16px 16px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }

  .page-header-left {
    flex: 1;
  }

  .mobile-menu-btn {
    display: flex;
    padding: 8px;
    border-radius: var(--radius);
    color: var(--text);
  }

  .mobile-menu-btn:hover {
    background: var(--bg-hover);
  }

  .page-body {
    padding: 16px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .calendar-day-num {
    font-size: 11px;
  }

  .calendar-day {
    min-height: 32px;
  }

  .habit-row-actions {
    opacity: 1;
  }

  .timeline-actions {
    opacity: 1;
  }

  .toast-container {
    bottom: 16px;
    right: 8px;
    left: 8px;
  }

  .toast {
    max-width: 100%;
  }
}

@media (min-width: 769px) {
  .mobile-menu-btn,
  .sidebar-toggle {
    display: none !important;
  }
}

/* ===== Scrollbar styling ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Animations ===== */
.fade-in {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Min-version tooltip ===== */
.min-version-note {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 7px;
  display: inline-block;
  margin-top: 3px;
}

/* ===== File upload area ===== */
.file-drop-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-muted);
}

.file-drop-area:hover,
.file-drop-area.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

.file-drop-area input[type="file"] {
  display: none;
}

/* ===== PHASE 2: STREAKS + ANALYTICS ===== */
.streak-row {
  display: flex;
  justify-content: space-around;
  gap: 8px;
  margin: 12px 0 8px;
  padding: 10px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
}
.streak-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.streak-icon { font-size: 18px; }
.streak-value { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1; }
.streak-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.mini-chart-wrapper { margin: 12px 0 0; }
.mini-chart-title { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.mini-chart-svg { width: 100%; height: 40px; }

.mood-energy-row {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  padding: 10px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
}
.mood-group { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.mood-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.rating-stars { display: flex; gap: 2px; }
.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: #d1d5db;
  padding: 0;
  line-height: 1;
  transition: color 0.15s, transform 0.1s;
}
.star-btn.active { color: #f59e0b; }
.star-btn:hover { color: #f59e0b; transform: scale(1.2); }

.low-energy-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  border-radius: 99px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 600;
  margin: 6px 0 0;
}
.low-energy-hint { color: #d97706 !important; }
.btn-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}
.btn-warning:hover { background: #fde68a; }

/* Weekly review modal */
.weekly-review { padding: 4px 0; }
.review-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.review-period { font-size: 13px; color: var(--text-muted); }
.review-score { font-size: 22px; font-weight: 700; }
.review-habits { display: flex; flex-direction: column; gap: 8px; }
.review-habit-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.review-habit-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.review-bar-wrap { width: 80px; height: 8px; background: var(--bg-secondary); border-radius: 4px; overflow: hidden; flex-shrink: 0; }
.review-bar { height: 100%; border-radius: 4px; transition: width 0.4s; }
.review-pct { font-size: 12px; color: var(--text-muted); width: 28px; text-align: right; flex-shrink: 0; }
.review-missed { margin: 0; padding-left: 20px; font-size: 14px; color: var(--text); }
.review-missed li { margin: 4px 0; }
.review-tip { font-size: 13px; color: var(--text-secondary); background: var(--bg-secondary); padding: 10px 12px; border-radius: var(--radius); margin-top: 12px; }
.page-header-actions { display: flex; gap: 8px; margin-left: auto; }

/* ===== EditorJS Overrides ===== */
.codex-editor__redactor {
  padding-bottom: 20px !important;
  margin-right: 0 !important;
  margin-left: 0 !important;
  max-width: none !important;
}

.ce-block__content {
  max-width: none !important;
  margin-left: 36px !important; /* Space for the '+' and 'dots' icons on the left */
  margin-right: 16px !important;
}

.ce-toolbar__content {
  max-width: none !important;
  margin-left: 0 !important;
}

.ce-toolbar__actions {
  left: -20px !important; /* Move the toolbar icons slightly to the left of the text */
}

/* Ensure the toolbar doesn't fly off screen */
.ce-toolbar {
  left: 0 !important;
  width: 0 !important;
}

[data-theme='dark'] .ce-toolbar__plus,
[data-theme='dark'] .ce-toolbar__settings-btn {
  background-color: var(--bg-secondary) !important;
  color: var(--text) !important;
}

[data-theme='dark'] .ce-conversion-tool,
[data-theme='dark'] .ce-inline-tool,
[data-theme='dark'] .ce-popover {
  background-color: var(--bg-secondary) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
}

/* Checklist Checkbox Styles */
.cdx-checklist__item-checkbox {
  border-color: var(--border) !important;
  background-color: var(--bg) !important;
}

.cdx-checklist__item--checked .cdx-checklist__item-checkbox {
  background-color: var(--accent) !important;
  border-color: var(--accent) !important;
}

[data-theme='dark'] .cdx-checklist__item-checkbox {
  background-color: var(--bg-secondary) !important;
}

/* Importance Tags */
.importance-tag {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
  text-transform: uppercase;
}
.importance-tag.high {
  background: #fee2e2;
  color: #dc2626;
  border: 1px solid #fecaca;
}
.importance-tag.med {
  background: #fef3c7;
  color: #d97706;
  border: 1px solid #fde68a;
}
[data-theme='dark'] .importance-tag.high {
  background: #450a0a;
  color: #f87171;
  border-color: #7f1d1d;
}
[data-theme='dark'] .importance-tag.med {
  background: #451a03;
  color: #fbbf24;
  border-color: #78350f;
}

.badge-notif {
  background: var(--bg-secondary) !important;
  color: var(--text-secondary) !important;
}
