/* ── Accountability — Orbi-inspired dark theme ────────────────
   Dark navy background, purple accents, rounded cards,
   clean modern typography, mobile-first.
   ──────────────────────────────────────────────────────────── */

:root {
  /* Background */
  --bg-primary: #0a0a1a;
  --bg-secondary: #111128;
  --bg-card: #181838;
  --bg-card-hover: #1f1f48;
  --bg-input: #1a1a3a;

  /* Text */
  --text-primary: #f0f0ff;
  --text-secondary: #a0a0c0;
  --text-muted: #6b6b8d;

  /* Accent — purple */
  --accent: #7C5CFC;
  --accent-light: #9b7fff;
  --accent-glow: rgba(124, 92, 252, 0.25);

  /* Success / Danger */
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;

  /* Borders */
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);

  /* Radius & spacing */
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Shadow */
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);

  /* Font */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  line-height: 1.6;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ──────────────────────────────────────────────── */

.app-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 100px;
}

/* ── Header ──────────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-badge {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 6px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 0 20px var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
}
.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* ── Dashboard Stats ─────────────────────────────────────── */

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all 0.2s;
}
.stat-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-value.accent { color: var(--accent-light); }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }

/* ── Section Headers ─────────────────────────────────────── */

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

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ── Habit Cards ─────────────────────────────────────────── */

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

.habit-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all 0.25s;
  cursor: pointer;
}
.habit-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.habit-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.habit-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.habit-name {
  font-size: 0.95rem;
  font-weight: 600;
}

.habit-streak {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--warning);
}

.habit-meta {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.habit-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Mini Calendar (last 30 days) ────────────────────────── */

.mini-calendar {
  display: flex;
  gap: 2px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.cal-day {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--bg-input);
  transition: all 0.15s;
}

.cal-day.completed {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

.cal-day.today {
  border: 1.5px solid var(--accent-light);
}

/* ── Check-in Button ─────────────────────────────────────── */

.checkin-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  transition: all 0.25s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.checkin-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
}

.checkin-btn.checked {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 20px var(--accent-glow);
}

/* ── Modal ───────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 640px;
  padding: 24px 20px 32px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 90dvh;
  overflow-y: auto;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  margin: 0 auto 20px;
}

.modal h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
}

/* ── Forms ───────────────────────────────────────────────── */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: border-color 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder {
  color: var(--text-muted);
}

select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236b6b8d' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.icon-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-option {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.icon-option:hover, .icon-option.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.color-picker {
  display: flex;
  gap: 8px;
}

.color-option {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.color-option:hover, .color-option.selected {
  border-color: white;
  transform: scale(1.15);
}

/* ── Detail View ─────────────────────────────────────────── */

.detail-view {
  display: none;
}

.detail-view.active {
  display: block;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.detail-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

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

/* ── Calendar Grid (full month) ──────────────────────────── */

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

.calendar-grid .day-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 0;
}

.calendar-grid .day-cell {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
}

.calendar-grid .day-cell:hover {
  border-color: var(--accent);
}

.calendar-grid .day-cell.completed {
  background: var(--accent);
  color: white;
  box-shadow: 0 0 8px var(--accent-glow);
}

.calendar-grid .day-cell.today {
  border: 1.5px solid var(--accent-light);
}

.calendar-grid .day-cell.other-month {
  opacity: 0.3;
}

/* ── Money Saved Banner ──────────────────────────────────── */

.money-banner {
  background: linear-gradient(135deg, #0d4d2e, #0a3d24);
  border: 1px solid rgba(52, 211, 153, 0.2);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.money-banner .money-icon {
  font-size: 1.5rem;
}

.money-banner .money-amount {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--success);
}

.money-banner .money-label {
  font-size: 0.8rem;
  color: rgba(52, 211, 153, 0.7);
}

/* ── Landing (unauthenticated) ───────────────────────────── */

.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80dvh;
  text-align: center;
  padding: 40px 20px;
}

.landing h1 {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.landing p {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 400px;
  margin-bottom: 32px;
}

.landing .btn-primary {
  font-size: 1rem;
  padding: 14px 32px;
  border-radius: var(--radius-full);
}

.feature-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 48px;
  width: 100%;
  max-width: 400px;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: left;
}

.feature-card .feature-icon {
  font-size: 1.5rem;
  margin-bottom: 10px;
}

.feature-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.feature-card p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0;
}

/* ── Toast ───────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.85rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  animation: slideDown 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-10px); }
}

/* ── Loading ─────────────────────────────────────────────── */

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}

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

/* ── Empty State ─────────────────────────────────────────── */

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

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 0.85rem;
}

/* ── Back Button ─────────────────────────────────────────── */

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 0;
  font-family: var(--font);
  margin-bottom: 16px;
}

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

/* ── Weight Tracking ─────────────────────────────────────── */

.weight-section {
  margin-bottom: 24px;
}

.weight-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.weight-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.weight-header h3 {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.weight-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.weight-stat {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}

.weight-stat .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.weight-stat .value {
  font-size: 1.1rem;
  font-weight: 700;
}

.weight-stat .value.loss { color: var(--success); }
.weight-stat .value.gain { color: var(--danger); }
.weight-stat .value.neutral { color: var(--text-secondary); }

.weight-progress-bar {
  background: var(--bg-secondary);
  border-radius: var(--radius-full);
  height: 8px;
  margin: 12px 0 8px;
  overflow: hidden;
}

.weight-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: var(--radius-full);
  transition: width 0.5s ease;
}

.week-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.weight-chart {
  position: relative;
  height: 180px;
  margin: 16px 0 8px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding-bottom: 24px;
}

.weight-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.weight-bar {
  width: 100%;
  max-width: 32px;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
  transition: height 0.3s ease;
  cursor: pointer;
  position: relative;
  min-height: 4px;
}

.weight-bar:hover { opacity: 0.8; }

.weight-bar-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.weight-bar-value {
  font-size: 0.65rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.weight-entry-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.weight-entry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.weight-entry-row .date {
  color: var(--text-secondary);
}

.weight-entry-row .weight {
  font-weight: 600;
}

.weight-entry-row .change {
  font-size: 0.75rem;
}

.weight-entry-row .delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.weight-entry-row .delete-btn:hover {
  color: var(--danger);
  background: rgba(248, 113, 113, 0.1);
}

/* ── Tab Navigation ──────────────────────────────────────── */

.tab-bar {
  display: flex;
  gap: 0;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  color: var(--text-primary);
  background: var(--bg-card);
  box-shadow: var(--shadow);
}

.tab-btn:hover:not(.active) {
  color: var(--text-secondary);
}

/* ── Responsive ──────────────────────────────────────────── */

@media (min-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .detail-stats {
    grid-template-columns: repeat(4, 1fr);
  }
  .weight-summary {
    grid-template-columns: repeat(4, 1fr);
  }
}
