@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Lora:ital,wght@0,400;0,500;0,600;1,400&display=swap');

:root {
  --background: 0 0% 100%;
  --foreground: 224 71.4% 4.1%;

  --card: 0 0% 100%;
  --card-foreground: 224 71.4% 4.1%;

  --popover: 0 0% 100%;
  --popover-foreground: 224 71.4% 4.1%;

  --primary: 220.9 39.3% 11%;
  --primary-foreground: 210 20% 98%;

  --secondary: 220 14.3% 95.9%;
  --secondary-foreground: 220.9 39.3% 11%;

  --muted: 220 14.3% 95.9%;
  --muted-foreground: 220 8.9% 46.1%;

  --accent: 220 14.3% 95.9%;
  --accent-foreground: 220.9 39.3% 11%;

  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 210 20% 98%;

  --border: 220 13% 91%;
  --input: 220 13% 91%;
  --ring: 224 71.4% 4.1%;

  --radius: 0.5rem;
}

.dark {
  --background: 224 71.4% 4.1%;
  --foreground: 210 20% 98%;

  --card: 224 71.4% 4.1%;
  --card-foreground: 210 20% 98%;

  --popover: 224 71.4% 4.1%;
  --popover-foreground: 210 20% 98%;

  --primary: 210 20% 98%;
  --primary-foreground: 220.9 39.3% 11%;

  --secondary: 215 27.9% 16.9%;
  --secondary-foreground: 210 20% 98%;

  --muted: 215 27.9% 16.9%;
  --muted-foreground: 215 20.2% 65.1%;

  --accent: 215 27.9% 16.9%;
  --accent-foreground: 210 20% 98%;

  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 210 20% 98%;

  --border: 215 27.9% 16.9%;
  --input: 215 27.9% 16.9%;
  --ring: 216 12.2% 83.9%;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    touch-action: manipulation;
}

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
}

.font-serif-editor {
    font-family: 'Lora', Georgia, Cambria, "Times New Roman", Times, serif;
}

body.modal-open {
    overflow: hidden;
}

/* Off-canvas Sidebar drawer */
.sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 290px;
    height: 100vh;
    background-color: hsl(var(--card));
    border-right: 1px solid hsl(var(--border));
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transition: left 0.22s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.sidebar.open {
    left: 0;
}

.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 1999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* Stats horizontal snapping row for mobile */
.stats-snap-row {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.stats-snap-row::-webkit-scrollbar {
    display: none;
}

.stat-card-snap {
    flex: 0 0 160px;
    scroll-snap-align: start;
}

/* Bottom Sheet Overlay on mobile */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 2500;
    display: none;
    align-items: flex-end;
}

.modal {
    background: hsl(var(--card));
    border-top: 1px solid hsl(var(--border));
    border-radius: 1rem 1rem 0 0;
    width: 100%;
    transform: translateY(100%);
    transition: transform 0.22s cubic-bezier(0.165, 0.84, 0.44, 1);
    max-height: 90vh;
    overflow-y: auto;
}

.modal.show {
    transform: translateY(0);
}

/* Floating centered popup on Desktop (992px+) */
@media (min-width: 992px) {
    .sidebar {
        position: sticky;
        top: 100px;
        left: 0;
        width: 260px;
        height: fit-content;
        border: none;
        z-index: 1;
        background-color: transparent;
        display: flex;
        overflow-y: visible;
        transition: none;
    }

    .sidebar-backdrop {
        display: none !important;
    }

    .stats-snap-row {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        overflow-x: visible;
        scroll-snap-type: none;
    }

    .stat-card-snap {
        flex: none;
        scroll-snap-align: none;
    }

    .modal-overlay {
        align-items: center;
        justify-content: center;
    }

    .modal {
        border: 1px solid hsl(var(--border));
        border-radius: var(--radius);
        width: 420px;
        transform: scale(0.9);
        opacity: 0;
        transition: transform 0.15s ease, opacity 0.15s ease;
        max-height: 90%;
    }

    .modal.show {
        transform: scale(1);
        opacity: 1;
    }
}

/* Loader animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .5; }
}

.animate-pulse-slow {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.shake-login {
    animation: shake-anim 0.4s ease-in-out;
}

@keyframes shake-anim {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}
