/* =============================================
   HABIT TRACKER PWA — styles.css
   Design system: warm beige, white cards,
   black accents, green streaks
   ============================================= */

/* ── Google Font ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── CSS Variables ── */
:root {
  --bg-primary: #F8F9FA;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-sidebar: rgba(255, 255, 255, 0.9);
  --text-primary: #1A1A1A;
  --text-secondary: #555555;
  --text-tertiary: #999999;
  --border-color: #E5E5E5;
  --accent-primary: #111111;
  --accent-hover: #333333;
  --success-color: #10B981;
  --success-light: #D1FAE5;
  --danger-color: #EF4444;
  --warning-color: #F59E0B;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.12);
  --sidebar-w: 220px;
  --topbar-h: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --accent-text: #FFFFFF;
}

/* Dark Mode */
[data-theme="dark"] {
  --bg-primary: #121212;
  --bg-card: rgba(30, 30, 30, 0.7);
  --bg-sidebar: rgba(24, 24, 24, 0.8);
  --text-primary: #F3F4F6;
  --text-secondary: #9CA3AF;
  --text-tertiary: #6B7280;
  --border-color: rgba(255, 255, 255, 0.15);
  --accent-primary: #FFFFFF;
  --accent-hover: #E5E5E5;
  --success-light: #064E3B;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.5);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ── Loading Screen ── */
.loading-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-primary);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 24px; transition: opacity 0.4s ease;
}
.loading-screen.fade-out { opacity: 0; pointer-events: none; }
.loading-logo { display: flex; align-items: center; gap: 12px; }
.loading-icon {
  width: 48px; height: 48px; background: var(--accent-primary);
  border-radius: 14px; display: flex; align-items: center;
  justify-content: center; color: white; font-size: 24px; font-weight: 700;
}
.loading-text { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.loading-spinner {
  width: 32px; height: 32px; border: 3px solid var(--border-color);
  border-top-color: var(--accent-primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Install Banner ── */
.install-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: var(--accent-primary); color: var(--accent-text);
  padding: 12px 20px; display: flex; align-items: center;
  justify-content: space-between; gap: 16px;
  animation: slideDown 0.3s ease;
}
.install-banner-close {
  color: var(--accent-text);
  opacity: 0.7;
  cursor: pointer;
  font-weight: 700;
  font-size: 16px;
  padding: 4px;
}
.install-banner-close:hover { opacity: 1; }
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
.install-banner-content { display: flex; align-items: center; gap: 12px; }
.install-icon { font-size: 20px; }
.install-text { display: flex; flex-direction: column; }
.install-text strong { font-size: 14px; font-weight: 600; }
.install-text span { font-size: 12px; opacity: 0.8; }
.install-banner-actions { display: flex; gap: 8px; align-items: center; }
.btn-install {
  background: white; color: var(--accent-primary);
  padding: 6px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
}
.btn-dismiss { color: white; opacity: 0.7; font-size: 18px; padding: 4px; }
.btn-dismiss:hover { opacity: 1; }

/* ── Offline Banner ── */
.offline-banner {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  z-index: 999; background: #1A1A1A; color: white;
  padding: 10px 20px; border-radius: 20px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateX(-50%) translateY(20px); opacity:0; } to { transform: translateX(-50%) translateY(0); opacity:1; } }

/* ── App Layout ── */
.app-container {
  display: flex; height: 100vh; overflow: hidden;
  opacity: 0; transition: opacity 0.3s ease;
  max-width: 1600px; margin: 0 auto;
  box-shadow: var(--shadow-2xl, 0 25px 50px -12px rgba(0, 0, 0, 0.25));
  background: var(--bg-primary);
}
.app-container.visible { opacity: 1; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); height: 100vh;
  background: var(--bg-sidebar); border-right: 1px solid var(--border-color);
  display: flex; flex-direction: column;
  padding: 0; padding-bottom: env(safe-area-inset-bottom); flex-shrink: 0; overflow-y: auto;
  transition: transform var(--transition);
  z-index: 100;
}
.sidebar-header {
  padding: 20px 16px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 32px; height: 32px; background: var(--accent-primary);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.logo-text { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.sidebar-close-btn { display: none; font-size: 18px; color: var(--text-tertiary); padding: 4px; }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-section { margin-bottom: 24px; }
.nav-section-header {
  font-size: 11px; font-weight: 600; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0 12px 8px;
}
.sidebar-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; color: var(--text-secondary);
  cursor: pointer; transition: background var(--transition), color var(--transition);
  margin-bottom: 2px; text-align: left;
}
.sidebar-item:hover { background: var(--bg-primary); color: var(--text-primary); }
.sidebar-item.active { background: var(--bg-primary); color: var(--text-primary); font-weight: 600; }
.sidebar-icon { font-size: 16px; flex-shrink: 0; }
.sidebar-label { flex: 1; }
.badge {
  background: var(--bg-primary); border: 1px solid var(--border-color);
  color: var(--text-secondary); font-size: 11px; font-weight: 600;
  padding: 2px 7px; border-radius: 10px; min-width: 22px; text-align: center;
}
[data-theme="dark"] .badge { background: #2A2A2A; }

.category-list { padding: 0 4px; }
.category-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text-secondary); cursor: pointer;
  transition: background var(--transition);
}
.category-item:hover { background: var(--bg-primary); }
.category-item.active { background: var(--bg-primary); color: var(--text-primary); font-weight: 600; }
.category-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--border-color);
}
.user-profile { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-primary); border: 2px solid var(--border-color);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.user-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.user-streak { font-size: 12px; color: var(--text-tertiary); display: flex; align-items: center; gap: 4px; }

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

/* ── Main Content ── */
.main-content {
  flex: 1; display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
}

/* ── Top Bar ── */
.top-bar {
  height: var(--topbar-h); flex-shrink: 0;
  background: var(--bg-sidebar); border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; gap: 16px; z-index: 10;
}
.top-bar-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.top-bar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.hamburger-btn {
  display: none; flex-direction: column; gap: 5px;
  padding: 8px; border-radius: var(--radius-sm); cursor: pointer;
}
.hamburger-btn span {
  display: block; width: 20px; height: 2px;
  background: var(--text-primary); border-radius: 2px;
  transition: transform 0.2s;
}

.search-input {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 8px 14px;
  max-width: 320px; width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.search-icon { font-size: 14px; flex-shrink: 0; }
.search-input input {
  border: none; outline: none; background: transparent;
  font-size: 14px; color: var(--text-primary); flex: 1; min-width: 0;
}
.search-input input::placeholder { color: var(--text-tertiary); }

/* ── Buttons ── */
.btn-primary {
  background: var(--accent-primary); color: var(--accent-text, white);
  border: none; border-radius: var(--radius-sm);
  padding: 9px 18px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background var(--transition), transform 0.1s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  padding: 9px 16px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background var(--transition), border-color var(--transition);
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn-secondary:hover { background: var(--bg-primary); }

.btn-danger {
  background: var(--danger-color); color: white;
  border: none; border-radius: var(--radius-sm);
  padding: 9px 18px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: opacity var(--transition);
}
.btn-danger:hover { opacity: 0.85; }

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

/* ── Views ── */
.view {
  flex: 1; overflow-y: auto; padding-bottom: calc(32px + env(safe-area-inset-bottom));
}
.view.hidden { display: none !important; }

.view-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px 24px 0; margin-bottom: 20px;
}
.view-title { font-size: 20px; font-weight: 700; color: var(--text-primary); }
.view-actions { display: flex; align-items: center; gap: 8px; }

/* ── Stats Section ── */
.stats-section {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 16px; padding: 20px 24px;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 20px;
  transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 16px;
}
.stat-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.stat-subtitle { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }
.stat-nav-btn {
  color: var(--text-tertiary); font-size: 16px; font-weight: 700;
  cursor: pointer; padding: 4px 8px; border-radius: 4px;
  transition: background var(--transition), color var(--transition);
}
.stat-nav-btn:hover { background: var(--bg-primary); color: var(--text-primary); }

.stat-value {
  font-size: 36px; font-weight: 800;
  color: var(--text-primary); line-height: 1;
}
.streak-value { color: var(--success-color); }
.stat-meta { font-size: 12px; color: var(--text-tertiary); margin-top: 6px; }

/* Bar Chart */
.bar-chart {
  display: flex; align-items: flex-end; gap: 6px; height: 60px;
}
.bar {
  flex: 1; background: var(--accent-primary); border-radius: 3px 3px 0 0;
  transition: height 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-height: 4px; cursor: pointer;
}
.bar:hover { opacity: 0.75; }
.bar.today { background: var(--success-color); }
.bar-chart-labels {
  display: flex; gap: 6px; margin-top: 6px;
}
.bar-label { flex: 1; text-align: center; font-size: 10px; color: var(--text-tertiary); font-weight: 500; }

/* Donut Chart */
.donut-chart-container {
  position: relative; display: flex; align-items: center; justify-content: center;
}
.donut-center {
  position: absolute; text-align: center;
}
.donut-value { font-size: 20px; font-weight: 800; color: var(--text-primary); }
.donut-sublabel { font-size: 10px; color: var(--text-tertiary); font-weight: 500; }

/* ── Status Columns ── */
.columns-section { padding: 0 24px; }
.columns-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px;
}
.columns-title { font-size: 16px; font-weight: 700; }
.view-toggle { display: flex; gap: 4px; }
.view-toggle-btn {
  padding: 6px 10px; border-radius: var(--radius-sm); font-size: 16px;
  color: var(--text-tertiary); transition: background var(--transition), color var(--transition);
}
.view-toggle-btn.active, .view-toggle-btn:hover {
  background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.status-columns {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
}
.status-column { min-width: 0; }
.column-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px; margin-bottom: 12px;
}
.column-title { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.column-count {
  font-size: 12px; font-weight: 600; color: var(--text-tertiary);
  background: var(--bg-primary); border: 1px solid var(--border-color);
  border-radius: 10px; padding: 2px 8px;
}
.column-cards { display: flex; flex-direction: column; gap: 10px; }

/* ── Habit Card ── */
.card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-md); padding: 16px;
  transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  cursor: pointer; position: relative; overflow: hidden;
  animation: slideUpFade 0.4s ease backwards;
}
@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.card:hover { 
  box-shadow: var(--shadow-lg); 
  border-color: var(--text-tertiary); 
  transform: translateY(-3px) scale(1.01); 
}
.card.completed { border-left: 3px solid var(--success-color); opacity: 0.85; }
.card.archived { opacity: 0.6; }
.card-color-strip {
  position: absolute; top: 0; left: 0; right: 0; height: 3px; border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 8px; }
.card-title-group { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.card-icon {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); line-height: 1.3; }
.card-menu-btn { color: var(--text-tertiary); font-size: 18px; padding: 2px 6px; border-radius: 4px; transition: background 0.15s; }
.card-menu-btn:hover { background: var(--bg-primary); }
.card-description { font-size: 12px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 12px; }
.card-footer {
  display: flex; align-items: center; gap: 12px;
  font-size: 11px; color: var(--text-tertiary); margin-top: auto;
}
.card-footer-item { display: flex; align-items: center; gap: 4px; }
.card-streak { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.card-streak-val { font-size: 12px; font-weight: 700; color: var(--success-color); }
.card-check-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border-color);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); cursor: pointer; font-size: 14px; background: transparent;
}
.card-check-btn:hover { border-color: var(--success-color); background: var(--success-light); transform: scale(1.15); }
.card-check-btn:active { transform: scale(0.9); }
.card-check-btn.done { background: var(--success-color); border-color: var(--success-color); color: white; transform: rotate(360deg); }

/* Dropdown menu */
.card-dropdown {
  position: absolute; top: 36px; right: 16px; z-index: 50;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 6px;
  box-shadow: var(--shadow-lg); min-width: 140px;
  animation: fadeIn 0.15s ease;
}
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; cursor: pointer; width: 100%;
  transition: background var(--transition); color: var(--text-primary);
}
.dropdown-item:hover { background: var(--bg-primary); }
.dropdown-item.danger { color: var(--danger-color); }

.advanced-filter-dropdown {
  position: fixed;
  z-index: 1000;
  padding: 0;
}

/* ── Habits Grid ── */
.habits-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px; padding: 0 24px;
}

/* Filter select */
.filter-select {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 8px 12px;
  font-size: 13px; font-weight: 500; color: var(--text-primary);
  cursor: pointer; outline: none;
}

/* ── Empty State ── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 24px; text-align: center;
  min-height: 300px;
}
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.empty-desc { font-size: 14px; color: var(--text-secondary); max-width: 320px; margin-bottom: 24px; }

/* ── Activity Calendar ── */
.activity-container {
  display: grid; grid-template-columns: 1fr 300px; gap: 20px; padding: 0 24px;
}
.calendar-grid {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 20px; overflow: hidden;
}
.calendar-month-header {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 4px; margin-bottom: 8px;
}
.calendar-day-label { text-align: center; font-size: 11px; font-weight: 600; color: var(--text-tertiary); padding: 4px; }
.calendar-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-day {
  aspect-ratio: 1; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 500; cursor: pointer;
  transition: background var(--transition); text-align: center;
  flex-direction: column; gap: 2px; border: 1px solid transparent;
}
.calendar-day:hover { border-color: var(--border-color); }
.calendar-day.empty { cursor: default; }
.calendar-day.today { font-weight: 700; border: 2px solid var(--accent-primary); }
.calendar-day.has-completions { background: var(--success-light); color: var(--success-color); }
.calendar-day.selected { background: var(--accent-primary) !important; color: white !important; }
.calendar-day-num { font-size: 12px; }
.calendar-day-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--success-color); }
.activity-sidebar {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 20px; height: fit-content;
}
.activity-sidebar-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text-secondary); }

/* ── Insights ── */
.insights-container { padding: 0 24px; display: flex; flex-direction: column; gap: 20px; }
.insights-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* Enhanced Top Stats */
.insight-stat-card-v2 {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 20px;
  display: flex; flex-direction: column; gap: 8px;
  position: relative; overflow: hidden;
}
.insight-stat-card-v2.highlight { border-color: var(--warning-color); box-shadow: 0 0 0 1px var(--warning-color); }
.insight-stat-card-v2.rate-card.green { border-bottom: 3px solid var(--success-color); }
.insight-stat-card-v2.rate-card.yellow { border-bottom: 3px solid var(--warning-color); }
.insight-stat-card-v2.rate-card.red { border-bottom: 3px solid var(--danger-color); }

.stat-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 4px; }
.stat-icon { font-size: 24px; }
.stat-trend { font-size: 12px; font-weight: 700; padding: 2px 6px; border-radius: 10px; }
.stat-trend.positive { color: var(--success-color); background: var(--success-light); }
.stat-trend.negative { color: var(--danger-color); background: rgba(239, 68, 68, 0.1); }
.stat-value { font-size: 32px; font-weight: 800; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.stat-subtitle { font-size: 11px; color: var(--text-tertiary); margin-top: auto; }
.stat-habit-name { font-size: 12px; color: var(--warning-color); font-weight: 600; }
.stat-progress { height: 4px; background: var(--bg-primary); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.stat-progress-fill { height: 100%; background: var(--accent-primary); transition: width 0.5s; }

/* Trend Insights */
.trend-insights-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (max-width: 900px) { .trend-insights-grid { grid-template-columns: 1fr; } }
.insight-card-v2 { display: flex; gap: 12px; background: var(--bg-primary); padding: 16px; border-radius: var(--radius-md); border-left: 3px solid transparent; align-items: center; }
.insight-card-v2.streak { border-left-color: var(--warning-color); }
.insight-card-v2.pattern { border-left-color: var(--accent-primary); }
.insight-card-v2.warning { border-left-color: var(--danger-color); }
.insight-card-v2.achievement { border-left-color: var(--success-color); }
.insight-card-icon { font-size: 24px; flex-shrink: 0; }
.insight-card-text { font-size: 13px; color: var(--text-secondary); line-height: 1.4; }

/* Time Performance */
.time-breakdown { display: flex; flex-direction: column; gap: 16px; padding: 8px 0; }
.time-category { display: flex; flex-direction: column; gap: 6px; }
.time-header { display: flex; align-items: center; gap: 8px; }
.time-icon { font-size: 16px; }
.time-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.time-bar { height: 8px; background: var(--bg-primary); border-radius: 4px; overflow: hidden; }
.time-fill { height: 100%; background: var(--accent-primary); transition: width 1s cubic-bezier(0.34,1.56,0.64,1); }
.time-stats { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-tertiary); font-weight: 600; }
.time-insight { margin-top: 16px; padding: 12px 16px; background: var(--success-light); border-radius: var(--radius-md); font-size: 13px; color: #065F46; }

/* Advanced Heatmap */
.heatmap-advanced { display: flex; flex-direction: column; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.heatmap-header { display: flex; align-items: center; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; margin-bottom: 8px; }
.habit-label { width: 150px; flex-shrink: 0; font-size: 12px; font-weight: 600; color: var(--text-tertiary); }
.heatmap-weeks-label { display: flex; gap: 4px; }
.week-label { width: 22px; font-size: 10px; color: var(--text-tertiary); text-align: center; }
.heatmap-body { display: flex; flex-direction: column; gap: 6px; }
.heatmap-row { display: flex; align-items: center; }
.habit-name { width: 150px; flex-shrink: 0; font-size: 13px; font-weight: 500; color: var(--text-primary); display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 8px; }
.habit-icon-small { font-size: 14px; }
.heatmap-weeks { display: flex; gap: 4px; }
.heatmap-cell-adv { width: 22px; height: 22px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: white; transition: transform 0.1s; cursor: default; }
.heatmap-cell-adv:hover { transform: scale(1.1); box-shadow: var(--shadow-sm); z-index: 2; position: relative;}

/* Categorized Habit Stats */
.habit-stats-container { display: flex; flex-direction: column; gap: 24px; padding: 4px 0; }
.stat-category { display: flex; flex-direction: column; gap: 12px; }
.stat-category-title { font-size: 14px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.habit-stat-row-v2 { display: flex; align-items: center; gap: 12px; background: var(--bg-primary); padding: 12px; border-radius: var(--radius-md); }
.habit-stat-icon-v2 { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.habit-stat-info-v2 { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.habit-stat-name-v2 { font-size: 14px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit-stat-meta-v2 { display: flex; align-items: center; gap: 8px; min-height: 14px; }
.streak-badge { font-size: 10px; font-weight: 700; color: var(--warning-color); background: rgba(245, 158, 11, 0.1); padding: 2px 6px; border-radius: 8px; }
.habit-stat-metrics-v2 { flex: 1; display: flex; align-items: center; gap: 12px; justify-content: flex-end; }
.habit-stat-bar-wrap-v2 { flex: 1; max-width: 120px; }
.habit-stat-bar-bg-v2 { height: 6px; background: var(--border-color); border-radius: 3px; overflow: hidden; }
.habit-stat-bar-fill-v2 { height: 100%; background: var(--success-color); border-radius: 3px; transition: width 1s cubic-bezier(0.34,1.56,0.64,1); }
.habit-stat-pct-v2 { font-size: 13px; font-weight: 700; color: var(--text-primary); min-width: 36px; text-align: right; }
.quick-start-btn { width: 28px; height: 28px; border-radius: 50%; background: var(--bg-card); border: 1px solid var(--border-color); display: flex; align-items: center; justify-content: center; color: var(--text-secondary); transition: all 0.2s; cursor: pointer; }
.quick-start-btn:hover { background: var(--success-color); color: white; border-color: var(--success-color); }

/* Next Milestone */
.next-achievement { margin-bottom: 24px; padding: 0 4px; }
.next-ach-title { font-size: 13px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }
.achievement-card.featured { display: flex; align-items: center; gap: 16px; background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(59, 130, 246, 0.08)); border: 1px solid var(--border-color); padding: 20px; border-radius: var(--radius-lg); }
.achievement-card.featured .achievement-icon { font-size: 40px; margin: 0; }
.achievement-card.featured .achievement-info h5 { font-size: 16px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.achievement-card.featured .achievement-info p { font-size: 13px; color: var(--text-secondary); line-height: 1.5;}

/* Achievements */
.achievements-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px,1fr)); gap: 12px; }
.achievement-item {
  background: var(--bg-primary); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 16px; text-align: center;
  transition: box-shadow var(--transition); position: relative;
}
.achievement-item.unlocked { background: var(--success-light); border-color: var(--success-color); }
.achievement-icon { font-size: 28px; margin-bottom: 8px; }
.achievement-name { font-size: 12px; font-weight: 600; color: var(--text-primary); line-height: 1.3; }
.achievement-desc { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }
.achievement-badge {
  position: absolute; top: -6px; right: -6px;
  background: var(--success-color); color: white;
  border-radius: 50%; width: 18px; height: 18px; font-size: 10px;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}

/* Period toggle */
.period-toggle { display: flex; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 3px; }
.period-btn { padding: 5px 14px; border-radius: 4px; font-size: 13px; font-weight: 500; color: var(--text-secondary); transition: all var(--transition); }
.period-btn.active { background: var(--accent-primary); color: white; }

/* ── Settings ── */
.settings-container { padding: 0 24px; display: flex; flex-direction: column; gap: 16px; }
.settings-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 24px;
  margin-bottom: 8px; /* Added spacing between cards */
}
.settings-section-title { font-size: 15px; font-weight: 700; margin-bottom: 20px; color: var(--text-primary); }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--border-color); gap: 16px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row-info { flex: 1; }
.settings-row-label { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.settings-row-desc { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; line-height: 1.4; }
.settings-row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-row .settings-row-label { color: var(--danger-color); }
.version-tag { font-size: 12px; font-weight: 600; color: var(--text-tertiary); background: var(--bg-primary); padding: 4px 10px; border-radius: 12px; }
.settings-about-text { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.btn-file-label { display: inline-flex; align-items: center; cursor: pointer; }

.theme-toggle-group { display: flex; gap: 6px; }
.theme-btn, .sound-btn { padding: 7px 14px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 500; border: 1px solid var(--border-color); color: var(--text-secondary); transition: all var(--transition); }
.theme-btn.active, .sound-btn.active { background: var(--accent-primary); color: var(--accent-text) !important; border-color: var(--accent-primary); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; animation: fadeIn 0.3s ease;
}
.modal-overlay.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card); border-radius: var(--radius-lg);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); animation: slideUp 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-tertiary); transition: background var(--transition);
}
.modal-close:hover { background: var(--bg-primary); }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  padding: 16px 24px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border-color);
  display: flex; justify-content: flex-end; gap: 8px;
  background: var(--bg-card); position: sticky; bottom: 0;
}

/* ── Form Elements ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.form-input {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: 14px; color: var(--text-primary); outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
.form-input:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 3px rgba(0,0,0,0.06); }
.form-textarea { resize: vertical; min-height: 64px; }
.form-select { appearance: none; cursor: pointer; color: var(--text-primary); background-color: var(--bg-card); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.form-select option { background: var(--bg-card); color: var(--text-primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Freq toggle */
.freq-toggle-group, .day-picker { display: flex; gap: 4px; }
.freq-btn, .day-btn {
  padding: 7px 14px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; border: 1px solid var(--border-color);
  color: var(--text-secondary); transition: all var(--transition);
}
.freq-btn.active, .day-btn.active { background: var(--accent-primary); color: white; border-color: var(--accent-primary); }
.day-btn { padding: 7px 10px; }

/* Color picker */
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid transparent; transition: transform 0.15s, border-color 0.15s;
  cursor: pointer;
}
.color-swatch.active, .color-swatch:hover { border-color: var(--text-primary); transform: scale(1.15); }

/* Icon picker */
.icon-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  font-size: 18px; border: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); background: var(--bg-primary);
}
.icon-btn.active, .icon-btn:hover { border-color: var(--accent-primary); background: var(--bg-card); transform: scale(1.1); }

/* ── Detail Panel ── */
.detail-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(2px);
  display: flex; justify-content: flex-end;
  animation: fadeIn 0.2s ease;
}
.detail-overlay.hidden { display: none !important; }
.detail-panel {
  width: 420px; height: 100%; background: var(--bg-card);
  overflow-y: auto; box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
.detail-header {
  display: flex; align-items: center; gap: 12px;
  padding: 20px; border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.detail-icon-badge {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  background: var(--bg-primary); flex-shrink: 0;
}
.detail-title-group { flex: 1; min-width: 0; }
.detail-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.detail-category { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }
.detail-actions { display: flex; gap: 4px; }
.detail-body { padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 24px; }
.detail-description { font-size: 14px; color: var(--text-secondary); line-height: 1.6; }
.detail-stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.detail-stat {
  background: var(--bg-primary); border-radius: var(--radius-md);
  padding: 12px; text-align: center;
}
.detail-stat-value { font-size: 20px; font-weight: 800; color: var(--text-primary); }
.detail-stat-label { font-size: 10px; color: var(--text-tertiary); margin-top: 4px; }
.detail-section-title { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 10px; }

/* Mini calendar */
.detail-mini-calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.mini-cal-day {
  aspect-ratio: 1; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--text-tertiary);
}
.mini-cal-day.completed-day { background: var(--success-color); color: white; font-weight: 700; }
.mini-cal-day.today-day { border: 2px solid var(--accent-primary); }

.detail-completions-list { display: flex; flex-direction: column; gap: 8px; }
.completion-entry {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px; background: var(--bg-primary); border-radius: var(--radius-sm);
}
.completion-check { color: var(--success-color); font-weight: 700; font-size: 14px; flex-shrink: 0; }
.completion-date { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.completion-note { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ── Celebration ── */
.celebration-overlay {
  position: fixed; inset: 0; z-index: 600;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.3s ease;
}
.celebration-overlay.hidden { display: none !important; }
.celebration-content {
  background: var(--bg-card); border-radius: var(--radius-lg);
  padding: 40px 48px; text-align: center; max-width: 360px; z-index: 1;
  animation: bounceIn 0.5s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes bounceIn { from { transform: scale(0.3); opacity:0; } to { transform: scale(1); opacity:1; } }
.celebration-emoji { font-size: 64px; margin-bottom: 16px; animation: bounce 0.6s ease infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-12px); } }
.celebration-title { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
.celebration-message { font-size: 15px; color: var(--text-secondary); margin-bottom: 24px; }
#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 0; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 800; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1A1A1A; color: white; padding: 12px 18px;
  border-radius: var(--radius-md); font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 8px;
  animation: slideUp 0.3s ease; max-width: 320px;
}
.toast.success { background: var(--success-color); }
.toast.error { background: var(--danger-color); }

/* ── Auto-Save Indicator ── */
.auto-save-indicator {
  position: fixed; bottom: 24px; left: 24px; z-index: 700;
  background: var(--bg-card); color: var(--text-secondary);
  padding: 8px 16px; border-radius: 20px; font-size: 12px; font-weight: 500;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border-color);
  display: flex; align-items: center; gap: 6px;
  animation: fadeIn 0.3s ease;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .stats-section { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
  .stat-chart { grid-column: 1 / -1; }
  .status-columns { grid-template-columns: repeat(2, 1fr); }
  .insights-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100%;
    width: 260px; transform: translateX(-100%); z-index: 200;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-close-btn { display: flex; }
  .sidebar-overlay { display: block; }
  .hamburger-btn { display: flex; }
  .search-input { max-width: 200px; }
  .stats-section { grid-template-columns: 1fr 1fr; padding: 12px; }
  .stat-chart { grid-column: 1 / -1; }
  .status-columns { grid-template-columns: 1fr; }
  .columns-section { padding: 0 12px; }
  .habits-grid { padding: 0 12px; grid-template-columns: 1fr; }
  .activity-container { grid-template-columns: 1fr; }
  .insights-stats { grid-template-columns: repeat(2, 1fr); }
  .insights-container { padding: 0 12px; }
  .settings-container { padding: 0 12px; }
  .detail-panel { width: 100%; }
  .view-header { padding: 16px 12px 0; }
  .top-bar { padding: 0 12px; }
  .form-row { grid-template-columns: 1fr; }
  .detail-stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .stats-section { grid-template-columns: 1fr; }
  .insights-stats { grid-template-columns: 1fr 1fr; }
  .achievements-grid { grid-template-columns: repeat(2, 1fr); }
  .top-bar-right .btn-secondary { display: none; }
  .year-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

/* Smooth scroll for views */
.view { scroll-behavior: smooth; }

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Selection */
::selection { background: rgba(0,0,0,0.1); }
[data-theme="dark"] ::selection { background: rgba(255,255,255,0.2); }

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

/* ── AI Assistant View ── */
.ai-container {
  display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - 32px);
  padding: 0 24px; max-width: 800px; margin: 0 auto;
}
.ai-chat-history {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px;
  padding: 24px 0;
}
.ai-msg { display: flex; width: 100%; }
.ai-msg.user { justify-content: flex-end; }
.ai-msg.app { justify-content: flex-start; }
.ai-bubble {
  max-width: 80%; padding: 12px 16px; border-radius: 18px; font-size: 15px; line-height: 1.5;
  word-wrap: break-word; font-weight: 500; animation: slideUpFade 0.3s ease;
}
.ai-msg.user .ai-bubble {
  background: var(--accent-primary); color: white;
  border-bottom-right-radius: 4px;
}
.ai-msg.app .ai-bubble {
  background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px; border-top-left-radius: 4px;
}
.ai-msg.app.loading .ai-bubble {
  color: var(--text-tertiary); font-style: italic; background: transparent; border: none;
}
.ai-input-area {
  padding: 16px 0 calc(16px + env(safe-area-inset-bottom));
  background: var(--bg-primary); z-index: 10;
  border-top: 1px solid var(--border-color);
  margin: 0 -24px; padding: 16px 24px calc(16px + env(safe-area-inset-bottom));
}
#ai-chat-form { display: flex; gap: 12px; }
.ai-input { flex: 1; border-radius: 24px; padding: 12px 20px; font-size: 15px; }
#ai-send-btn { border-radius: 24px; padding: 10px 20px; font-weight: 600; flex-shrink: 0; }

/* ── Smart Parsing ── */
.parse-activity-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border-color);
  transition: background var(--transition), opacity var(--transition);
}
.parse-activity-card:last-child { border-bottom: none; }
.parse-activity-card.unchecked { opacity: 0.45; }
.parse-activity-card:hover { background: var(--bg-primary); }

.parse-checkbox {
  width: 20px; height: 20px; border-radius: 5px;
  border: 2px solid var(--border-color); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.2s;
  accent-color: var(--success-color);
}
.parse-checkbox:checked { background: var(--success-color); border-color: var(--success-color); }

.parse-emoji {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--bg-primary); border: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0; cursor: default;
}

.parse-details { flex: 1; min-width: 0; }
.parse-name {
  font-size: 14px; font-weight: 600; color: var(--text-primary);
  line-height: 1.3; margin-bottom: 4px;
}
.parse-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 11px; color: var(--text-tertiary);
}
.parse-meta-item { display: flex; align-items: center; gap: 3px; }

.parse-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
}
.parse-badge.new-habit { background: #DBEAFE; color: #1D4ED8; }
.parse-badge.existing { background: var(--success-light); color: var(--success-color); }
[data-theme="dark"] .parse-badge.new-habit { background: #1E3A5F; color: #93C5FD; }

.parse-confidence {
  font-size: 10px; font-weight: 600; padding: 2px 6px;
  border-radius: 8px; white-space: nowrap;
}
.parse-confidence.high { color: var(--success-color); }
.parse-confidence.medium { color: var(--warning-color); }
.parse-confidence.low { color: var(--danger-color); }

.parse-remove-btn {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-tertiary); flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
}
.parse-remove-btn:hover { background: var(--danger-color); color: white; }

.parse-category-select {
  font-size: 11px; padding: 2px 6px; border-radius: 4px;
  border: 1px solid var(--border-color); background: var(--bg-card);
  color: var(--text-secondary); cursor: pointer; outline: none;
}

.parse-quantity {
  font-size: 11px; color: var(--text-secondary); font-weight: 500;
  background: var(--bg-primary); padding: 1px 6px; border-radius: 4px;
}

/* ── Accent Color Picker ── */
.accent-picker {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.accent-swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}
.accent-swatch:hover { transform: scale(1.15); }
.accent-swatch.active {
  border-color: var(--text-primary);
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 4px var(--text-tertiary);
}
.accent-custom-wrap {
  display: flex; align-items: center; gap: 4px;
}
.accent-color-input {
  width: 26px; height: 26px; border: none; padding: 0;
  border-radius: 50%; cursor: pointer; background: transparent;
  -webkit-appearance: none; appearance: none;
}
.accent-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.accent-color-input::-webkit-color-swatch { border: 2px solid var(--border-color); border-radius: 50%; }
.accent-color-input::-moz-color-swatch { border: 2px solid var(--border-color); border-radius: 50%; }

/* ── Category Group Headers ── */
.category-group {
  margin-bottom: 24px;
}
.category-group-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0 12px; margin-bottom: 4px;
  border-bottom: 2px solid var(--border-color);
}
.category-group-emoji {
  font-size: 20px;
}
.category-group-label {
  font-size: 15px; font-weight: 700; color: var(--text-primary);
  flex: 1;
}
.category-group-count {
  font-size: 12px; font-weight: 600; color: var(--text-tertiary);
  background: var(--bg-primary); border: 1px solid var(--border-color);
  border-radius: 12px; padding: 2px 10px;
}
.category-group .habits-grid {
  padding: 0; margin-top: 12px;
}

/* ── Card Progress Indicator (multi-target) ── */
.card-progress {
  display: flex; align-items: center; gap: 4px;
  margin-left: auto;
}
.card-progress-bar {
  width: 40px; height: 5px; background: var(--border-color);
  border-radius: 3px; overflow: hidden;
}
.card-progress-fill {
  height: 100%; background: var(--success-color);
  border-radius: 3px; transition: width 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
.card-progress-text {
  font-size: 10px; font-weight: 700; color: var(--text-secondary);
  min-width: 24px; text-align: right;
}

/* ── AI Recommendations Panel ── */
.rec-panel {
  margin: 0 24px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: box-shadow var(--transition);
}
.rec-panel:hover { box-shadow: var(--shadow-sm); }
.rec-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 16px; gap: 12px;
}
.rec-header-left { flex: 1; }
.rec-title {
  font-size: 15px; font-weight: 700; color: var(--text-primary);
  display: flex; align-items: center; gap: 6px;
}
.rec-subtitle {
  font-size: 11px; color: var(--text-tertiary); display: block; margin-top: 2px;
}
.rec-refresh-btn {
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  padding: 6px 12px; background: var(--bg-primary);
  cursor: pointer; transition: all var(--transition); white-space: nowrap;
}
.rec-refresh-btn:hover { background: var(--bg-card); border-color: var(--text-tertiary); }
.rec-refresh-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Daily Insight Banner */
.rec-daily-insight {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 14px; margin-bottom: 14px;
  background: var(--bg-primary); border-radius: var(--radius-sm);
  border-left: 3px solid var(--warning-color);
  font-size: 12px; font-style: italic; color: var(--text-secondary);
  line-height: 1.5;
}
.rec-daily-insight-icon { font-size: 14px; flex-shrink: 0; line-height: 1.4; }

/* Loading skeleton */
.rec-loading { padding: 8px 0; }
.rec-skeleton {
  height: 14px; background: var(--border-color); border-radius: 6px;
  margin-bottom: 10px; animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
  0% { opacity: 0.5; }
  50% { opacity: 1; }
  100% { opacity: 0.5; }
}

/* Empty / error states */
.rec-empty {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--bg-primary); font-size: 13px; color: var(--text-secondary);
}
.rec-empty-icon { font-size: 18px; flex-shrink: 0; }
.rec-empty-inline {
  font-size: 13px; color: var(--text-tertiary);
  padding: 12px 0; text-align: center;
}

/* Recommendation Cards */
.rec-cards { display: flex; flex-direction: column; gap: 10px; }
.rec-card {
  display: flex; flex-wrap: wrap; align-items: stretch;
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
  overflow: hidden; transition: all 0.25s ease;
  position: relative; background: var(--bg-card);
  animation: slideUpFade 0.4s ease backwards;
}
.rec-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--text-tertiary);
}

/* Dismiss button */
.rec-dismiss-btn {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: var(--text-tertiary);
  background: transparent; cursor: pointer;
  transition: all 0.15s; opacity: 0;
  border: none;
}
.rec-card:hover .rec-dismiss-btn { opacity: 1; }
.rec-dismiss-btn:hover {
  background: var(--danger-color); color: white;
}

/* Card layout */
.rec-card-left {
  width: 48px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; border-radius: var(--radius-md) 0 0 0;
}
.rec-card-emoji { font-size: 20px; }

.rec-card-body {
  flex: 1; padding: 12px 14px; min-width: 0;
}
.rec-card-name {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  margin-bottom: 2px; line-height: 1.3;
}
.rec-card-insight {
  font-size: 12px; color: var(--text-secondary); line-height: 1.4;
}
.rec-card-meta {
  display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap;
}

/* Right side */
.rec-card-right {
  display: flex; align-items: center; justify-content: center;
  padding: 0 12px; flex-shrink: 0;
}

/* Quick complete button */
.rec-quick-complete {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; cursor: pointer;
  border: 2px solid var(--success-color); color: var(--success-color);
  background: transparent;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rec-quick-complete:hover {
  background: var(--success-color); color: white;
  transform: scale(1.15);
}
.rec-quick-complete:active { transform: scale(0.9); }

.rec-done-check { font-size: 20px; }

/* Timing badge */
.rec-timing-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
  background: var(--bg-primary); color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

/* Priority badges */
.rec-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
}
.rec-badge-high { background: #D1FAE5; color: #065F46; }
.rec-badge-medium { background: #FEF3C7; color: #92400E; }
.rec-badge-low { background: var(--bg-primary); color: var(--text-tertiary); }
[data-theme="dark"] .rec-badge-high { background: #064E3B; color: #A7F3D0; }
[data-theme="dark"] .rec-badge-medium { background: #78350F; color: #FDE68A; }

/* Confidence bar */
.rec-confidence-bar {
  width: 100%; height: 3px;
  background: var(--border-color);
  flex-basis: 100%; order: 10;
}
.rec-confidence-fill {
  height: 100%; border-radius: 0 0 0 var(--radius-md);
  transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Feedback row */
.rec-feedback {
  width: 100%; flex-basis: 100%; order: 11;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--border-color);
  font-size: 11px; color: var(--text-tertiary);
  animation: fadeIn 0.3s ease;
}
.rec-feedback.hidden { display: none !important; }
.rec-feedback-prompt { font-size: 11px; color: var(--text-tertiary); }
.rec-feedback-btn {
  font-size: 16px; cursor: pointer; border: none;
  background: transparent; padding: 2px 6px; border-radius: 4px;
  transition: background 0.15s, transform 0.15s;
}
.rec-feedback-btn:hover { background: var(--bg-primary); transform: scale(1.2); }

/* Summary footer */
.rec-summary {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px solid var(--border-color);
  font-size: 12px; color: var(--text-secondary); font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
  .rec-panel { margin: 0 12px 16px; padding: 16px; }
}

/* ── Onboarding Wizard ── */
.onboarding-container {
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  margin: 5vh auto;
  padding: 0; /* Let children handle padding for full-width components if needed */
  position: relative;
  overflow: hidden;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
}

.onboarding-header {
  padding: 32px 32px 0;
  text-align: center;
  margin-bottom: 24px;
  position: relative;
}

.onboarding-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 32px 20px;
  min-height: 200px;
}

.onboarding-body::-webkit-scrollbar {
  width: 4px;
}

/* Handled in container above */

.modal-close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 10px;
  line-height: 1;
  transition: color 0.2s;
  z-index: 10;
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.onboarding-header h2 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.onboarding-header p {
  color: var(--text-secondary);
  font-size: 15px;
}

.onboarding-progress {
  display: flex;
  gap: 8px;
  margin: 24px auto 0;
  max-width: 200px;
}

.progress-step {
  flex: 1;
  height: 4px;
  background: var(--border-color);
  border-radius: 4px;
  transition: all 0.3s ease;
}

.progress-step.active {
  background: var(--accent-primary);
}

.progress-step.completed {
  background: var(--success-color);
}

/* Body is now scrollable */

.onboarding-step {
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.question-label {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.question-description {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.goal-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.goal-card {
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.goal-card:hover {
  border-color: var(--accent-primary);
  background: var(--bg-elevated);
}

.goal-card.selected {
  border-color: var(--accent-primary);
  background: var(--accent-very-light);
  box-shadow: 0 0 0 1px var(--accent-primary);
}

.goal-icon {
  font-size: 24px;
  margin-bottom: 8px;
  display: block;
}

.goal-name {
  font-size: 14px;
  font-weight: 500;
  display: block;
}

.textarea-input {
  width: 100%;
  min-height: 150px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}

.hint-text {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 12px;
  line-height: 1.6;
}

.onboarding-actions {
  display: flex;
  justify-content: space-between;
  padding: 24px 32px 32px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  /* Added specific styling for onboarding buttons to ensure contrast */
  box-shadow: 0 -10px 20px -5px rgba(0,0,0,0.05);
  z-index: 10;
}

.onboarding-btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  font-weight: 600;
}

.onboarding-btn-secondary:hover {
  background: var(--border-color);
}

.plan-reasoning-box {
  background: var(--bg-elevated);
  padding: 20px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  border-left: 4px solid var(--accent-primary);
}

.plan-reasoning-box h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-primary);
  margin-bottom: 8px;
}

.plan-reasoning-box p {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
}

.phase-card {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
}

.phase-card:last-child {
  border-bottom: none;
}

.phase-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
}

.phase-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.phase-weeks {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.habit-preview-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
}

.habit-preview-icon {
  font-size: 18px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  border-radius: 50%;
}

.habit-preview-info {
  flex: 1;
}

.habit-preview-name {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.habit-preview-meta {
  font-size: 11px;
  color: var(--text-tertiary);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top: 3px solid var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 40px auto 16px;
}

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

#plan-generation-status {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ── Weekly Check-In ── */
.checkin-section {
  margin-bottom: 24px;
}

.checkin-h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.checkin-p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.checkin-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.checkin-stat-card {
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  text-align: center;
}

.checkin-stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.checkin-stat-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent-primary);
}

.adjustment-card {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  transition: all 0.2s ease;
}

.adjustment-card.applied {
  border-color: var(--success-color);
  background: var(--success-very-light);
}

.adjustment-icon {
  font-size: 20px;
  color: var(--accent-primary);
}

.adjustment-info {
  flex: 1;
}

.adjustment-habit {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.adjustment-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.adjustment-reason {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
  font-style: italic;
}

/* ── AI Metadata ── */
.card-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ai-badge-tiny {
  font-size: 9px;
  font-weight: 700;
  color: #8B5CF6; /* AI Purple */
  background: #F5F3FF;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid #DDD6FE;
  width: fit-content;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 2px;
}

[data-theme="dark"] .ai-badge-tiny {
  background: #2E1065;
  color: #DDD6FE;
  border-color: #4C1D95;
}

/* ── AI Coach Hub ── */
.ai-hub-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  height: calc(100vh - 120px);
  padding: 0 24px 24px;
}

.ai-dashboard-area {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: auto auto auto;
  gap: 20px;
  overflow-y: auto;
  padding-right: 8px;
}

.hub-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hub-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.hub-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.hub-card-icon {
  font-size: 20px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border-radius: 10px;
}

.hub-card h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Bento Spans */
.bento-journey { grid-column: span 2; }
.bento-insights { grid-column: span 1; }
.bento-lifestyle { grid-column: span 1; }
.bento-stats { grid-column: span 2; }

/* Widgets */
.hub-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 40px;
  text-align: center;
}

.hub-stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hub-stat-value {
  font-size: 32px;
  font-weight: 700;
  color: #8B5CF6; /* AI Purple */
}

.hub-stat-label {
  font-size: 13px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* AI Chat Sidebar */
.ai-chat-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  height: 100%; /* Fill container */
}

.chat-sidebar-header {
  padding: 16px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 14px;
}

.chat-input-hub {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  padding-right: 45px;
}

.ai-input-area {
  padding: 16px 20px 20px;
  position: relative;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
}

.chat-send-hub {
  position: absolute;
  right: 28px;
  top: calc(50% + 2px); /* Adjust for visually centering since it has extra top space usually */
  transform: translateY(-50%);
  background: #8B5CF6;
  color: white;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-weight: bold;
}

/* Shimmer Effect */
.loading-shimmer {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--border-color) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Responsive Hub */
@media (max-width: 1200px) {
  .ai-hub-grid {
    grid-template-columns: 1fr 300px;
  }
}

@media (max-width: 1024px) {
  .ai-hub-grid {
    grid-template-columns: 1fr;
    height: auto;
  }
  .ai-chat-sidebar {
    height: 500px;
  }
}



