/* GrantScope.ai Accessible Theme System (Light, Dark, High-Contrast) */
/* Brand: Vibe Purple (#6D4AFF), Aqua Teal (#14B8A6), Signal Amber (#FF8C00) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap');

/* Core tokens: fonts, radii, shadows, spacing, full color ramps in rgb(var) format */
:root {
  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Radius */
  --radius-xs: 0.125rem;
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px rgba(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px rgba(0 0 0 / 0.15);
  --shadow-xl: 0 20px 25px rgba(0 0 0 / 0.18);

  /* Spacing */
  --space-xxs: 2px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* === Brand Ramps ======================================================= */
  /* Primary (Vibe Purple): #6D4AFF - Adjusted for WCAG AA/AAA compliance */
  --primary-50: 243 240 255;   /* #F3F0FF */
  --primary-100: 233 227 255;  /* #E9E3FF */
  --primary-200: 211 199 255;  /* #D3C7FF */
  --primary-300: 182 164 255;  /* #B6A4FF */
  --primary-400: 150 122 255;  /* #967AFF */
  --primary-500: 109 74 255;   /* #6D4AFF */
  --primary-600: 87 54 204;    /* #5736CC - Better contrast */
  --primary-700: 71 40 173;    /* #4728AD - WCAG AA */
  --primary-800: 56 29 140;    /* #381D8C - WCAG AAA */
  --primary-900: 41 20 107;    /* #29146B */
  --primary-950: 26 10 71;     /* #1A0A47 */
  --primary-foreground: 255 255 255;

  /* Secondary (Aqua Teal): #14B8A6 */
  --secondary-50: 229 250 246;
  --secondary-100: 191 245 236;
  --secondary-200: 152 238 226;
  --secondary-300: 112 226 213;
  --secondary-400: 74 213 198;
  --secondary-500: 20 184 166; /* #14B8A6 */
  --secondary-600: 17 148 134;
  --secondary-700: 13 116 106;
  --secondary-800: 10 90 82;
  --secondary-900: 7 64 58;
  --secondary-950: 4 40 36;
  --secondary-foreground: 17 24 39;

  /* Accent (Signal Amber): #FF8C00 */
  --accent-50: 255 244 230;
  --accent-100: 255 231 204;
  --accent-200: 255 210 153;
  --accent-300: 255 187 102;
  --accent-400: 255 164 51;
  --accent-500: 255 140 0;     /* #FF8C00 */
  --accent-600: 217 119 0;
  --accent-700: 179 97 0;
  --accent-800: 140 76 0;
  --accent-900: 102 55 0;
  --accent-950: 64 35 0;
  --accent-foreground: 17 24 39;

  /* Semantic ramps */
  --success-50: 236 253 245;
  --success-500: 5 150 105;   /* teal-600 */
  --success-700: 4 120 84;

  --error-50: 254 242 242;
  --error-500: 220 38 38;
  --error-700: 185 28 28;

  --warning-50: 255 251 235;
  --warning-500: 217 119 6;
  --warning-700: 180 83 9;

  --info-50: 239 246 255;
  --info-500: 59 130 246;
  --info-700: 29 78 216;

  /* Light surfaces */
  --background: 246 247 251;         /* slightly cooler canvas for purple brand */
  --surface: 255 255 255;
  --surface-variant: 245 247 252;
  --card: 255 255 255;
  --overlay: 0 0 0;

  /* Text & borders - Enhanced for accessibility */
  --text-primary: 10 10 20;          /* Near black for max contrast */
  --text-secondary: 45 50 65;        /* Darker gray for AA compliance */
  --text-muted: 75 85 99;            /* Still muted but readable */
  --border: 203 213 225;             /* slate-300 */

  /* Links - WCAG compliant */
  --link: 71 40 173;                 /* Primary-700 for AA compliance */
  --link-visited: 56 29 140;         /* Primary-800 for visited */

  /* Focus ring and selection */
  --focus-ring: var(--primary-500);
  --selection-bg: var(--primary-200);
  --selection-fg: 23 12 64;

  /* Motion */
  --transition-fast: 150ms;
  --transition-base: 250ms;
  --transition-slow: 400ms;

  /* Brand utility */
  --brand-gradient-from: var(--primary-500);
  --brand-gradient-to: var(--secondary-500);

  /* Legacy compatibility */
  --primary: rgb(var(--primary-500));
  --secondary: rgb(var(--secondary-500));
  --accent: rgb(var(--accent-500));
  --success: rgb(var(--success-500));
  --warning: rgb(var(--warning-500));
  --danger: rgb(var(--error-500));
  --text: rgb(var(--text-primary));
  --text-light: rgb(var(--text-secondary));
  --background-rgb: rgb(var(--background));
  --surface-rgb: rgb(var(--surface));
}

/* Dark theme */
:root[data-theme='dark'] {
  --background: 15 23 42;           /* slate-900 */
  --surface: 30 41 59;              /* slate-800 */
  --surface-variant: 42 53 70;      /* slate-700 */
  --card: 30 41 59;
  --overlay: 0 0 0;

  --text-primary: 248 250 252;       /* slate-50 */
  --text-secondary: 203 213 225;     /* slate-300 */
  --text-muted: 148 163 184;         /* slate-400 */
  --border: 71 85 105;               /* slate-600 */

  /* Slightly brighter brand in dark mode for contrast */
  --primary-500: 173 148 255;        /* #AD94FF */
  --secondary-500: 45 212 191;       /* teal-400 */
  --accent-500: 251 191 36;          /* amber-400 */

  --primary-foreground: 23 12 64;    /* deep purple text */
  --secondary-foreground: 17 24 39;
  --accent-foreground: 17 24 39;

  --success-50: 32 39 35;
  --success-500: 110 231 183;
  --success-700: 6 95 70;

  --error-50: 40 32 34;
  --error-500: 248 113 113;
  --error-700: 153 27 27;

  --warning-50: 41 37 31;
  --warning-500: 251 191 36;
  --warning-700: 180 83 9;

  --info-50: 30 36 47;
  --info-500: 147 197 253;
  --info-700: 55 48 163;

  --link: var(--primary-500);
  --link-visited: 196 181 253;
}

/* High contrast (intentionally strong for maximum legibility) */
:root[data-theme='hc'] {
  --background: 0 0 0;
  --surface: 0 0 0;
  --surface-variant: 0 0 0;
  --card: 0 0 0;

  --text-primary: 255 255 255;
  --text-secondary: 255 255 0;
  --text-muted: 200 200 200;
  --border: 255 255 0;

  --primary-500: 255 255 0;       /* yellow accents on black */
  --secondary-500: 255 255 0;
  --accent-500: 255 255 0;

  --primary-foreground: 0 0 0;
  --secondary-foreground: 0 0 0;
  --accent-foreground: 0 0 0;

  --link: 255 255 0;
  --link-visited: 173 255 47;

  --focus-ring: 255 255 0;
  --selection-bg: 255 255 0;
  --selection-fg: 0 0 0;
}

/* Dark mode detection */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --background: 15 23 42;
    --surface: 30 41 59;
    --surface-variant: 42 53 70;
    --card: 30 41 59;
    --overlay: 0 0 0;

    --text-primary: 248 250 252;
    --text-secondary: 203 213 225;
    --text-muted: 148 163 184;
    --border: 71 85 105;

    --primary-500: 173 148 255;
    --secondary-500: 45 212 191;
    --accent-500: 251 191 36;

    --primary-foreground: 23 12 64;
    --secondary-foreground: 17 24 39;
    --accent-foreground: 17 24 39;

    --success-50: 32 39 35;
    --success-500: 110 231 183;
    --success-700: 6 95 70;

    --error-50: 40 32 34;
    --error-500: 248 113 113;
    --error-700: 153 27 27;

    --warning-50: 41 37 31;
    --warning-500: 251 191 36;
    --warning-700: 180 83 9;

    --info-50: 30 36 47;
    --info-500: 147 197 253;
    --info-700: 55 48 163;

    --link: var(--primary-500);
    --link-visited: 196 181 253;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Selection color (all themes) */
::selection {
  background: rgb(var(--selection-bg));
  color: rgb(var(--selection-fg));
}

/* Base styles */
html {
  font-family: var(--font-sans);
  color: rgb(var(--text-primary));
  background-color: rgb(var(--background));
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  line-height: 1.6;
}

a {
  color: rgb(var(--link));
}
a:visited { color: rgb(var(--link-visited)); }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid rgb(var(--focus-ring));
  outline-offset: 2px;
}

/* Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  background-color: rgb(var(--surface));
  color: rgb(var(--text-primary));
  border: 1px solid rgb(var(--border));
}

.btn:focus-visible {
  outline: 2px solid rgb(var(--focus-ring));
  outline-offset: 2px;
}

.btn-primary {
  background-color: rgb(var(--primary-700));  /* Use darker shade for better contrast */
  color: rgb(var(--primary-foreground));
  border-color: transparent;
}
.btn-primary:hover { 
  background-color: rgb(var(--primary-800)); 
}

.btn-secondary {
  background-color: rgb(var(--secondary-500));
  color: rgb(var(--secondary-foreground));
  border-color: transparent;
}
.btn-secondary:hover { 
  background-color: rgb(var(--secondary-600)); 
}

.btn-accent {
  background-color: rgb(var(--accent-500));
  color: rgb(var(--accent-foreground));
  border-color: transparent;
}
.btn-accent:hover { 
  background-color: rgb(var(--accent-600)); 
}

.btn-ghost {
  background-color: transparent;
  color: rgb(var(--text-primary));
  border: 1px solid rgb(var(--border));
}
.btn-ghost:hover { 
  background-color: rgba(var(--text-primary) / 0.05); 
}

.input {
  width: 100%;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid rgb(var(--border));
  background-color: rgb(var(--surface));
  color: rgb(var(--text-primary));
  caret-color: rgb(var(--primary-500));
}

.input::placeholder { 
  color: rgb(var(--text-muted)); 
}

.input:focus-visible {
  box-shadow: 0 0 0 2px rgba(var(--primary-500) / 0.3);
  border-color: rgb(var(--primary-500));
  outline: none;
}

.card {
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  background-color: rgb(var(--surface));
  color: rgb(var(--text-primary));
  box-shadow: var(--shadow-md);
  border: 1px solid rgb(var(--border));
}

.navbar {
  height: 4rem;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  background-color: rgb(var(--surface));
  color: rgb(var(--text-primary));
  border-bottom: 1px solid rgb(var(--border));
}

.footer {
  font-size: 0.875rem;
  text-align: center;
  padding: 1rem;
  background-color: rgb(var(--surface-variant));
  color: rgb(var(--text-muted));
}

/* Brand gradient utility (vibe flourish) */
.bg-brand-gradient {
  background-image: linear-gradient(135deg,
    rgb(var(--brand-gradient-from)) 0%,
    rgb(var(--brand-gradient-to)) 100%);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 500;
  background-color: rgba(var(--primary-500) / 0.1);
  color: rgb(var(--primary-700));
  border: 1px solid rgba(var(--primary-500) / 0.25);
}

/* Accessible Slider Styles */
.slider-purple {
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    opacity: 0.9;
    transition: opacity var(--transition-fast);
    background-color: rgb(var(--border));
    height: 6px;
    border-radius: var(--radius-full);
}

.slider-purple:hover {
    opacity: 1;
}

.slider-purple:focus-visible {
    outline: 2px solid rgb(var(--focus-ring));
    outline-offset: 2px;
}

.slider-purple::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: rgb(var(--primary-700));
    cursor: pointer;
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast);
}

.slider-purple::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.slider-purple::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: rgb(var(--primary-700));
    cursor: pointer;
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    border: none;
    transition: transform var(--transition-fast);
}

.slider-purple::-moz-range-thumb:hover {
    transform: scale(1.1);
}

/* Base styles with improved mobile support */
* {
    box-sizing: border-box;
}

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

body {
    font-family: var(--font-body);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* Enhanced mobile-first approach */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }
    
    /* Prevent horizontal overflow on mobile */
    .mobile-header {
        max-width: 100vw;
    }
    
    #app {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    main {
        max-width: 100vw;
        overflow-x: hidden;
    }
}

/* Improved scrollbar for all browsers */
* {
    scrollbar-width: thin;
    scrollbar-color: rgb(var(--text-muted)) rgb(var(--surface-variant));
}

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

*::-webkit-scrollbar-track {
    background: rgb(var(--surface-variant));
    border-radius: 3px;
}

*::-webkit-scrollbar-thumb {
    background: rgb(var(--text-muted));
    border-radius: 3px;
    transition: var(--transition-fast);
}

*::-webkit-scrollbar-thumb:hover {
    background: rgb(var(--text-secondary));
}

/* Enhanced focus states for accessibility */
*:focus {
    outline: 2px solid rgb(var(--focus-ring));
    outline-offset: 2px;
}

button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid rgb(var(--focus-ring));
    outline-offset: 2px;
}

/* Modern glass morphism effect */
.glass {
    background: rgba(var(--surface) / 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(var(--border) / 0.5);
}

/* AI Writing Assistant specific styles - fully opaque */
#ai-writing-assistant {
    background: rgb(var(--surface)) !important;
    opacity: 1 !important;
}

#ai-writing-assistant .bg-surface-light,
#ai-writing-assistant .bg-surface-hover {
    background: rgb(var(--surface)) !important;
    opacity: 1 !important;
}

/* Quick action buttons styling */
.quick-action-btn {
    background: rgb(var(--surface-variant));
    border: 1px solid rgb(var(--border));
    padding: 0.75rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: rgb(var(--text-primary));
    transition: all 0.2s;
}

.quick-action-btn:hover {
    background: rgb(var(--primary-500));
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(var(--primary-500) / 0.3);
}

/* Grant writing tooltips - ensure visibility */
.grant-writing-tooltip {
    background: rgb(var(--surface)) !important;
    opacity: 1 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid rgb(var(--border));
}

/* Gradient backgrounds */
.gradient-primary {
    background: linear-gradient(135deg, rgb(var(--primary-700)) 0%, rgb(var(--primary-500)) 100%);
}

.gradient-secondary {
    background: linear-gradient(135deg, rgb(var(--secondary-700)) 0%, rgb(var(--secondary-500)) 100%);
}

.gradient-accent {
    background: linear-gradient(135deg, rgb(var(--accent-700)) 0%, rgb(var(--accent-500)) 100%);
}

/* Enhanced animations */
@keyframes slideInUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(var(--primary-500) / 0.4);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(var(--primary-500) / 0);
    }
}

@keyframes shimmer {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.animate-slide-up {
    animation: slideInUp var(--transition-normal) ease-out;
}

.animate-slide-right {
    animation: slideInRight var(--transition-normal) ease-out;
}

.animate-fade-in {
    animation: fadeIn var(--transition-normal) ease-out;
}

.animate-pulse-glow {
    animation: pulse-glow 2s infinite;
}

/* Loading skeleton */
.skeleton {
    background: linear-gradient(90deg, 
        rgb(var(--surface-variant)) 25%, 
        rgba(var(--text-muted) / 0.1) 50%, 
        rgb(var(--surface-variant)) 75%);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

/* Enhanced mobile responsiveness */
.mobile-hidden {
    display: block;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-hidden {
        display: none;
    }
    
    .mobile-only {
        display: block;
    }
    
    .mobile-stack {
        flex-direction: column;
    }
    
    .mobile-full {
        width: 100%;
    }
    
    .mobile-text-center {
        text-align: center;
    }
    
    .mobile-p-4 {
        padding: 1rem;
    }
    
    .mobile-mt-4 {
        margin-top: 1rem;
    }
}

/* Enhanced Navigation styles */
.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-lg);
    color: rgb(var(--text-secondary));
    font-weight: 500;
    font-size: 0.875rem;
    transition: var(--transition-fast);
    text-decoration: none;
    overflow: hidden;
    z-index: 10;
    pointer-events: auto;
}

.nav-link:hover {
    background: rgb(var(--surface-variant));
    color: rgb(var(--text-primary));
    transform: translateY(-1px);
}

.nav-link.active {
    background: rgb(var(--primary-700));
    color: rgb(var(--primary-foreground));
    box-shadow: var(--shadow-md);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 100%);
    pointer-events: none;
}

.nav-link i,
.nav-link svg {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}

.nav-link .nav-badge {
    margin-left: auto;
    background: var(--accent);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.375rem;
    border-radius: 9999px;
    min-width: 1.25rem;
    text-align: center;
}

/* Mobile navigation improvements */
@media (max-width: 768px) {
    .nav-link {
        padding: 1rem;
        font-size: 1rem;
    }
    
    .nav-link i,
    .nav-link svg {
        width: 1.5rem;
        height: 1.5rem;
    }
}

/* Mobile navigation removed - no longer needed */

/* Fix horizontal scrollbar on mobile */
@media (max-width: 1023px) {
    /* Prevent horizontal overflow */
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
        position: relative;
    }
    
    /* Ensure all containers respect viewport width */
    #app, main, .mobile-header {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Fix sidebar width on mobile */
    #sidebar {
        width: 85%;
        max-width: 320px;
    }
    
    /* Ensure content doesn't overflow */
    .tunaas-logo, .nav-link, .p-4, .p-6 {
        max-width: 100%;
        word-wrap: break-word;
        box-sizing: border-box;
    }
    
    /* Fix any fixed positioned elements */
    .fixed {
        max-width: 100vw;
    }
    
    /* Footer specific fixes */
    .bg-gray-50 {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Prevent padding-induced overflow */
    .p-4 {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* Main content adjustments */
    main {
        width: 100%;
        padding-bottom: 60px; /* Space for mobile nav if any */
    }
}

/* Enhanced sidebar */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--surface-dark);
    transition: var(--transition-normal);
    z-index: 100;
    pointer-events: auto;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--surface-dark);
    background: var(--surface-light);
}

.tunaas-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--primary);
    border-radius: var(--radius-lg);
    color: white;
    font-weight: 700;
    font-size: 0.875rem;
    letter-spacing: 0.05em;
}

.tunaas-logo .icon {
    font-size: 1.25rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-3px);
    }
}

/* Mobile sidebar toggle */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1000;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 0.75rem;
    box-shadow: var(--shadow-lg);
    transition: var(--transition-fast);
}

.sidebar-toggle:hover {
    transform: scale(1.05);
}

@media (max-width: 768px) {
    .sidebar-toggle {
        display: block;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        height: 100vh;
        width: 280px;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
        transition: var(--transition-normal);
    }
    
    .sidebar-overlay.active {
        display: block;
    }
}

/* Enhanced Grant card styles */
.grant-card {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--surface-dark);
    padding: 1.5rem;
    transition: var(--transition-normal);
    cursor: pointer;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.grant-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 50%, var(--accent) 100%);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform var(--transition-normal);
}

.grant-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.grant-card:hover::before {
    transform: scaleX(1);
}

.grant-card:active {
    transform: translateY(0);
}

.grant-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    gap: 1rem;
}

.grant-card-title {
    color: rgb(var(--text-primary));
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.4;
    margin: 0 0 0.5rem 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.grant-card-agency {
    color: rgb(var(--text-secondary));
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.grant-card-description {
    color: rgb(var(--text-secondary));
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 1rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.grant-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.grant-card-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid var(--surface-dark);
}

.grant-card-funding {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--success);
    font-weight: 600;
    font-size: 0.875rem;
}

.grant-card-deadline {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.grant-card-deadline.urgent {
    color: var(--danger);
}

.grant-card-deadline.soon {
    color: var(--warning);
}

.grant-card-deadline.normal {
    color: var(--text-light);
}

/* Enhanced badge styles */
.grant-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    transition: var(--transition-fast);
}

.grant-badge:hover {
    transform: scale(1.05);
}

.grant-badge.agency {
    background: rgba(108, 43, 217, 0.1);
    color: var(--primary);
    border: 1px solid rgba(108, 43, 217, 0.2);
}

.grant-badge.category {
    background: rgba(255, 140, 0, 0.1);
    color: var(--accent);
    border: 1px solid rgba(255, 140, 0, 0.2);
}

.grant-badge.funding {
    background: rgba(5, 150, 105, 0.1);
    color: var(--success);
    border: 1px solid rgba(5, 150, 105, 0.2);
}

.grant-badge.deadline {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.grant-badge.deadline.soon {
    background: var(--warning);
    color: white;
    animation: pulse-glow 2s infinite;
}

.grant-badge.deadline.urgent {
    background: var(--danger);
    color: white;
    animation: pulse-glow 1s infinite;
}

.grant-badge.status {
    background: rgba(31, 182, 162, 0.1);
    color: var(--secondary);
    border: 1px solid rgba(31, 182, 162, 0.2);
}

/* Icon enhancements */
.grant-card-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

/* Mobile grant card optimizations */
@media (max-width: 768px) {
    .grant-card {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .grant-card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .grant-card-title {
        font-size: 1rem;
        -webkit-line-clamp: 3;
    }
    
    .grant-card-meta {
        justify-content: flex-start;
    }
    
    .grant-card-actions {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }
    
    .grant-badge {
        font-size: 0.65rem;
        padding: 0.25rem 0.5rem;
    }
}

/* Loading state for grant cards */
.grant-card.loading {
    pointer-events: none;
}

.grant-card.loading .grant-card-title,
.grant-card.loading .grant-card-description,
.grant-card.loading .grant-card-agency {
    background: var(--surface-dark);
    color: transparent;
    border-radius: var(--radius-sm);
    animation: shimmer 1.5s infinite;
}

/* Grid layout for grant cards */
.grants-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
    padding: 1rem;
}

@media (max-width: 768px) {
    .grants-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 0.5rem;
    }
}

/* Enhanced Chat interface styles */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--surface);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.chat-header {
    padding: 1rem 1.5rem;
    background: var(--primary);
    color: white;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-header .icon {
    width: 1.5rem;
    height: 1.5rem;
}

.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: slideInUp var(--transition-normal) ease-out;
}

.chat-message.user {
    flex-direction: row-reverse;
}

.chat-message-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.chat-message.user .chat-message-avatar {
    background: var(--primary);
    color: white;
}

.chat-message.assistant .chat-message-avatar {
    background: var(--secondary);
    color: white;
}

.chat-message-content {
    max-width: 75%;
    padding: 0.875rem 1.125rem;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    line-height: 1.5;
    position: relative;
}

.chat-message.user .chat-message-content {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: var(--radius-sm);
}

.chat-message.assistant .chat-message-content {
    background: var(--surface-light);
    color: var(--text);
    border-bottom-left-radius: var(--radius-sm);
    border: 1px solid var(--surface-dark);
}

.chat-message-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    text-align: right;
}

.chat-message.assistant .chat-message-time {
    text-align: left;
}

.chat-input-container {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--surface-dark);
    background: var(--surface-light);
}

.chat-input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    min-height: 2.5rem;
    max-height: 8rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--surface-dark);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    resize: none;
    font-size: 0.875rem;
    line-height: 1.4;
    transition: var(--transition-fast);
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 43, 217, 0.1);
}

.chat-send-button {
    width: 2.5rem;
    height: 2.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.chat-send-button:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.chat-send-button:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

.chat-typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-light);
    font-size: 0.875rem;
    font-style: italic;
}

.chat-typing-dots {
    display: flex;
    gap: 0.25rem;
}

.chat-typing-dot {
    width: 0.375rem;
    height: 0.375rem;
    background: var(--text-light);
    border-radius: 50%;
    animation: typing-pulse 1.4s infinite ease-in-out;
}

.chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-pulse {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    30% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Mobile chat optimizations */
@media (max-width: 768px) {
    .chat-container {
        border-radius: 0;
        height: 100vh;
    }
    
    .chat-messages {
        max-height: none;
        flex: 1;
        padding: 0.75rem;
    }
    
    .chat-message-content {
        max-width: 85%;
        font-size: 0.875rem;
    }
    
    .chat-input-container {
        padding: 1rem;
    }
    
    .chat-input {
        font-size: 1rem;
    }
}

/* Loading animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

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

/* Custom scrollbar */
.overflow-auto::-webkit-scrollbar {
    width: 6px;
}

.overflow-auto::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.overflow-auto::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.overflow-auto::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Form styles */
.form-input {
    @apply w-full border border-gray-300 rounded-md px-3 py-2 text-sm focus:ring-2 focus:ring-primary focus:border-transparent;
    color: #000000 !important;
    background-color: #FFFFFF !important;
}

/* Ensure all form elements have black text */
input, textarea, select, option {
    color: #000000 !important;
    background-color: #FFFFFF !important;
}

/* Specific select/dropdown styles */
select {
    color: #000000 !important;
    background-color: #FFFFFF !important;
}

select option {
    color: #000000 !important;
    background-color: #FFFFFF !important;
}

/* Filter panel specific styles */
.filter-select {
    color: #000000 !important;
    background-color: #FFFFFF !important;
}

.filter-input {
    color: #000000 !important;
    background-color: #FFFFFF !important;
}

/* Theme-aware text colors - removed forced black text to allow proper theming */
/* Text colors are now controlled by CSS variables in the theme system */

/* Exception for specific elements that should keep their colors */
.nav-link.active {
    color: rgb(var(--primary-foreground)) !important;
}

.btn-primary, .bg-primary button {
    color: white !important;
}

.text-primary {
    color: var(--primary) !important;
}

.text-white {
    color: white !important;
}

/* Navigation links use theme colors */
.nav-link:not(.active) {
    color: rgb(var(--text-secondary)) !important;
}

.nav-link:not(.active):hover {
    color: var(--primary) !important;
}

/* Ensure badges and special elements maintain their styling */
.grant-badge, .nav-badge {
    color: inherit !important;
}

/* Chat messages maintain their styling */
.chat-message.user .chat-message-content,
.chat-message.assistant .chat-message-content {
    color: inherit !important;
}

/* Maintain button text colors */
button.btn-primary,
button.bg-primary {
    color: white !important;
}

/* Ensure placeholders are visible */
::placeholder {
    color: #6B7280 !important;
    opacity: 1;
}

/* Fix text in gray containers */
.text-gray-500, .text-gray-600, .text-gray-700 {
    color: #374151 !important;
}

/* Ensure dropdown options are black on white */
select option {
    color: #000000 !important;
    background-color: #FFFFFF !important;
    padding: 8px;
}

/* Fix any potential contrast issues */
.bg-gray-100, .bg-gray-200 {
    color: #000000 !important;
}

.btn-primary {
    @apply px-4 py-2 bg-primary text-white rounded-lg hover:bg-primary-600 focus:ring-2 focus:ring-primary focus:ring-offset-2 transition-colors;
}

.btn-secondary {
    @apply px-4 py-2 bg-gray-200 text-gray-800 rounded-lg hover:bg-gray-300 focus:ring-2 focus:ring-gray-500 focus:ring-offset-2 transition-colors;
}

/* Responsive design */
@media (max-width: 768px) {
    .nav-link span {
        @apply sr-only;
    }
    
    .nav-link {
        @apply justify-center;
    }
}

/* Print styles */
@media print {
    .nav-link, #ai-panel, header {
        display: none !important;
    }
    
    #main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* Tunaas.ai Brand Styles */
body {
    font-family: var(--font-body);
    color: var(--text);
    background-color: var(--background);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--text);
    font-weight: 600;
}

.tunaas-logo {
    font-family: var(--font-mono);
    color: rgb(var(--primary-700));
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.tunaas-logo .icon {
    font-size: 1.2em;
}

/* Updated button styles */
.btn-primary {
    background-color: var(--primary);
    color: white;
    font-weight: 600;
    padding: 12px 20px;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    background-color: #5721B5;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(108, 43, 217, 0.3);
}

.btn-secondary {
    background-color: var(--secondary);
    color: white;
    font-weight: 600;
    padding: 12px 20px;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background-color: #178B7C;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(31, 182, 162, 0.3);
}

/* Card styles with new design */
.card {
    background: var(--surface);
    border-radius: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    padding: 24px;
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

/* Input styles */
input, textarea, select {
    border: 1px solid #CBD5E1;
    border-radius: 0.375rem;
    padding: 10px 14px;
    font-family: var(--font-body);
    transition: all 0.3s ease;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 43, 217, 0.1);
}

/* Team section styles */
.team-member {
    background: var(--surface);
    border-radius: 1rem;
    padding: 2rem;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.team-member:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.team-member h3 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.team-member .role {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 1rem;
}

.team-member .bio {
    color: var(--text-secondary);
    line-height: 1.6;
    font-size: 0.875rem;
}

/* Footer styles */
.footer {
    background: #F9FAFB;
    color: var(--text-light);
    padding: 2rem 0;
    text-align: center;
    border-top: 1px solid #E5E7EB;
    margin-top: 4rem;
}

.footer .powered-by {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

/* Navigation section headers */
.nav-section-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.25rem 0.75rem;
    margin: 0.5rem 0;
    opacity: 0.8;
}

/* Mobile-first optimizations */
@media (max-width: 768px) {
    /* Touch-friendly buttons */
    .btn, button {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
    }
    
    /* Better spacing for mobile */
    .p-6 {
        padding: 1rem;
    }
    
    .p-4 {
        padding: 0.75rem;
    }
    
    /* Responsive text sizes */
    h1 {
        font-size: 1.5rem;
    }
    
    h2 {
        font-size: 1.25rem;
    }
    
    h3 {
        font-size: 1.1rem;
    }
    
    /* Mobile-friendly cards */
    .grant-card {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    /* Touch-friendly navigation */
    .nav-link {
        padding: 1rem 1.25rem;
        min-height: 56px;
        border-radius: 8px;
        margin: 2px 0;
    }
    
    /* Mobile sidebar adjustments */
    #sidebar {
        width: 85%;
        max-width: 320px;
    }
    
    /* Mobile search bar */
    .search-bar {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    input[type="text"], input[type="search"] {
        font-size: 16px !important;
        -webkit-appearance: none;
    }
    
    /* Responsive grid adjustments */
    .grid-cols-2 {
        grid-template-columns: 1fr;
    }
    
    .grid-cols-3 {
        grid-template-columns: 1fr;
    }
    
    /* Mobile modal optimization */
    .modal {
        margin: 0;
        max-height: 100vh;
        width: 100%;
        border-radius: 0;
    }
    
    /* Sticky mobile header */
    .mobile-header {
        position: sticky;
        top: 0;
        z-index: 100;
    }
    
    /* Mobile table scrolling */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    /* Touch-friendly form elements */
    input, select, textarea {
        font-size: 16px;
        padding: 12px;
        min-height: 44px;
    }
    
    /* Mobile filter panel */
    .filter-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 16px 16px 0 0;
        max-height: 70vh;
        overflow-y: auto;
    }
    
    /* Mobile-friendly grant display */
    .grant-list {
        padding-bottom: 60px; /* Space for bottom nav */
    }
    
    /* Mobile AI assistant */
    .ai-assistant {
        bottom: 75px; /* Above bottom nav */
        right: 10px;
        max-width: calc(100% - 20px);
    }
    
    /* Swipeable grant cards */
    .grant-card:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }
    
    /* Mobile bottom navigation active state */
    .mobile-nav-item.active {
        color: #6C2BD9;
    }
    
    /* Mobile-friendly modals */
    .grant-modal-content {
        height: 100vh;
        max-height: none;
        overflow-y: auto;
        padding-bottom: 60px;
    }
    
    /* Improve readability on mobile */
    .grant-description {
        line-height: 1.6;
        font-size: 0.95rem;
    }
    
    /* Mobile filters toggle button */
    .mobile-filter-toggle {
        position: fixed;
        bottom: 70px;
        right: 20px;
        width: 56px;
        height: 56px;
        background: #6C2BD9;
        color: white;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(108, 43, 217, 0.3);
        z-index: 40;
    }
}

/* Additional mobile horizontal overflow fix */
@media (max-width: 768px) {
    /* Prevent all horizontal overflow on mobile */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        position: relative;
    }
    
    /* Fix all containers */
    #app, main, nav, .mobile-header, .bg-gray-50, .border-t {
        max-width: 100vw !important;
        overflow-x: hidden !important;
        box-sizing: border-box;
    }
    
    /* Fix sidebar footer specifically */
    .p-4.border-t.border-gray-200,
    div[class*="p-4"][class*="border-t"] {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* Ensure no element can cause overflow */
    * {
        max-width: 100vw !important;
    }
}

/* Animation classes for toast notifications */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(1rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(1rem);
    }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out;
}

.animate-fade-out {
    animation: fadeOut 0.3s ease-in;
}

/* AI Writing Assistant Specific Styles */
#ai-writing-assistant-sidebar {
    backdrop-filter: blur(16px);
    background: rgba(var(--surface-light-rgb), 0.95);
    opacity: 100% !important;
}

.ai-writing-assistant-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: var(--primary-600);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 1000;
}

.ai-writing-assistant-btn:hover {
    background: var(--primary-700);
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.ai-writing-assistant-btn svg {
    width: 24px;
    height: 24px;
}

/* Markdown content styling for AI responses */
.markdown-content p {
    margin-bottom: 0.5rem;
}

.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
    color: var(--text-primary);
}

.markdown-content ul,
.markdown-content ol {
    margin-left: 1rem;
    margin-bottom: 0.5rem;
}

.markdown-content li {
    margin-bottom: 0.25rem;
}

/* Typing indicator animation */
@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Chat input container fix */
.chat-input-container {
    position: relative;
}

/* Suggestions container */
.suggestions-container {
    background: var(--surface-hover);
}
