/* ========================================
   🎨 Habit Tracker — Style System (LTR)
   ======================================== */

/* ─── CSS Variables ─── */
:root {
  --bg-primary: #0b0d13;
  --bg-secondary: #13151d;
  --bg-card: #181b25;
  --bg-card-hover: #1f2231;
  --bg-input: #1f2231;
  --border: #262938;
  --border-focus: #6c63ff;

  --text-primary: #eaeaf0;
  --text-secondary: #8b8fa4;
  --text-muted: #5c6078;

  --accent: #6c63ff;
  --accent-light: #8b83ff;
  --accent-glow: rgba(108, 99, 255, 0.25);
  --success: #34d399;
  --success-glow: rgba(52, 211, 153, 0.2);
  --danger: #f87171;
  --danger-glow: rgba(248, 113, 113, 0.2);
  --warning: #fbbf24;
  --streak: #f59e0b;
  --streak-glow: rgba(245, 158, 11, 0.2);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.45);
  --shadow-accent: 0 4px 20px var(--accent-glow);
}

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

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

body {
  font-family: 'Inter', 'Segoe UI', 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

input,
button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}

button {
  cursor: pointer;
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ========================================
   🧭 Header
   ======================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 13, 19, 0.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
}

.header-content {
  max-width: 1060px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  gap: 1rem;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.logo-icon {
  font-size: 1.35rem;
}

.date-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
  white-space: nowrap;
  border: 1px solid var(--border);
}

/* ─── Tabs ─── */
.tab-nav {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.tab-btn {
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: var(--transition);
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-accent);
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* ========================================
   📄 Main
   ======================================== */
.app-main {
  max-width: 1060px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ========================================
   📱 Mobile Swipe Tabs (page-to-page)
   ======================================== */
.tabs-viewport {
  width: 100%;
}

.tabs-track {
  width: 100%;
}

.tab-content {
  display: none;
  animation: fadeUp 0.3s ease;
}

.tab-content.active {
  display: block;
}

@media (max-width: 900px) {
  /* App-shell layout: header + viewport fill exactly one screen */
  body {
    height: 100dvh;
    height: 100vh; /* fallback */
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .app-header {
    flex-shrink: 0;
  }

  .app-main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0 !important;
    margin: 0;
    max-width: 100%;
  }

  .tabs-viewport {
    overflow: hidden;
    height: 100%;
    touch-action: pan-y;
  }

  .tabs-track {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    height: 100%;
    will-change: transform;
    transition: transform 260ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  .tabs-track.dragging {
    transition: none;
  }

  /* Each page fills the viewport and scrolls independently */
  .tab-content {
    display: block !important;
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    animation: none;
    padding: 1rem;
    box-sizing: border-box;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   📊 Stats Cards
   ======================================== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: rgba(255, 255, 255, 0.06);
}

.stat-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.stat-body {
  min-width: 0;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

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

.stat-card.success .stat-value {
  color: var(--success);
}

.stat-card.streak .stat-value {
  color: var(--streak);
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

/* ========================================
   ➕ Add Habit
   ======================================== */
.add-habit-bar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

.add-habit-bar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  transition: var(--transition);
}

.add-habit-bar input::placeholder {
  color: var(--text-muted);
}

.add-habit-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-add {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent);
  color: #fff;
  padding: 0.7rem 1.15rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-add:hover {
  background: var(--accent-light);
  box-shadow: var(--shadow-accent);
  transform: translateY(-1px);
}

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

/* ========================================
   ✅ Habits List
   ======================================== */
.habits-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.habit-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  transition: var(--transition);
  animation: slideIn 0.25s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.habit-item:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.06);
}

.habit-item.done {
  border-color: rgba(52, 211, 153, 0.25);
}

/* Custom Checkbox */
.habit-check {
  position: relative;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.habit-check input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 2;
}

.habit-check .checkmark {
  position: absolute;
  inset: 0;
  border: 2px solid var(--border);
  border-radius: 7px;
  background: var(--bg-input);
  transition: var(--transition-bounce);
  display: flex;
  align-items: center;
  justify-content: center;
}

.habit-check .checkmark svg {
  opacity: 0;
  transform: scale(0);
  transition: var(--transition-bounce);
  color: #fff;
}

.habit-check input:checked+.checkmark {
  background: var(--success);
  border-color: var(--success);
  box-shadow: 0 0 12px var(--success-glow);
}

.habit-check input:checked+.checkmark svg {
  opacity: 1;
  transform: scale(1);
}

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

.habit-name {
  font-size: 0.92rem;
  font-weight: 500;
}

.habit-item.done .habit-name {
  color: var(--success);
}

.habit-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.75rem;
  margin-top: 0.1rem;
}

.habit-streak {
  color: var(--streak);
  font-weight: 600;
}

.habit-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: var(--transition);
}

.habit-item:hover .habit-actions {
  opacity: 1;
}

.habit-actions button {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: var(--transition);
}

.habit-actions .btn-edit:hover {
  background: var(--accent-glow);
  color: var(--accent-light);
}

.habit-actions .btn-delete:hover {
  background: var(--danger-glow);
  color: var(--danger);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.6rem;
}

.empty-state p {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.2rem;
}

.empty-state span {
  font-size: 0.82rem;
}

/* ========================================
   📊 Dashboard
   ======================================== */

/* Summary Row */
.dash-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.dash-summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  transition: var(--transition);
}

.dash-summary-card:hover {
  border-color: rgba(255, 255, 255, 0.06);
  transform: translateY(-1px);
}

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

.dash-summary-icon.blue {
  background: rgba(108, 99, 255, 0.12);
  color: #8b83ff;
}

.dash-summary-icon.green {
  background: rgba(52, 211, 153, 0.12);
  color: #34d399;
}

.dash-summary-icon.amber {
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
}

.dash-summary-value {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.dash-summary-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

/* Charts Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto auto;
  gap: 0.75rem;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding-top: 1.25rem;
  padding-bottom: 1.25rem;
  transition: var(--transition);
}

.chart-card:hover {
  border-color: rgba(255, 255, 255, 0.06);
}

.chart-card h3 {
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 0.85rem;
  margin-left: 0.85rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.chart-card h3 small {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-left: 0.35rem;
}

/* Ring Card */
.ring-card {
  grid-row: 1 / 2;
  grid-column: 1 / 2;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ring-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.ring-container {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

#ring-chart {
  display: block;
  margin: 0 auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px !important;
  height: 200px !important;
}

.ring-value {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--accent-light);
  letter-spacing: -0.03em;
}

.ring-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ring-detail {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 1rem;
  font-weight: 500;
}

/* Line Card */
.line-card {
  grid-row: 1 / 2;
  grid-column: 2 / 3;
}

/* Bar Card */
.bar-card {
  grid-row: 2 / 3;
  grid-column: 1 / -1;
}

.chart-wrapper {
  position: relative;
  width: 100%;
}

.line-card .chart-wrapper {
  height: 220px;
}

.bar-wrapper {
  height: 260px;
}

/* ========================================
   📅 Calendar
   ======================================== */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

.calendar-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  min-width: 160px;
  text-align: center;
}

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

.day-header {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.4rem 0;
  text-transform: uppercase;
}

.day-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition);
  cursor: default;
}

.day-cell.today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  color: var(--text-primary);
  font-weight: 700;
}

.day-cell.full {
  background: var(--success);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 8px var(--success-glow);
}

.day-cell.partial {
  background: rgba(108, 99, 255, 0.25);
  color: var(--accent-light);
}

.day-cell.none {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
}

.day-cell.empty {
  background: none;
}

.calendar-legend {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 1.15rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

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

.legend-dot.partial {
  background: rgba(108, 99, 255, 0.45);
}

.legend-dot.none {
  background: rgba(248, 113, 113, 0.3);
}

/* ========================================
   🗂 Modals
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  min-width: 320px;
  max-width: 400px;
  width: 90%;
  animation: scaleIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.modal p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-bottom: 1.15rem;
}

.modal input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  font-size: 0.92rem;
  margin-bottom: 1.15rem;
  transition: var(--transition);
}

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

.modal-actions {
  display: flex;
  gap: 0.4rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--accent-light);
}

.btn-secondary {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  transition: var(--transition);
}

.btn-danger:hover {
  opacity: 0.85;
}

.btn-ghost {
  color: var(--text-secondary);
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.85rem;
  transition: var(--transition);
}

.btn-ghost:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Install Modal Special */
.install-modal {
  text-align: center;
  padding: 2rem 1.5rem;
}

.install-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.install-icon {
  font-size: 3rem;
}

.install-modal h3 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent-light);
  margin-bottom: 0.25rem;
}

.install-modal p {
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.install-modal .modal-actions {
  justify-content: center;
}

/* ========================================
   🍞 Toast
   ======================================== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--success);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.35rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 2000;
  box-shadow: 0 8px 30px rgba(52, 211, 153, 0.18);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-weight: 500;
  font-size: 0.9rem;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.hidden {
  display: none;
}

.toast-icon {
  font-size: 1.2rem;
}

/* Celebration */
@keyframes celebrate {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.12);
  }

  100% {
    transform: scale(1);
  }
}

.habit-item.celebrate {
  animation: celebrate 0.4s ease;
}

.habit-item.celebrate .checkmark {
  animation: celebrate 0.5s ease;
}

/* ========================================
   📱 Responsive
   ======================================== */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    height: auto;
    padding: 0.6rem 0;
    gap: 0.6rem;
  }

  .header-left,
  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .tab-nav {
    flex: 1;
  }

  .tab-btn {
    flex: 1;
    text-align: center;
    font-size: 0.78rem;
    padding: 0.3rem 0.4rem;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .dash-summary {
    grid-template-columns: 1fr;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .ring-card {
    grid-row: auto;
    grid-column: auto;
  }

  .line-card {
    grid-row: auto;
    grid-column: auto;
  }

  .bar-card {
    grid-row: auto;
    grid-column: auto;
  }

  .ring-container {
    width: 170px;
    height: 170px;
  }

  .ring-value {
    font-size: 1.85rem;
  }

  .habit-actions {
    opacity: 1;
  }

  .app-main {
    padding: 1rem;
  }

  .calendar-grid {
    gap: 3px;
  }
}

@media (max-width: 480px) {
  .logo {
    font-size: 1rem;
  }

  .date-badge {
    font-size: 0.68rem;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .add-habit-bar {
    flex-direction: column;
  }

  .btn-add {
    justify-content: center;
  }

  .calendar-legend {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
}