/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0: #0d0f14;
  --bg-1: #141720;
  --bg-2: #1c2030;
  --bg-3: #252a3a;
  --border: #2e3348;
  --text-0: #e8eaf0;
  --text-1: #9da3b8;
  --text-2: #606680;
  --accent: #6c63ff;
  --accent-dim: #4f49cc;
  --accent-glow: rgba(108, 99, 255, 0.18);
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.15);
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

html { font-size: 16px; scroll-behavior: smooth; }

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

/* ===== Typography ===== */
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 700; letter-spacing: -0.5px; }
h2 { font-size: clamp(1.2rem, 3vw, 1.5rem); font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p  { color: var(--text-1); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ===== Layout ===== */
.container {
  width: min(860px, 92vw);
  margin: 0 auto;
  padding: 2.5rem 0;
}

.container-wide {
  width: min(1200px, 96vw);
  margin: 0 auto;
  padding: 2rem 0;
}

/* ===== Navbar ===== */
.navbar {
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 5%;
  gap: 1rem;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-0);
  text-decoration: none;
}

.nav-brand .brand-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  font-size: 1rem;
}

.nav-actions { display: flex; gap: 0.5rem; align-items: center; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dim); }

.btn-ghost {
  background: transparent;
  color: var(--text-1);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text-0); }

.btn-danger {
  background: rgba(239,68,68,0.1);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.35);
}
.btn-danger:hover { background: rgba(239,68,68,0.2); border-color: var(--danger); }

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-1);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}
.btn-back:hover { color: var(--text-0); }

.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.8rem; font-size: 1rem; }
.btn-icon {
  width: 34px; height: 34px; padding: 0;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--text-1);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 1rem;
}
.btn-icon:hover { background: var(--border); color: var(--text-0); }

/* ===== Cards ===== */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.card-sm { padding: 1rem; border-radius: var(--radius-md); }

/* ===== Form Elements ===== */
.form-group { display: flex; flex-direction: column; gap: 0.5rem; }

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-1);
}

.form-input,
.form-select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  font-family: var(--font);
  transition: border-color 0.15s;
  width: 100%;
}

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

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

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7);
  cursor: pointer;
}

/* ===== Challenge Type Selector ===== */
.challenge-types {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.challenge-type-card {
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg-2);
  user-select: none;
}

.challenge-type-card:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.challenge-type-card.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 0 1px var(--accent);
}

.challenge-type-card .ct-days {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.challenge-type-card .ct-label {
  font-size: 0.75rem;
  color: var(--text-1);
  margin-top: 0.2rem;
}

/* ===== Todo List ===== */
.todo-list { display: flex; flex-direction: column; gap: 0.5rem; }

.todo-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  transition: border-color 0.15s;
}

.todo-item:hover { border-color: var(--border); }

.todo-item input[type="text"] {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-0);
  font-size: 0.875rem;
  font-family: var(--font);
  outline: none;
  padding: 0;
}

.todo-item input[type="text"]::placeholder { color: var(--text-2); }

.todo-add-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

/* ===== Calendar / Progress Grid ===== */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.5rem;
}

.day-cell {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg-2);
  position: relative;
  min-height: 68px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

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

.day-cell.today { border-color: var(--accent); }

.day-cell.future {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.day-cell.all-done {
  background: var(--success-dim);
  border-color: var(--success);
}

.day-num {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-1);
  line-height: 1;
}

.day-date-label {
  font-size: 0.65rem;
  color: var(--text-2);
}

.day-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: auto;
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.1s;
}

.dot.done { background: var(--success); }

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
  color: var(--warn);
  font-weight: 600;
}

/* ===== Stats Row ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.stat-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-0);
  line-height: 1;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-1);
}

/* ===== Progress bar ===== */
.progress-bar-wrap {
  background: var(--bg-3);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
  width: 100%;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width 0.4s ease;
}

/* ===== Day Detail Panel ===== */
.day-panel {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: min(380px, 100vw);
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 40px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.day-panel.open { transform: translateX(0); }

.day-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.day-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ===== Todo check items in panel ===== */
.todo-check-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.todo-check-item:hover { border-color: var(--accent); }

.todo-check-item.done {
  border-color: var(--success);
  background: var(--success-dim);
}

.check-box {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid; place-items: center;
  flex-shrink: 0;
  font-size: 0.7rem;
  transition: all 0.15s;
}

.todo-check-item.done .check-box {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.todo-check-item .todo-text {
  font-size: 0.875rem;
  color: var(--text-0);
  flex: 1;
}

.todo-check-item.done .todo-text {
  text-decoration: line-through;
  color: var(--text-2);
}

/* ===== Overlay ===== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 150;
  display: none;
}
.overlay.show { display: block; }

/* ===== Challenges list on home ===== */
.challenges-list { display: flex; flex-direction: column; gap: 0.75rem; }

.challenge-row {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  transition: border-color 0.15s;
  text-decoration: none;
  color: var(--text-0);
}

.challenge-row:hover { border-color: var(--accent); }

.challenge-row-info { flex: 1; min-width: 0; }

.challenge-row-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.challenge-row-meta {
  font-size: 0.78rem;
  color: var(--text-2);
  margin-top: 0.15rem;
}

.challenge-badge {
  padding: 0.25rem 0.6rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--accent-glow);
  color: var(--accent);
  flex-shrink: 0;
}

/* ===== Modals ===== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 300;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 1.5rem 1rem;
}

.modal {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: min(500px, 96vw);
  flex-shrink: 0;
  margin: auto;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

/* ===== Empty state ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 3rem 2rem;
  text-align: center;
}

.empty-icon { font-size: 3rem; opacity: 0.5; }

/* ===== Divider ===== */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--text-0);
  box-shadow: var(--shadow);
  animation: slideInToast 0.2s ease;
  max-width: 300px;
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger);  }

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .card { padding: 1rem; }
  .navbar-inner { padding: 0.7rem 4%; }
}

@media (max-width: 600px) {
  .stats-row          { grid-template-columns: repeat(2, 1fr); }
  .challenge-types    { grid-template-columns: repeat(2, 1fr); }
  .day-cell           { min-height: 50px; padding: 0.3rem 0.25rem; }
  .day-num            { font-size: 0.62rem; }
  .day-date-label     { font-size: 0.55rem; }
  .dot                { width: 6px; height: 6px; }
  .navbar-inner       { padding: 0.65rem 3%; gap: 0.5rem; }
  .btn-sm             { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
}

@media (max-width: 480px) {
  .day-cell           { min-height: 44px; padding: 0.25rem; }
  .card               { padding: 0.75rem; border-radius: var(--radius-md); }
  .modal              { padding: 1rem; }
  .day-panel          { width: 100vw; }
}

/* ===== Screen-reader only ===== */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ===== Utility ===== */
.flex   { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1  { gap: 0.5rem; }
.gap-2  { gap: 1rem; }
.mt-1   { margin-top: 0.5rem; }
.mt-2   { margin-top: 1rem; }
.mt-3   { margin-top: 1.5rem; }
.mb-1   { margin-bottom: 0.5rem; }
.mb-2   { margin-bottom: 1rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.78rem; }
.text-muted { color: var(--text-1); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-right { text-align: right; }
.w-full { width: 100%; }
.hidden { display: none !important; }
