/* ==========================================================================
   DAILY HABIT SYSTEM - DESIGN TOKENS & BASE STYLES
   ========================================================================== */

:root {
  /* Color Palette - HSL based */
  --hue-primary: 250;
  --hue-accent: 160;
  --hue-warning: 38;
  --hue-danger: 0;

  /* Light Theme Defaults */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-surface-subtle: #f1f5f9;
  --bg-surface-hover: #e2e8f0;
  
  --border-subtle: #e2e8f0;
  --border-medium: #cbd5e1;
  --border-focus: hsl(var(--hue-primary), 80%, 60%);

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --text-inverse: #ffffff;

  /* Brand Accents */
  --primary: hsl(250, 84%, 60%);
  --primary-hover: hsl(250, 84%, 54%);
  --primary-subtle: hsl(250, 84%, 96%);
  --primary-text: hsl(250, 84%, 45%);

  --success: hsl(158, 70%, 42%);
  --success-subtle: hsl(158, 70%, 94%);
  --success-hover: hsl(158, 70%, 36%);

  --warning: hsl(38, 92%, 50%);
  --warning-subtle: hsl(38, 92%, 95%);

  --danger: hsl(0, 72%, 51%);
  --danger-subtle: hsl(0, 84%, 96%);

  --streak-fire: #ff6b35;
  --streak-fire-subtle: #fff2ed;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-family-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --font-size-xs: 0.75rem;     /* 12px */
  --font-size-sm: 0.875rem;    /* 14px */
  --font-size-base: 1rem;      /* 16px */
  --font-size-lg: 1.125rem;    /* 18px */
  --font-size-xl: 1.25rem;     /* 20px */
  --font-size-2xl: 1.5rem;     /* 24px */
  --font-size-3xl: 1.875rem;   /* 30px */

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.04);

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 350ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Layout */
  --max-content-width: 1080px;
  --header-height: 64px;
  --nav-height-mobile: 60px;
}

/* Dark Theme Variables */
[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-surface: #111827;
  --bg-surface-elevated: #182235;
  --bg-surface-subtle: #1e293b;
  --bg-surface-hover: #26334d;

  --border-subtle: #1e293b;
  --border-medium: #334155;
  --border-focus: hsl(var(--hue-primary), 80%, 65%);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --text-inverse: #0f172a;

  --primary: hsl(250, 85%, 68%);
  --primary-hover: hsl(250, 85%, 74%);
  --primary-subtle: rgba(129, 140, 248, 0.15);
  --primary-text: hsl(250, 90%, 80%);

  --success: hsl(158, 65%, 48%);
  --success-subtle: rgba(16, 185, 129, 0.15);
  --success-hover: hsl(158, 65%, 55%);

  --warning: hsl(38, 92%, 58%);
  --warning-subtle: rgba(245, 158, 11, 0.15);

  --danger: hsl(0, 75%, 60%);
  --danger-subtle: rgba(239, 68, 68, 0.15);

  --streak-fire: #ff7d4d;
  --streak-fire-subtle: rgba(255, 107, 53, 0.15);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* CSS Reset & Baseline */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  overflow-x: hidden;
}

/* Typography Hierarchy */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-main);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

h1 { font-size: var(--font-size-2xl); }
h2 { font-size: var(--font-size-xl); }
h3 { font-size: var(--font-size-lg); }
h4 { font-size: var(--font-size-base); }

p {
  color: var(--text-muted);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  text-decoration: underline;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* App Container Layout */
.app-container {
  max-width: var(--max-content-width);
  width: 100%;
  margin: 0 auto;
  padding: 0 1rem 3rem 1rem;
  flex: 1;
}

/* Top App Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-app);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.header-inner {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.header-brand-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), hsl(280, 80%, 65%));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.brand-badge {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.12rem 0.4rem;
  border-radius: var(--radius-full);
  background: var(--primary-subtle);
  color: var(--primary-text);
  letter-spacing: 0.05em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

/* Navigation Tabs */
.main-nav {
  display: flex;
  align-items: center;
  background: var(--bg-surface-subtle);
  padding: 0.2rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.nav-tab:hover {
  color: var(--text-main);
}

.nav-tab.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
}

/* Icon Buttons & Controls */
.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: all var(--transition-fast);
  font-size: 0.95rem;
  flex-shrink: 0;
}

.btn-icon:hover {
  color: var(--text-main);
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

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

/* Primary Action Buttons */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  background: var(--primary);
  color: #ffffff;
  font-size: var(--font-size-sm);
  font-weight: 600;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: var(--font-size-sm);
  font-weight: 600;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

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

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  background: var(--danger);
  color: #ffffff;
  font-size: var(--font-size-sm);
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}
.btn-danger:hover {
  opacity: 0.9;
}

/* Sync Status Indicator */
.sync-indicator {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
  max-width: 140px;
}

.sync-indicator:hover {
  background: var(--bg-surface-hover);
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-subtle);
  flex-shrink: 0;
}

.sync-label-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-indicator.online .sync-dot {
  background: var(--success);
  box-shadow: 0 0 0 2px var(--success-subtle);
}

.sync-indicator.local .sync-dot {
  background: var(--warning);
}

.sync-indicator.syncing .sync-dot {
  background: var(--primary);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* Tab View Panels */
.tab-panel {
  display: none;
  animation: fadeIn var(--transition-normal);
  padding-top: 1rem;
}

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

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

/* Responsive Mobile Navigation & 2-Row Header */
@media (max-width: 680px) {
  .header-inner {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 1rem 0.45rem 1rem;
    gap: 0.4rem;
  }

  /* Row 1: Brand on left, User Sync Pill on right */
  .header-brand-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .brand-badge {
    display: none;
  }

  .sync-indicator {
    max-width: 160px;
    padding: 0.25rem 0.65rem;
    font-size: 0.72rem;
  }

  /* Row 2: Utility controls spanning cleanly */
  .header-actions {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding-top: 0.35rem;
    border-top: 1px solid var(--border-subtle);
  }

  .header-actions .btn-icon {
    flex: 1;
    height: 32px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
  }

  .app-header .main-nav {
    display: none;
  }

  .app-container {
    padding-bottom: calc(var(--nav-height-mobile) + env(safe-area-inset-bottom) + 1.25rem);
  }

  .bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height-mobile) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    z-index: 50;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    flex: 1;
    height: var(--nav-height-mobile);
    padding: 0.2rem 0;
    transition: color var(--transition-fast);
  }

  .bottom-nav-item.active {
    color: var(--primary);
  }

  .bottom-nav-item svg {
    width: 19px;
    height: 19px;
  }
}

.bottom-nav {
  display: none;
}
