/**
 * SAGE - Main Styles and Utilities  
 * Contains global styles, mobile responsiveness, and utility classes
 */

/* Enhanced mobile responsiveness */
@media (max-width: 768px) {
    .main-container {
        padding: 1.5rem;
        margin-top: 2rem;
        margin-bottom: 2rem;
        border-radius: 1.5rem;
    }
    
    .sage-title {
        font-size: 2rem;
    }
    
    .full-name {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }
    
    /* Improve touch targets */
    .action-btn {
        min-height: 48px;
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
        touch-action: manipulation;
    }
    
    input[type="text"], input[type="password"], textarea, select {
        min-height: 48px;
        padding: 1rem 1.25rem;
        font-size: 1rem;
        touch-action: manipulation;
    }
    
    /* Better spacing for mobile */
    .space-y-8 > * + * {
        margin-top: 1.5rem;
    }
    
    /* Optimize button layout on mobile */
    .flex.gap-2.flex-wrap {
        gap: 0.75rem;
    }
    
    .flex.gap-2.flex-wrap .action-btn {
        flex: 1;
        min-width: 140px;
    }
    
    /* Improve question cards on mobile */
    .question-item {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .question-item .math-rendered {
        font-size: 1rem;
        line-height: 1.5;
    }
    
    /* Mobile-specific math symbol sizing */
    .math-symbol {
        font-size: 1.5rem;
    }
    
    /* Better progress bar visibility */
    .progress-bar {
        height: 6px;
        margin: 1.25rem 0;
    }
    
    /* Optimize keyboard shortcuts overlay for mobile */
    .fixed.inset-0 .bg-gray-800 {
        max-height: 90vh;
        overflow-y: auto;
    }
}

@media (max-width: 640px) {
    .main-container {
        padding: 1.25rem;
        margin: 1rem;
        border-radius: 1rem;
    }
    
    .sage-title {
        font-size: 1.8rem;
    }
    
    .full-name {
        font-size: 0.95rem;
    }
    
    /* Stack buttons vertically on small screens */
    .flex.flex-col.sm\\:flex-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    .flex.flex-col.sm\\:flex-row .action-btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Smaller math symbols for very small screens */
    .math-symbol {
        font-size: 1.25rem;
        gap: 0.25rem;
    }
    
    /* Compact question cards */
    .question-item {
        padding: 0.875rem;
    }
    
    .question-item h3 {
        font-size: 1.125rem;
    }
    
    .question-item .math-rendered {
        font-size: 0.9rem;
        line-height: 1.4;
    }
}

/* Touch-specific improvements */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .action-btn:hover {
        transform: none;
        background: inherit;
    }
    
    /* Add press feedback instead */
    .action-btn:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }
    
    /* Improve touch scroll */
    .main-container {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Better touch targets for copy buttons */
    .action-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Utility Classes */
.hidden {
    display: none;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.flex-row {
    flex-direction: row;
}

.items-center {
    align-items: center;
}

.items-start {
    align-items: flex-start;
}

.items-end {
    align-items: flex-end;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-start {
    justify-content: flex-start;
}

.justify-end {
    justify-content: flex-end;
}

.gap-1 {
    gap: 0.25rem;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-3 {
    gap: 0.75rem;
}

.gap-4 {
    gap: 1rem;
}

.flex-wrap {
    flex-wrap: wrap;
}

.flex-1 {
    flex: 1;
}

.grid {
    display: grid;
}

.space-y-8 > * + * {
    margin-top: 2rem;
}

.space-y-4 > * + * {
    margin-top: 1rem;
}

.space-y-2 > * + * {
    margin-top: 0.5rem;
}

/* Text Utilities */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.text-xs {
    font-size: 0.75rem;
}

.text-sm {
    font-size: 0.875rem;
}

.text-base {
    font-size: 1rem;
}

.text-lg {
    font-size: 1.125rem;
}

.text-xl {
    font-size: 1.25rem;
}

.text-2xl {
    font-size: 1.5rem;
}

.font-medium {
    font-weight: 500;
}

.font-semibold {
    font-weight: 600;
}

.font-bold {
    font-weight: 700;
}

/* Margin and Padding Utilities */
.m-0 {
    margin: 0;
}

.mb-1 {
    margin-bottom: 0.25rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-3 {
    margin-bottom: 0.75rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.mb-6 {
    margin-bottom: 1.5rem;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.p-2 {
    padding: 0.5rem;
}

.p-4 {
    padding: 1rem;
}

.px-2 {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

.px-3 {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.py-1 {
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
}

.py-2 {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

/* Border Utilities */
.rounded {
    border-radius: 0.25rem;
}

.rounded-lg {
    border-radius: 0.5rem;
}

.rounded-full {
    border-radius: 9999px;
}

/* Position Utilities */
.fixed {
    position: fixed;
}

.absolute {
    position: absolute;
}

.relative {
    position: relative;
}

.top-4 {
    top: 1rem;
}

.right-4 {
    right: 1rem;
}

.left-4 {
    left: 1rem;
}

/* Z-index Utilities */
.z-50 {
    z-index: 50;
}

.z-40 {
    z-index: 40;
}

.z-30 {
    z-index: 30;
}

/* Shadow Utilities */
.shadow-lg {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.shadow-sm {
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

/* Overflow Utilities */
.overflow-hidden {
    overflow: hidden;
}

.overflow-x-auto {
    overflow-x: auto;
}

.overflow-y-auto {
    overflow-y: auto;
}

/* Transform Utilities */
.transform {
    transform: translateX(var(--tw-translate-x, 0)) translateY(var(--tw-translate-y, 0)) rotate(var(--tw-rotate, 0)) skewX(var(--tw-skew-x, 0)) skewY(var(--tw-skew-y, 0)) scaleX(var(--tw-scale-x, 1)) scaleY(var(--tw-scale-y, 1));
}

.translate-x-full {
    --tw-translate-x: 100%;
}

.-translate-x-1\/2 {
    --tw-translate-x: -50%;
}

.transition-all {
    transition-property: all;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 150ms;
}

.transition-colors {
    transition-property: color, background-color, border-color, text-decoration-color, fill, stroke;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 150ms;
}

.duration-300 {
    transition-duration: 300ms;
}

/* Display Utilities */
.block {
    display: block;
}

.inline {
    display: inline;
}

.inline-block {
    display: inline-block;
}

.inline-flex {
    display: inline-flex;
}

/* Width and Height Utilities */
.w-full {
    width: 100%;
}

.w-auto {
    width: auto;
}

.h-full {
    height: 100%;
}

.min-h-screen {
    min-height: 100vh;
}

/* Color Text Utilities (These will use CSS custom properties) */
.text-red-400 {
    color: var(--accent);
}

.text-red-500 {
    color: var(--accent-hover);
}

.text-gray-200 {
    color: var(--text-primary);
}

.text-gray-400 {
    color: var(--text-secondary);
}

.text-gray-500 {
    color: var(--text-muted);
}

.text-white {
    color: #ffffff;
}

/* Background Color Utilities */
.bg-red-600 {
    background-color: var(--accent);
}

.bg-gray-800 {
    background-color: var(--surface);
}

/* Responsive prefixes for mobile-first design */
@media (min-width: 640px) {
    .sm\\:flex-row {
        flex-direction: row;
    }
    
    .sm\\:grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    
    .sm\\:grid-cols-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (min-width: 768px) {
    .md\\:grid-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .lg\\:grid-cols-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* Model Selector and Cost Tracking Styles */
.model-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--surface-secondary);
    border-radius: 0.5rem;
    border-left: 3px solid var(--accent);
}

.cost-estimate-container {
    background: var(--surface-secondary);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-top: 1rem;
    border: 1px solid var(--border);
}

.cost-estimate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.cost-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.cost-value {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent);
    font-family: 'Courier New', monospace;
}

.budget-info {
    margin-top: 0.5rem;
}

.budget-bar {
    width: 100%;
    height: 8px;
    background: var(--surface);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.budget-progress {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444);
    transition: width 0.3s ease;
    border-radius: 4px;
}

.budget-text {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.budget-settings-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease;
}

.budget-settings-btn:hover {
    background: var(--surface);
    color: var(--text-primary);
}

/* Budget over-limit warning */
.budget-progress.over-budget {
    background: #ef4444;
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Usage Analytics Styles */
.usage-analytics {
    background: var(--surface-secondary);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-top: 1rem;
    border: 1px solid var(--border);
}

.usage-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.usage-stat:last-child {
    border-bottom: none;
}

.usage-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.usage-value {
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
}

.model-breakdown {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.model-stat {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 0.5rem;
    padding: 0.5rem;
    margin: 0.25rem 0;
    background: var(--surface);
    border-radius: 0.5rem;
    font-size: 0.875rem;
}

.model-name {
    font-weight: 600;
    color: var(--text-primary);
}

.model-requests, .model-tokens, .model-cost {
    font-family: 'Courier New', monospace;
    color: var(--text-secondary);
    text-align: right;
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
    .cost-estimate-container {
        padding: 0.75rem;
    }

    .cost-estimate-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .budget-text {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .model-stat {
        grid-template-columns: 1fr;
        text-align: left;
    }

    .model-requests, .model-tokens, .model-cost {
        text-align: left;
    }
}

/* Usage Analytics Modal Styles */
.usage-analytics-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.usage-analytics-modal.show {
    opacity: 1;
    visibility: visible;
}

.usage-analytics-content {
    background: var(--surface);
    border-radius: 1rem;
    width: 90vw;
    max-width: 900px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.usage-analytics-modal.show .usage-analytics-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-secondary);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: var(--surface);
    color: var(--text-primary);
}

.usage-analytics-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.analytics-section {
    margin-bottom: 2rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--surface-secondary);
    border-radius: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--border);
    transition: transform 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    font-family: 'Courier New', monospace;
}

.budget-progress-large {
    width: 100%;
    height: 20px;
    background: var(--surface);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

.budget-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444);
    transition: width 0.3s ease;
    border-radius: 10px;
}

.budget-status-text {
    margin-bottom: 1rem;
}

.budget-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.budget-info-row:last-child {
    border-bottom: none;
}

.budget-actions, .export-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.model-breakdown-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
}

.model-breakdown-card {
    background: var(--surface-secondary);
    border-radius: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--border);
}

.model-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.model-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.model-card-cost {
    font-weight: 700;
    color: var(--accent);
    font-family: 'Courier New', monospace;
}

.model-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
}

.model-stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.model-stat-value {
    color: var(--text-primary);
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

/* Font utilities */
.font-mono {
    font-family: 'Courier New', monospace;
}

/* Text color utilities */
.text-red-500 { color: #ef4444; }
.text-yellow-500 { color: #eab308; }
.text-green-500 { color: #22c55e; }

/* Theme-aware text color utilities */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .usage-analytics-content {
        width: 95vw;
        max-height: 95vh;
    }

    .modal-header {
        padding: 1rem;
    }

    .usage-analytics-body {
        padding: 1rem;
    }

    .analytics-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .model-breakdown-grid {
        grid-template-columns: 1fr;
    }

    .budget-actions, .export-actions {
        flex-direction: column;
    }

    .budget-info-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
}