/* START CUSTOM STYLES */
/**
 * Custom CSS for Sig Fig Calculator
 * Extends Tailwind CSS with custom styles and accessibility improvements
 */

/* Font Configuration */
.font-inter {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Focus States for Better Accessibility */
.focus-visible:focus {
    outline: 2px solid #3B82F6;
    outline-offset: 2px;
}

/* Skip to Content Link */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.focus\:not-sr-only:focus {
    position: static !important;
    width: auto !important;
    height: auto !important;
    padding: 0.5rem 1rem !important;
    margin: 0 !important;
    overflow: visible !important;
    clip: auto !important;
    white-space: normal !important;
}

/* Calculator Specific Styles */
.calculator-result {
    transition: all 0.2s ease-in-out;
}

.calculator-result:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Copy Button Animations */
.copy-button {
    transition: all 0.15s ease-in-out;
}

.copy-button:hover {
    background-color: #F3F4F6;
    transform: scale(1.05);
}

.copy-button:active {
    transform: scale(0.95);
}

/* Form Input Enhancements */
input[type="text"], 
input[type="number"], 
select {
    transition: all 0.15s ease-in-out;
}

input[type="text"]:focus, 
input[type="number"]:focus, 
select:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Radio Button Custom Styling */
input[type="radio"]:checked {
    background-color: #3B82F6;
    border-color: #3B82F6;
}

input[type="radio"]:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Table Enhancements */
table {
    border-collapse: collapse;
}

tbody tr:hover {
    background-color: #F9FAFB;
}

/* Smooth Scroll */
html {
    scroll-behavior: smooth;
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #3B82F6;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Ad Container Styling */
.ad-container {
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #F9FAFB;
    border: 1px dashed #D1D5DB;
    border-radius: 0.5rem;
    color: #6B7280;
    font-size: 0.875rem;
}

.ad-container:empty::after {
    content: 'Advertisement Space';
}

/* Mobile Menu Animation */
#mobile-menu {
    transition: all 0.2s ease-in-out;
    max-height: 0;
    overflow: hidden;
}

#mobile-menu:not(.hidden) {
    max-height: 200px;
}

/* Article Content Styling */
article h2 {
    scroll-margin-top: 100px;
}

article h3 {
    scroll-margin-top: 100px;
}

/* Code Block Styling */
code {
    font-family: 'SF Mono', Monaco, Inconsolata, 'Roboto Mono', 'Source Code Pro', monospace;
    font-size: 0.875em;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .bg-gray-50 {
        background-color: #ffffff;
    }
    
    .border-gray-200 {
        border-color: #000000;
    }
    
    .text-gray-600 {
        color: #000000;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    html {
        scroll-behavior: auto;
    }
}

/* Print Styles */
@media print {
    .no-print,
    header,
    footer,
    .ad-container,
    button {
        display: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
        line-height: 1.4;
    }
    
    .bg-white {
        background: white !important;
    }
    
    .shadow-sm {
        box-shadow: none !important;
    }
    
    .border {
        border: 1px solid #000 !important;
    }
    
    a::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    .grid {
        display: block !important;
    }
    
    .lg\:col-span-3,
    .lg\:col-span-1 {
        width: 100% !important;
        display: block !important;
    }
}

/* Dark Mode Support (Optional) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1F2937;
        --bg-secondary: #374151;
        --text-primary: #F9FAFB;
        --text-secondary: #D1D5DB;
        --border-color: #4B5563;
    }
    
    /* Uncomment to enable dark mode */
    /*
    body {
        background-color: var(--bg-primary);
        color: var(--text-primary);
    }
    
    .bg-white {
        background-color: var(--bg-secondary) !important;
    }
    
    .text-gray-900 {
        color: var(--text-primary) !important;
    }
    
    .text-gray-600 {
        color: var(--text-secondary) !important;
    }
    
    .border-gray-200 {
        border-color: var(--border-color) !important;
    }
    */
}

/* Utility Classes */
.text-balance {
    text-wrap: balance;
}

.text-pretty {
    text-wrap: pretty;
}

/* Custom Animation Classes */
.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Component-Specific Styles */
.calculator-section {
    position: relative;
}

.result-section {
    position: relative;
    z-index: 10;
}

.copy-success {
    animation: copySuccess 0.3s ease-in-out;
}

@keyframes copySuccess {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
        background-color: #10B981;
        color: white;
    }
    100% {
        transform: scale(1);
    }
}

/* Responsive Typography */
@media (max-width: 640px) {
    .text-4xl {
        font-size: 2rem;
        line-height: 2.5rem;
    }
    
    .text-3xl {
        font-size: 1.75rem;
        line-height: 2.25rem;
    }
    
    .text-2xl {
        font-size: 1.5rem;
        line-height: 2rem;
    }
}

/* Error State Animations */
.error-shake {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}

/* Success State Animations */
.success-pulse {
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

/* Form Validation States */
.field-valid {
    border-color: #10B981;
    background-color: #F0FDF4;
}

.field-invalid {
    border-color: #EF4444;
    background-color: #FEF2F2;
}

.field-valid:focus {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.field-invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Accessibility Improvements */
.visually-hidden {
    position: absolute !important;
    clip: rect(1px, 1px, 1px, 1px) !important;
    padding: 0 !important;
    border: 0 !important;
    height: 1px !important;
    width: 1px !important;
    overflow: hidden !important;
}

/* Focus Management */
.focus-trap:focus {
    outline: 2px solid #3B82F6;
    outline-offset: 2px;
}

/* Loading Skeleton */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Performance Optimizations */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* Calculator Interface Styles */
.calculator-container {
    font-family: 'Inter', sans-serif;
}

.calculator-screen {
    background: linear-gradient(145deg, #1a1a1a, #2d2d2d);
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
    border: 1px solid #333;
}

.calc-btn {
    height: 48px;
    font-weight: 600;
    font-size: 16px;
    border-radius: 8px;
    border: none;
    transition: all 0.15s ease;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    user-select: none;
}

.calc-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.calc-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Primary button (Calculate) */
.calc-btn.primary {
    background: linear-gradient(145deg, #3B82F6, #2563EB);
    color: white;
    font-size: 14px;
    font-weight: 700;
}

.calc-btn.primary:hover {
    background: linear-gradient(145deg, #2563EB, #1D4ED8);
}

/* Secondary buttons (functions) */
.calc-btn.secondary {
    background: linear-gradient(145deg, #F3F4F6, #E5E7EB);
    color: #374151;
    font-size: 14px;
}

.calc-btn.secondary:hover {
    background: linear-gradient(145deg, #E5E7EB, #D1D5DB);
}

/* Number buttons */
.calc-btn:not(.secondary):not(.primary) {
    background: linear-gradient(145deg, #FFFFFF, #F9FAFB);
    color: #1F2937;
    border: 1px solid #E5E7EB;
}

.calc-btn:not(.secondary):not(.primary):hover {
    background: linear-gradient(145deg, #F9FAFB, #F3F4F6);
}

/* Wide buttons */
.calc-btn.wide {
    grid-column: span 2;
}

/* Example buttons */
.example-btn {
    padding: 6px 12px;
    background: #DBEAFE;
    color: #1D4ED8;
    border: 1px solid #93C5FD;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.15s ease;
    cursor: pointer;
}

.example-btn:hover {
    background: #BFDBFE;
    transform: translateY(-1px);
}

/* Display styling */
#display {
    background: transparent !important;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

#display::placeholder {
    color: #6B7280;
    opacity: 0.7;
}

/* Live calculation display */
#live-calculation {
    min-height: 20px;
    font-family: 'SF Mono', Monaco, monospace;
}

/* Mode selector */
.mode-selector {
    background: linear-gradient(145deg, #F9FAFB, #F3F4F6);
    border: 1px solid #E5E7EB;
}

/* Form radio styling */
.form-radio:checked {
    background-color: #3B82F6;
    border-color: #3B82F6;
}

/* Calculator results enhancement */
.result-display {
    background: linear-gradient(145deg, #F0FDF4, #DCFCE7);
    border: 2px solid #16A34A;
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
}

.result-value {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 24px;
    font-weight: 700;
    color: #15803D;
    background: #FFFFFF;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #BBF7D0;
    display: inline-block;
    margin: 8px 0;
}

.result-explanation {
    background: #FFFFFF;
    padding: 12px;
    border-radius: 8px;
    border-left: 4px solid #16A34A;
    margin-top: 12px;
    font-size: 14px;
    line-height: 1.5;
}

/* Animation for calculator */
@keyframes buttonPress {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.calc-btn:active {
    animation: buttonPress 0.1s ease-in-out;
}

/* Responsive calculator */
@media (max-width: 640px) {
    .calculator-buttons {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }
    
    .calc-btn {
        height: 40px;
        font-size: 14px;
    }
    
    .calc-btn.wide {
        grid-column: span 2;
    }
    
    #display {
        font-size: 18px;
    }
}

/* Accessibility improvements */
.calc-btn:focus {
    outline: 2px solid #3B82F6;
    outline-offset: 2px;
}

/* Dark mode support for calculator */
@media (prefers-color-scheme: dark) {
    .calculator-screen {
        background: linear-gradient(145deg, #0F172A, #1E293B);
        border-color: #475569;
    }
    
    .mode-selector {
        background: linear-gradient(145deg, #1E293B, #334155);
        border-color: #475569;
    }
}

/* History and help modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 24px;
    border-radius: 12px;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Calculator button grid improvements */
.calculator-buttons button[data-number] {
    background: linear-gradient(145deg, #FFFFFF, #F8FAFC);
    border: 1px solid #E2E8F0;
    color: #1A202C;
    font-weight: 600;
}

.calculator-buttons button[data-number]:hover {
    background: linear-gradient(145deg, #F8FAFC, #F1F5F9);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Quick examples styling */
.quick-examples {
    border: 1px solid #BFDBFE;
}

.quick-examples h4 {
    margin-bottom: 8px;
    font-weight: 600;
}

/* END CUSTOM STYLES */
