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

:root {
  /* Brand */
  --color-primary:       #22c55e;
  --color-primary-light: #dcfce7;
  --color-primary-dark:  #16a34a;
  --color-accent:        #6366f1;
  --color-accent-light:  #eef2ff;

  /* Habit palette */
  --habit-green:       #22c55e;
  --habit-blue:        #3b82f6;
  --habit-indigo:      #6366f1;
  --habit-purple:      #a855f7;
  --habit-pink:        #ec4899;
  --habit-red:         #ef4444;
  --habit-yellow:      #eab308;
  --habit-orange:      #f97316;
  --habit-deep-orange: #ea580c;
  --habit-lime:        #84cc16;
  --habit-cyan:        #06b6d4;
  --habit-teal:        #14b8a6;
  --habit-gray:        #6b7280;
  --habit-black:       #1f1f1f;

  /* Backgrounds */
  --bg-app:      #f4f4f5;
  --bg-card:     #ffffff;
  --bg-input:    #f4f4f5;
  --bg-nav:      #ffffff;
  --bg-overlay:  rgba(0,0,0,0.4);

  /* Text */
  --text-primary:   #111827;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;
  --text-white:     #ffffff;

  /* Border */
  --border:         #e5e7eb;
  --border-focus:   var(--color-primary);

  /* Radius */
  --r-sm:   6px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   20px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-sm:     0 1px 2px rgba(0,0,0,0.06);
  --shadow-card:   0 1px 4px rgba(0,0,0,0.08);
  --shadow-nav:    0 -1px 0 rgba(0,0,0,0.06);
  --shadow-fab:    0 4px 16px rgba(0,0,0,0.18);
  --shadow-sidebar:2px 0 8px rgba(0,0,0,0.06);

  /* Sizing */
  --nav-h:        52px;
  --sidebar-w:    260px;
  --content-max-w: 100%;   /* mobile: full width */

  /* Safe areas */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Shared shell geometry */
  --app-top-bar-content-h: 54px;
  --app-top-bar-h: calc(var(--app-top-bar-content-h) + var(--safe-top));
  --app-rail-w: 0px;
  --app-top-bar-gutter: 20px;
  --app-top-bar-action-gutter: 12px;
  --brand-lockup-gap: 6px;
  --nav-clearance: calc(var(--nav-h) + var(--safe-bottom) + 30px);

  /* Transitions */
  --ease:     cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 180ms;
}

/* ===== Base ===== */
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

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

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
svg { display: block; flex-shrink: 0; }
.brand-logo {
  display: block;
  flex-shrink: 0;
  max-width: none;
  object-fit: contain;
  image-rendering: pixelated;
}

/* ===================================================
   MOBILE LAYOUT (default — < 768px)
   ================================================= */
#app {
  max-width: 100%;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  background: var(--bg-app);
  overflow-x: clip;
}

#main-content {
  width: 100%;
  padding-top: var(--app-top-bar-h);
}

/* Views */
.view {
  min-height: 100dvh;
  padding-bottom: var(--nav-clearance);
  animation: fadeIn var(--duration) var(--ease);
}

.view--no-nav { padding-bottom: 0; }

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

/* Bottom Nav (mobile) */
.bottom-nav {
  position: fixed;
  bottom: calc(6px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 20px);
  max-width: 410px;
  height: var(--nav-h);
  padding: 4px;
  background: linear-gradient(180deg, rgba(255,255,255,0.74), rgba(245,247,249,0.52));
  border: 1px solid rgba(255,255,255,0.9);
  border-radius: 22px;
  box-shadow:
    0 14px 34px rgba(15,23,42,0.14),
    0 3px 9px rgba(15,23,42,0.07),
    inset 0 1px 0 rgba(255,255,255,0.92),
    inset 0 -1px 0 rgba(15,23,42,0.05);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  isolation: isolate;
  z-index: 100;
  animation: navRise 360ms cubic-bezier(0.22, 1, 0.36, 1);
}

.bottom-nav::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at 18% 0%, rgba(255,255,255,0.8), transparent 38%),
    linear-gradient(105deg, rgba(255,255,255,0.28), transparent 46%);
  pointer-events: none;
  z-index: -1;
}

.bottom-nav::after {
  content: '';
  position: absolute;
  top: 1px;
  right: 18px;
  left: 18px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.96), transparent);
  pointer-events: none;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 3px 8px;
  color: #626873;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: -0.01em;
  border-radius: 18px;
  transition:
    color 220ms var(--ease),
    transform 160ms var(--ease);
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  isolation: isolate;
  z-index: 1;
}
.nav-item.active {
  color: var(--color-primary-dark);
  font-weight: 700;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.82), rgba(220,252,231,0.68));
  border: 1px solid rgba(255,255,255,0.88);
  border-radius: 18px;
  box-shadow:
    0 4px 12px rgba(22,163,74,0.10),
    inset 0 1px 0 rgba(255,255,255,0.95),
    inset 0 -1px 0 rgba(22,163,74,0.08);
  z-index: -1;
  animation: activeGlassIn 240ms cubic-bezier(0.22, 1, 0.36, 1);
}
.nav-item svg {
  width: 19px;
  height: 19px;
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}
.nav-item.active svg {
  transform: translateY(-1px) scale(1.06);
  filter: drop-shadow(0 2px 3px rgba(22,163,74,0.18));
}
.nav-item:active { transform: scale(0.94); }
.nav-social-badge {
  position: absolute; top: 2px; right: 15%; min-width: 15px; height: 15px; padding: 0 4px;
  display: grid; place-items: center; border-radius: 99px; background: #ef4444; color: white;
  font-size: 8px; font-weight: 850; line-height: 1; box-shadow: 0 0 0 2px rgba(255,255,255,.9);
}
.nav-social-badge[hidden] { display: none; }

@keyframes navRise {
  from { opacity: 0; transform: translate(-50%, 12px) scale(0.98); }
  to   { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

@keyframes activeGlassIn {
  from { opacity: 0; transform: scale(0.88); }
  to   { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .bottom-nav,
  .nav-item.active::before { animation: none; }
  .nav-item,
  .nav-item svg { transition: none; }
}

/* Sidebar (desktop — hidden on mobile) */
.sidebar { display: none; }

/* FAB */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 28px);
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: var(--r-full);
  background: var(--color-accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-fab);
  z-index: 50;
  transition: transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
  border: none;
  cursor: pointer;
}
.fab:hover  { transform: scale(1.05); }
.fab:active { transform: scale(0.94); }
.fab svg { width: 24px; height: 24px; }

/* Loader */
.loader-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--bg-app);
}
.loader-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* Colors */
.color-swatch {
  display: inline-block;
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color var(--duration), transform var(--duration);
}
.color-swatch.selected { border-color: var(--text-primary); transform: scale(1.1); }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

* { -webkit-tap-highlight-color: transparent; }


/* ===================================================
   TABLET LAYOUT (768px – 1023px)
   Sidebar collapsed (icon only, 72px)
   ================================================= */
@media (min-width: 768px) {

  :root {
    --content-max-w: 800px;
    --app-top-bar-content-h: 64px;
    --app-rail-w: 72px;
    --app-top-bar-gutter: 22px;
  }

  body { overflow: hidden; } /* #main-content scrolls, not body */

  #app {
    max-width: 100%;
    margin: 0;
    overflow: hidden;
    display: flex;
    align-items: stretch;
    height: 100dvh;
  }

  /* Hide mobile nav */
  .bottom-nav { display: none !important; }

  /* Sidebar — collapsed */
  .sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    width: var(--app-rail-w);
    height: 100dvh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-sidebar);
    z-index: 240;
    overflow: hidden;
    transition: width 0.22s var(--ease);
  }

  .sidebar:hover { width: var(--sidebar-w); }

  .sidebar__logo {
    display: flex;
    align-items: center;
    gap: var(--brand-lockup-gap);
    padding: var(--safe-top) 20px 0;
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    height: var(--app-top-bar-h);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
    font-family: inherit;
  }
  .sidebar__logo .brand-logo { width: 28px; height: 28px; }
  .sidebar__logo-text { opacity: 0; transition: opacity 0.15s; }
  .sidebar:hover .sidebar__logo-text { opacity: 1; }

  .sidebar__nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px 6px;
    gap: 2px;
    overflow: hidden;
  }

  .sidebar__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--r-md);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--duration), color var(--duration);
    white-space: nowrap;
    overflow: hidden;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    position: relative;
  }
  .sidebar__item svg { width: 20px; height: 20px; flex-shrink: 0; }
  .sidebar__item:hover { background: var(--bg-input); color: var(--text-primary); }
  .sidebar__item:active { background: var(--border); }
  .sidebar__item.active {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    font-weight: 700;
  }
  .sidebar__item.active:hover { background: #cef5da; }
  .sidebar__item-label { opacity: 0; transition: opacity 0.15s; }
  .sidebar__item .nav-social-badge { top: 50%; right: 8px; transform: translateY(-50%); box-shadow: 0 0 0 2px white; }
  .sidebar:hover .sidebar__item-label { opacity: 1; }

  .sidebar__new-btn {
    margin: 8px 6px;
    padding: 10px 14px;
    border-radius: var(--r-md);
    background: var(--color-accent);
    color: white;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    border: none;
    white-space: nowrap;
    overflow: hidden;
    flex-shrink: 0;
    transition: opacity var(--duration);
  }
  .sidebar__new-btn:hover { opacity: 0.88; }
  .sidebar__new-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
  .sidebar__new-btn-label { opacity: 0; transition: opacity 0.15s; }
  .sidebar:hover .sidebar__new-btn-label { opacity: 1; }

  .sidebar__footer {
    padding: 12px 6px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }
  .sidebar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--r-md);
    overflow: hidden;
    cursor: pointer;
    white-space: nowrap;
  }
  .sidebar__user:hover { background: var(--bg-input); }
  .sidebar__avatar {
    width: 32px; height: 32px;
    border-radius: var(--r-full);
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
  }
  .sidebar__user-info { opacity: 0; transition: opacity 0.15s; }
  .sidebar:hover .sidebar__user-info { opacity: 1; }
  .sidebar__username { font-size: 13px; font-weight: 600; }
  .sidebar__user-email { font-size: 11px; color: var(--text-muted); }

  /* Main content */
  #main-content {
    flex: 1;
    margin-left: var(--app-rail-w);
    height: 100dvh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.22s var(--ease);
  }

  /* View container fills main content and centers children */
  #view-container {
    width: 100%;
    flex: 1;
  }

  /* Views on tablet/desktop */
  .view {
    padding-bottom: 40px;
    min-height: 100%; /* fills #main-content height */
  }
  .view--no-nav { padding-bottom: 0; }

  /* FAB: keep on tablet, reposition */
  .fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
  }

}


/* ===================================================
   DESKTOP LAYOUT (≥ 1024px)
   Full sidebar (260px), wider content
   ================================================= */
@media (min-width: 1024px) {

  :root {
    --content-max-w: 900px;
    --app-rail-w: var(--sidebar-w);
    --app-top-bar-gutter: 28px;
  }
  .sidebar:hover { width: var(--sidebar-w); } /* no hover expand needed */

  .sidebar__logo-text  { opacity: 1; }
  .sidebar__item-label { opacity: 1; }
  .sidebar__new-btn-label { opacity: 1; }
  .sidebar__user-info  { opacity: 1; }

  /* No FAB — the sidebar has the New Habit button */
  .fab { display: none !important; }

}

/* ===================================================
   WIDE DESKTOP (≥ 1280px)
   Two-column home layout
   ================================================= */
@media (min-width: 1280px) {
  :root { --content-max-w: 1060px; }

  /* Two-column layout for habits list */
  .habits-grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .habits-grid-2col .habit-card { margin-bottom: 0; }
}

/* ===================================================
   ULTRA-WIDE (≥ 1600px)
   ================================================= */
@media (min-width: 1600px) {
  :root { --content-max-w: 1140px; }
}
