/* =================================================================
   BASE-SPA.CSS - Foundation Styles for GateChecks SPA
   =================================================================
   Contains: CSS Variables, Resets, Typography, Utilities, Animations
   ================================================================= */

/* =================================================================
   CSS VARIABLES
   ================================================================= */
:root {
    /* Brand Colors */
    --color-primary: #00bcd4;      /* Cyan - Main accent */
    --color-primary-dark: #00acc1; /* Darker cyan */
    --color-primary-light: #26c6da; /* Lighter cyan */
    --color-secondary: #0f766e;    /* Teal */
    --color-accent: #3b82f6;       /* Blue */
    
    /* Status Colors */
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #3b82f6;
    
    /* Dark Theme Colors */
    --bg-primary: #0f172a;         /* Very dark blue - main background */
    --bg-secondary: #1e293b;       /* Dark blue-gray - sections */
    --bg-tertiary: #334155;        /* Medium blue-gray - cards */
    --bg-card: #1a1f2e;           /* Custom dark for cards */
    --border-color: #334155;       /* Dark borders */
    --border-color-dark: #475569;  /* Darker borders */
    
    /* Text Colors - Dark Theme */
    --text-primary: #ffffff;       /* White - main text */
    --text-secondary: #94a3b8;     /* Light blue-gray - secondary */
    --text-tertiary: #64748b;      /* Medium blue-gray - muted */
    --text-inverse: #0f172a;      /* Dark text on light backgrounds */
    
    /* Dark Theme Support (future) */
    --dark-bg-primary: #0f172a;
    --dark-bg-secondary: #1e293b;
    --dark-bg-tertiary: #334155;
    --dark-text-primary: #e2e8f0;
    --dark-text-secondary: #94a3b8;
    
    /* Spacing Scale */
    --spacing-xs: 0.25rem;   /* 4px */
    --spacing-sm: 0.5rem;    /* 8px */
    --spacing-md: 1rem;      /* 16px */
    --spacing-lg: 1.5rem;    /* 24px */
    --spacing-xl: 2rem;      /* 32px */
    --spacing-2xl: 3rem;     /* 48px */
    
    /* Font Sizes */
    --font-xs: 0.75rem;      /* 12px */
    --font-sm: 0.875rem;     /* 14px */
    --font-base: 1rem;       /* 16px */
    --font-lg: 1.125rem;     /* 18px */
    --font-xl: 1.25rem;      /* 20px */
    --font-2xl: 1.5rem;      /* 24px */
    --font-3xl: 1.875rem;    /* 30px */
    --font-4xl: 2.25rem;     /* 36px */
    
    /* Line Heights */
    --line-tight: 1.25;
    --line-normal: 1.5;
    --line-relaxed: 1.75;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
    --transition-slow: 500ms ease;
    
    /* Border Radius */
    --radius-sm: 0.25rem;    /* 4px */
    --radius-md: 0.5rem;     /* 8px */
    --radius-lg: 0.75rem;    /* 12px */
    --radius-xl: 1rem;       /* 16px */
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    /* Z-index Scale */
    --z-base: 0;
    --z-dropdown: 50;
    --z-sticky: 100;
    --z-overlay: 200;
    --z-modal: 300;
    --z-popover: 400;
    --z-tooltip: 500;
    --z-notification: 600;
}

/* =================================================================
   RESET & BASE STYLES
   ================================================================= */
*:not(:root) {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    font-size: var(--font-base);
    line-height: var(--line-normal);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    overflow-x: hidden;
}

/* =================================================================
   TYPOGRAPHY
   ================================================================= */
h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-weight: 600;
    line-height: var(--line-tight);
    color: var(--text-primary);
}

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

p {
    margin: 0;
    line-height: var(--line-normal);
}

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

a:hover {
    color: var(--color-primary-dark);
    text-decoration: underline;
}

strong, b {
    font-weight: 600;
}

/* =================================================================
   COMMON UTILITIES
   ================================================================= */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }

.bg-primary { background-color: var(--bg-primary); }
.bg-secondary { background-color: var(--bg-secondary); }
.bg-tertiary { background-color: var(--bg-tertiary); }

/* Spacing Utilities */
.mt-xs { margin-top: var(--spacing-xs); }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mt-xl { margin-top: var(--spacing-xl); }

.mb-xs { margin-bottom: var(--spacing-xs); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.mb-xl { margin-bottom: var(--spacing-xl); }

/* =================================================================
   LAYOUT UTILITIES
   ================================================================= */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-xs { gap: var(--spacing-xs); }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }
.gap-lg { gap: var(--spacing-lg); }
.gap-xl { gap: var(--spacing-xl); }

/* =================================================================
   ERROR STATES
   ================================================================= */
.app-error {
    text-align: center;
    padding: 40px;
    color: var(--color-danger);
}

.app-error h1 {
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.app-error p {
    color: var(--text-secondary);
    margin-top: 20px;
}

/* =================================================================
   ANIMATIONS
   ================================================================= */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

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

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideOutDown {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0;
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}

/* Animation Classes */
.animate-fadeIn {
    animation: fadeIn var(--transition-normal);
}

.animate-spin {
    animation: spin 1s linear infinite;
}

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

/* =================================================================
   RESPONSIVE BREAKPOINTS
   ================================================================= */
@media (max-width: 480px) {
    :root {
        --font-base: 0.875rem;  /* 14px on mobile */
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 var(--spacing-sm);
    }
}

/* =================================================================
   LOADING STATES
   ================================================================= */
.app-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.loading-logo {
    width: 80px;
    height: 80px;
    margin-bottom: var(--spacing-lg);
    animation: pulse 2s infinite;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    margin-top: var(--spacing-md);
    color: var(--text-secondary);
    font-size: var(--font-sm);
}

/* =================================================================
   ACCESSIBILITY
   ================================================================= */
:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Ensure good contrast for links in dark theme */
a {
    color: var(--color-primary);
}

a:hover {
    color: var(--color-primary-light);
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* =================================================================
   CONTENT MAX-WIDTH CONSTRAINTS
   ================================================================= */
/* Main content area max-width for all logged-in pages */
.dashboard-view .content-area,
.dashboard-view .view-container,
.dashboard-main .content-area {
    max-width: 1024px !important;
    margin: 0 auto !important;
    width: 100% !important;
    padding: 0 1rem !important;
}

/* Dashboard main wrapper */
.dashboard-main {
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
}

/* View containers - full width for scrollbar positioning */
.checks-view-content,
.checks-landing,
.checks-chat,
.history-container,
.billing-container,
.settings-container,
.profile-container,
.security-container,
.page-content {
    /* Full width to push scrollbar to edge */
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    /* Use padding to center content - preserve vertical padding */
    box-sizing: border-box !important;
}

/* For smaller screens, adjust padding */
@media (max-width: 1024px) {
    .checks-view-content,
    .checks-landing,
    .checks-chat,
    .history-container,
    .billing-container,
    .settings-container,
    .profile-container,
    .security-container,
    .page-content {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

/* Chat specific container - handled by general view containers above */

/* Dashboard wrapper should allow full width for header/nav */
.dashboard-wrapper {
    max-width: none !important;
    width: 100% !important;
}

/* Header and navigation should remain full width */
.dashboard-header,
.header-content,
.app-header,
.nav-menu,
.nav-menu-wrapper {
    max-width: none !important;
    width: 100% !important;
}

/* Content sections - handled by parent container padding */
.content-section,
.form-section,
.subscription-section,
.settings-section,
.security-section,
.usage-section {
    /* Inherit from parent container */
}

/* Landing page, chat, and form containers - inherit from parent */

/* Ensure proper padding on mobile */
@media (max-width: 640px) {
    .dashboard-view .content-area,
    .dashboard-view .view-container,
    .checks-view-content,
    .checks-landing,
    .checks-chat {
        padding: 0 1rem !important;
    }
}

/* Remove any conflicting max-widths from nested elements */
.dashboard-view .content-area > *,
.view-container > * {
    max-width: none !important;
}

/* Exception: Keep modals and overlays full width */
.modal-overlay,
.dialog-overlay,
.payment-modal,
.user-dropdown {
    max-width: none !important;
}

/* =================================================================
   SCROLLBAR STYLING AND BEHAVIOR
   ================================================================= */
/* Global Scrollbar Styling */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.5) rgba(30, 41, 59, 0.5);
}

/* Webkit Scrollbar Styling - Apply to all elements */
::-webkit-scrollbar {
    width: 8px !important;
    height: 8px !important;
}

::-webkit-scrollbar-track {
    background: rgba(30, 41, 59, 0.5) !important;
}

::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.5) !important;
    border-radius: 4px !important;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.7) !important;
}

/* Force scrollbar display on scrollable elements */
body,
html,
.dashboard-view .app-container,
.chat-messages,
.view-container,
.dashboard-main {
    scrollbar-width: thin !important;
    scrollbar-color: rgba(100, 116, 139, 0.5) rgba(30, 41, 59, 0.5) !important;
}

/* Fix overflow to allow scrolling at window edge */
html {
    height: 100% !important;
    overflow: hidden !important;
}

body {
    height: 100% !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* For dashboard views with header and footer */
body.dashboard-view {
    overflow: hidden !important;
    height: 100vh !important;
}

/* Main app container should fill viewport */
#app {
    height: 100vh !important;
    overflow: hidden !important;
    position: relative !important;
}

/* Dashboard view container should be positioned relative for absolute children */
.dashboard-view .app-container {
    position: relative !important;
    height: 100vh !important;
    overflow: hidden !important;
}

/* Main content area between header and footer */
.dashboard-main {
    position: absolute !important;
    top: 60px !important;  /* Position directly below header */
    bottom: 80px !important;  /* Stop at footer */
    left: 0 !important;
    right: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    /* Apply scrollbar styling to main content area */
    scrollbar-width: auto !important;
    scrollbar-color: rgba(100, 116, 139, 0.6) rgba(30, 41, 59, 0.8) !important;
    /* Remove max-width to allow full-width scrolling */
    max-width: none !important;
    width: 100% !important;
    padding: 0 !important;
    /* Ensure scrollbar is flush against edge */
    scrollbar-gutter: stable !important;
}

/* Content area within dashboard-main */
.content-area {
    overflow: visible !important;
    height: auto !important;
    min-height: 100% !important;
}

/* View containers should allow content to flow naturally */
.view-container {
    overflow: visible !important;
    height: auto !important;
}

/* Ensure specific view containers don't restrict height */
.checks-view-content,
.checks-landing,
.checks-chat,
.history-container,
.billing-container,
.settings-container,
.profile-container,
.security-container {
    overflow: visible !important;
    height: auto !important;
}

/* Exception: Chat messages need their own scroll */
.chat-messages {
    overflow-y: auto !important;
    max-height: calc(100vh - 300px) !important;
}

/* Main content area scrollbar styling - Wider and at window edge */
.dashboard-main::-webkit-scrollbar {
    width: 16px !important;
    height: 16px !important;
    background: transparent !important;
}

.dashboard-main::-webkit-scrollbar-track {
    background: rgba(30, 41, 59, 0.8) !important;
    border-radius: 0 !important; /* No rounding at window edge */
    border: none !important;
}

.dashboard-main::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.6) !important;
    border-radius: 0 !important; /* Square edges for window-edge appearance */
    border: none !important;
}

.dashboard-main::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.8) !important;
}

/* Chat messages scrollbar (keep it small and subtle) */
.chat-messages::-webkit-scrollbar {
    width: 8px !important;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(30, 41, 59, 0.3) !important;
    border-radius: 4px !important;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.5) !important;
    border-radius: 4px !important;
}

/* Keep header sticky at top */
.app-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 1000 !important;
}

/* Keep footer at bottom */
.app-footer {
    margin-top: auto !important;
}

/* Modal and overlay scrollbar handling */
.modal-overlay {
    overflow-y: auto !important;
}

.modal {
    max-height: 90vh !important;
    overflow-y: auto !important;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .dashboard-main::-webkit-scrollbar {
        width: 10px !important;
    }
}