/* Theme custom properties for System Preference Dark/Light mode */
:root {
  --bg-app: #f1f5f9;
  --card-bg: rgba(255, 255, 255, 0.85);
  --card-hover: #e2e8f0;
  --border-grey: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --input-bg: #ffffff;
  --dialog-backdrop: rgba(220, 225, 235, 0.8);
  --dialog-bg: #ffffff;
  --stroke-track: #cbd5e1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-app: #0d0e11;
    --card-bg: rgba(22, 25, 32, 0.85);
    --card-hover: #1e222b;
    --border-grey: #1f2937;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --input-bg: rgba(13, 14, 17, 0.8);
    --dialog-backdrop: rgba(7, 8, 10, 0.85);
    --dialog-bg: #161920;
    --stroke-track: #374151;
  }
}

/* Global Overrides */
body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

    :where(*) {
      border-color: rgba(100, 116, 139, 0.18);
    }
    
    /* Premium custom scrollbar */
    ::-webkit-scrollbar {
      width: 6px;
      height: 6px;
    }
    ::-webkit-scrollbar-track {
      background: var(--bg-app);
    }
    ::-webkit-scrollbar-thumb {
      background: var(--border-grey);
      border-radius: 9999px;
    }
    ::-webkit-scrollbar-thumb:hover {
      background: var(--color-mint);
    }
    
    /* Circular progress glow and visibility fixes */
    #progress-circle {
      filter: drop-shadow(0 0 3px rgba(16, 185, 129, 0.6));
    }
    
    /* High-contrast today active highlights */
    .today-cell {
      outline: 3px solid #f59e0b !important;
      outline-offset: 3px !important;
      z-index: 10 !important;
    }
    .today-row {
      outline: 3px solid #f59e0b !important;
      outline-offset: 3px !important;
      z-index: 10 !important;
    }

    /* Glow utility — applied to perfect day cells */
    .glow-mint {
      box-shadow: 0 0 12px rgba(16, 185, 129, 0.45), 0 0 4px rgba(16, 185, 129, 0.25) !important;
    }

    .milestone-dot-unlocked {
      background-color: var(--color-mint) !important;
      border-color: var(--color-mint) !important;
    }

    .segmented-tab-active {
      background: var(--dialog-bg) !important;
      color: var(--text-main) !important;
      border-color: rgba(16, 185, 129, 0.55) !important;
    }

    .segmented-tab-inactive {
      background: transparent !important;
      color: var(--text-muted) !important;
      border-color: transparent !important;
    }

    /* Calendar Cell & Row Status Styles (2px solid borders) */
    .cell-perfect {
      background-color: rgba(16, 185, 129, 0.12) !important;
      border: 2px solid #10b981 !important;
      color: #10b981 !important;
    }
    .cell-grace {
      background-color: rgba(16, 185, 129, 0.1) !important;
      border: 2px solid #10b981 !important;
      color: #10b981 !important;
    }
    .cell-compliant {
      background-color: rgba(234, 179, 8, 0.09) !important;
      border: 2px solid #eab308 !important;
      color: #eab308 !important;
    }
    .cell-forfeit {
      background-color: rgba(249, 115, 22, 0.1) !important;
      border: 2px solid #f97316 !important;
      color: #f97316 !important;
    }
    .cell-missed {
      background-color: rgba(249, 115, 22, 0.06) !important;
      border: 2px solid rgba(249, 115, 22, 0.65) !important;
      color: rgba(249, 115, 22, 0.75) !important;
    }
    .cell-default {
      background-color: var(--card-bg) !important;
      border: 1px solid rgba(100, 116, 139, 0.35) !important;
      color: var(--text-muted) !important;
    }
    .cell-locked {
      background-color: transparent !important;
      border: 1px solid rgba(100, 116, 139, 0.15) !important;
      color: rgba(156, 163, 175, 0.25) !important;
      opacity: 0.5 !important;
      cursor: default !important;
    }

    /* Chain View Row Status Styles */
    .row-perfect {
      background-color: rgba(16, 185, 129, 0.1) !important;
      border: 2px solid #10b981 !important;
      color: #10b981 !important;
    }
    .row-grace {
      background-color: rgba(16, 185, 129, 0.1) !important;
      border: 2px solid #10b981 !important;
      color: #10b981 !important;
    }
    .row-compliant {
      background-color: rgba(234, 179, 8, 0.09) !important;
      border: 2px solid #eab308 !important;
      color: #eab308 !important;
    }
    .row-forfeit {
      background-color: rgba(249, 115, 22, 0.1) !important;
      border: 2px solid #f97316 !important;
      color: #f97316 !important;
    }
    .row-missed {
      background-color: rgba(249, 115, 22, 0.06) !important;
      border: 2px solid rgba(249, 115, 22, 0.65) !important;
      color: rgba(249, 115, 22, 0.75) !important;
    }
    .row-default {
      background-color: var(--card-bg) !important;
      border: 1px solid rgba(100, 116, 139, 0.35) !important;
      color: var(--text-muted) !important;
    }
    .row-locked {
      background-color: transparent !important;
      border: 1px solid rgba(100, 116, 139, 0.12) !important;
      color: rgba(156, 163, 175, 0.25) !important;
      opacity: 0.5 !important;
      cursor: default !important;
    }
    
    /* Keyframe Animations */
    @keyframes pulse-glow {
      0%, 100% {
        box-shadow: 0 0 10px rgba(16, 185, 129, 0.15);
        border-color: rgba(16, 185, 129, 0.3);
      }
      50% {
        box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
        border-color: rgba(16, 185, 129, 0.8);
      }
    }
    
    @keyframes spring {
      0% { transform: scale(1); }
      30% { transform: scale(0.92); }
      70% { transform: scale(1.03); }
      100% { transform: scale(1); }
    }
    
    /* Utility Animations classes */
    .animate-glow-pulse {
      animation: pulse-glow 2s infinite ease-in-out;
    }
    
    .springy-click:active {
      animation: spring 0.25s ease-out;
    }

    .settings-workout-day-toggle {
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 2.25rem;
      padding: 0.5rem;
      border: 1px solid var(--border-grey);
      border-radius: 0.5rem;
      background-color: var(--input-bg);
      color: var(--text-muted);
      cursor: pointer;
      user-select: none;
      font-family: var(--font-mono);
      font-size: 10px;
      font-weight: 700;
      transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
    }

    .settings-workout-day-toggle:hover {
      border-color: rgba(16, 185, 129, 0.6);
      color: var(--text-main);
    }

    .settings-workout-day-toggle:focus-visible {
      outline: 2px solid rgba(16, 185, 129, 0.6);
      outline-offset: 2px;
    }

    .settings-workout-day-toggle[aria-pressed="true"] {
      border-color: #10b981;
      background-color: rgba(16, 185, 129, 0.1);
      color: #10b981;
    }

    .settings-workout-day-toggle:active {
      animation: spring 0.25s ease-out;
    }

    .help-button {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 0;
      border: 0;
      background: transparent;
      color: var(--text-muted);
      cursor: pointer;
      font-family: var(--font-mono);
      font-size: 0.8em;
      font-weight: 900;
      line-height: 1;
      transition: color 0.15s ease, transform 0.15s ease;
    }

    .help-button:hover,
    .help-button:focus-visible {
      color: var(--color-mint);
      outline: none;
      transform: scale(1.08);
    }

    #help-modal {
      max-width: 34rem;
    }
    
    /* Glassmorphism card backgrounds */
    .glass-card {
      background: var(--card-bg);
      backdrop-filter: blur(16px);
      border: 1px solid var(--border-grey);
    }
    
    /* Horizontal lines for chain view connection */
    .chain-line {
      background: linear-gradient(180deg, var(--border-grey) 0%, var(--border-grey) 100%);
    }
    .chain-line-active {
      background: linear-gradient(180deg, var(--color-mint) 0%, var(--color-mint) 100%);
    }

    /* Absolute Centering of Dialog Modals */
    dialog {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      margin: 0;
      max-width: 28rem;
      max-height: 90vh;
      overflow-y: auto;
      width: calc(100% - 2rem);
      background-color: var(--dialog-bg);
      color: var(--text-main);
      border: 1px solid var(--border-grey);
      border-radius: 1.5rem;
      box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
      z-index: 50;
      padding: 1.5rem;
    }

    #settings-modal {
      max-width: 62rem;
    }

    .settings-modal-grid {
      display: grid;
      grid-template-columns: minmax(0, 1fr);
      gap: 1rem;
    }

    dialog::backdrop {
      background-color: var(--dialog-backdrop);
      backdrop-filter: blur(12px);
      transition: backdrop-filter 0.3s ease;
    }

    /* Mobile responsive optimization overrides */
    @media (max-width: 640px) {
      body {
        padding: 0.75rem !important; /* Decrease outer margins for more layout space */
      }
      #sync-indicator {
        width: 1.75rem !important;
        height: 1.75rem !important;
      }
      #sync-dot {
        width: 0.5rem !important;
        height: 0.5rem !important;
      }
      /* Scale up small typography for mobile legibility */
      .text-\[8px\] { font-size: 10px !important; }
      .text-\[9px\] { font-size: 11px !important; }
      .text-\[10px\] { font-size: 12px !important; }
      .text-\[11px\] { font-size: 13px !important; }
      
      /* Make sure calendar grid adapts nicely */
      #calendar-view-container .grid {
        gap: 0.375rem !important;
      }
      /* Mobile grid cells: just the number, no extra padding needed */
      #calendar-view-container button {
        padding: 4px !important;
      }
      #calendar-view-container button span:first-of-type {
        font-size: 12px !important;
      }
      
      /* Scale up modal items slightly */
      dialog {
        padding: 1.25rem !important;
        border-radius: 1.25rem !important;
      }
      .settings-workout-day-toggle {
        min-height: 2.5rem;
        font-size: 12px;
      }

      #settings-modal {
        width: calc(100% - 1.5rem);
      }
    }

    @media (min-width: 1024px) {
      .settings-modal-grid {
        grid-template-columns: minmax(0, 1.02fr) minmax(0, 0.98fr);
        gap: 1.25rem;
      }
    }
    
    /* Sync Status Colors */
    .sync-success {
      background-color: var(--color-mint, #10b981) !important;
    }
    .sync-syncing {
      background-color: var(--color-amber-custom, #f59e0b) !important;
    }
    .sync-offline {
      background-color: var(--color-crimson, #ef4444) !important;
    }
    .sync-connecting {
      background-color: var(--text-muted, #9ca3af) !important;
    }
