/* HabitNow -- design system + app styles. Plain CSS, no build step. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-muted: #f0f2f8;
  --border: #e3e7f1;
  --text: #1c2233;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --primary: #5b8def;
  --primary-dark: #4472d6;
  --primary-tint: #eaf1ff;
  --success: #2fb380;
  --success-tint: #e6f7f0;
  --danger: #e0555f;
  --danger-tint: #fbe9ea;
  --warning: #e0a52f;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.04), 0 4px 16px rgba(20, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }

.icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.15em;
}

/* ---------------------------------------------------------------- shell */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand .brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #8f5bef);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.05rem;
}

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
}

.nav-link:hover { background: var(--surface-muted); color: var(--text); }

.nav-link.active {
  background: var(--primary-tint);
  color: var(--primary-dark);
}

.nav-link .icon { width: 18px; height: 18px; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.user-chip .user-name {
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip .user-email {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.logout-btn:hover { background: var(--surface-muted); color: var(--danger); }

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 64px;
  max-width: 960px;
}

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

/* ------------------------------------------------------------- page head */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ------------------------------------------------------------------ btn */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn .icon { width: 16px; height: 16px; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-muted); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #c8434d; }

.btn-ghost {
  background: none;
  color: var(--text-muted);
  border: none;
  padding: 8px 10px;
}
.btn-ghost:hover { background: var(--surface-muted); color: var(--text); }

.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* -------------------------------------------------------------- alerts */

.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
}

.alert-success { background: var(--success-tint); color: #1a7a54; }
.alert-error { background: var(--danger-tint); color: #a5323a; }

/* --------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.card-pad { padding: 20px; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .icon { width: 40px; height: 40px; margin-bottom: 12px; color: var(--text-faint); }
.empty-state p { margin-bottom: 16px; }

/* --------------------------------------------------------- date switch */

.date-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  margin-bottom: 20px;
}

.date-switch .date-label {
  flex: 1;
  text-align: center;
  font-weight: 600;
}

.date-switch .date-label small {
  display: block;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn .icon { width: 16px; height: 16px; }
.icon-flip { transform: rotate(180deg); }

/* -------------------------------------------------------------- progress */

.progress-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.progress-ring-wrap { position: relative; width: 56px; height: 56px; flex-shrink: 0; }

.progress-ring-wrap svg { transform: rotate(-90deg); }

.progress-ring-track { stroke: var(--surface-muted); }
.progress-ring-bar { stroke: var(--success); stroke-linecap: round; transition: stroke-dashoffset 0.3s; }

.progress-ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
}

.progress-summary-text .big { font-size: 1.05rem; font-weight: 700; }
.progress-summary-text .small { font-size: 0.82rem; color: var(--text-muted); }

/* --------------------------------------------------------- habit rows */

.section-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  font-weight: 700;
  margin: 24px 0 10px;
}

.section-label:first-child { margin-top: 0; }

.list { display: flex; flex-direction: column; gap: 10px; }

.item-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.check-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: transparent;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.check-btn .icon { width: 16px; height: 16px; }

.check-btn.checked {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.item-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.item-body { flex: 1; min-width: 0; }
.item-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-title.done { color: var(--text-faint); text-decoration: line-through; }

.item-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.item-meta .streak-flame { color: var(--warning); display: flex; align-items: center; gap: 3px; }
.item-meta .streak-flame .icon { width: 13px; height: 13px; }

.item-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.due-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  flex-shrink: 0;
}
.due-badge.overdue { background: var(--danger-tint); color: var(--danger); }

/* ------------------------------------------------------------ habit list */

.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filter-bar select {
  padding: 7px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); font: inherit; font-size: 0.82rem; color: var(--text);
}

.habit-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.habit-tab {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--surface);
}
.habit-tab.active { background: var(--text); color: #fff; border-color: var(--text); }

.stat-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.stat-pill.rate-high { background: var(--success-tint); color: #1a7a54; }
.stat-pill.rate-mid { background: #fff3d9; color: #8a6516; }
.stat-pill.rate-low { background: var(--danger-tint); color: #a5323a; }

/* ------------------------------------------------------------------ form */

.form-grid { display: flex; flex-direction: column; gap: 18px; max-width: 520px; }

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.field .hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 6px; }

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="date"],
.field input[type="time"],
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font: inherit;
  color: var(--text);
}

.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint);
}

.field textarea { resize: vertical; min-height: 70px; }

.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.color-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }

.weekday-picker { display: flex; gap: 6px; }
.weekday-toggle {
  flex: 1;
  text-align: center;
  padding: 8px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
}
.weekday-toggle input { display: none; }
.weekday-toggle.checked { background: var(--primary); border-color: var(--primary); color: #fff; }

.frequency-options { display: flex; flex-direction: column; gap: 10px; }
.frequency-option {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
}
.frequency-option.selected { border-color: var(--primary); background: var(--primary-tint); }
.frequency-option .opt-title { font-weight: 600; font-size: 0.88rem; display: flex; align-items: center; gap: 8px; }
.frequency-option .opt-body { margin-top: 10px; display: none; }
.frequency-option.selected .opt-body { display: block; }

.icon-emoji-input { display: flex; gap: 10px; align-items: center; }
.icon-preview {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: var(--surface-muted);
  flex-shrink: 0;
}
.icon-emoji-input input { flex: 1; }

.form-actions { display: flex; gap: 10px; justify-content: space-between; align-items: center; margin-top: 4px; }
.form-actions .left { display: flex; gap: 10px; }

.checklist-editor { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.checklist-editor-row { display: flex; gap: 8px; align-items: center; }
.checklist-editor-row input { flex: 1; }
.checklist-editor-row button {
  width: 32px; height: 32px; border-radius: 8px; border: none; background: var(--surface-muted);
  color: var(--text-muted); font-size: 1.1rem; line-height: 1; cursor: pointer; flex-shrink: 0;
}
.checklist-editor-row button:hover { background: var(--danger-tint); color: var(--danger); }

.checklist-view { display: flex; flex-direction: column; gap: 6px; }
.checklist-view-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.checklist-view-row .check-btn { width: 24px; height: 24px; }
.checklist-view-row .check-btn .icon { width: 12px; height: 12px; }
.checklist-view-row span.done { color: var(--text-faint); text-decoration: line-through; }

.category-badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 0.72rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
}
.category-badge .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

/* ---------------------------------------------------------------- auth */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card { width: 100%; max-width: 380px; }

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.auth-brand .brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #8f5bef);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.5rem;
}

.auth-brand h1 { font-size: 1.3rem; }
.auth-brand p { color: var(--text-muted); font-size: 0.85rem; }

.auth-switch { text-align: center; margin-top: 16px; font-size: 0.85rem; color: var(--text-muted); }
.auth-switch a { color: var(--primary); font-weight: 600; }

/* ------------------------------------------------------------- calendar */

.streak-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.streak-card { padding: 16px; text-align: center; }
.streak-card .value { font-size: 1.5rem; font-weight: 700; }
.streak-card .label { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.streak-card .value.flame { color: var(--warning); display: flex; align-items: center; justify-content: center; gap: 6px; }

.calendar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.calendar-header h3 { font-size: 1rem; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.calendar-dow {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-faint);
  font-weight: 700;
  padding-bottom: 4px;
}

.calendar-day {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  background: var(--surface-muted);
  color: var(--text-muted);
  position: relative;
}

.calendar-day.blank { background: none; }
.calendar-day.not-scheduled { background: none; color: var(--text-faint); }
.calendar-day.completed { background: var(--success); color: #fff; font-weight: 700; }
.calendar-day.missed { background: var(--danger-tint); color: var(--danger); }
.calendar-day.future { color: var(--text-faint); }
.calendar-day.today { box-shadow: inset 0 0 0 2px var(--primary); }

/* ------------------------------------------------------------------ misc */

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { display: none; }
  .topbar { display: flex; }
  .main { padding: 20px 16px 100px; max-width: none; }
  .streak-cards { grid-template-columns: repeat(3, 1fr); }
  .two-col { grid-template-columns: 1fr; }

  .mobile-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
    z-index: 10;
  }
  .mobile-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 0;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
  }
  .mobile-nav a.active { color: var(--primary); }
  .mobile-nav .icon { width: 20px; height: 20px; }
}

@media (min-width: 861px) {
  .mobile-nav { display: none; }
}
