/* ===================================
   MODERN CALCULATOR DESIGN SYSTEM
   ================================== */

/* CSS Variables for Design System */
:root {
    /* Primary Colors */
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --primary-dark: #1e40af;
    
    /* Secondary Colors */
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --secondary-light: #f1f5f9;
    
    /* Accent Colors */
    --accent-color: #10b981;
    --accent-hover: #059669;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --success-color: #22c55e;
    
    /* Neutral Colors */
    --white: #ffffff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    
    /* Typography */
    --font-family-primary: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-family-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    
    /* Font Sizes */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    
    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --space-20: 5rem;
    
    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
    --radius-2xl: 1rem;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Transitions */
    --transition-fast: 150ms ease-in-out;
    --transition-normal: 250ms ease-in-out;
    --transition-slow: 350ms ease-in-out;
}

/* Dark Mode Variables */
[data-theme="dark"] {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #1e3a8a;
    --secondary-color: #94a3b8;
    --secondary-light: #1e293b;
    --white: #0f172a;
    --gray-50: #0f172a;
    --gray-100: #1e293b;
    --gray-200: #334155;
    --gray-300: #475569;
    --gray-800: #f1f5f9;
    --gray-900: #f8fafc;
}

/* ===================================
   GLOBAL STYLES
   ================================== */

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-family-primary);
    line-height: 1.6;
    color: var(--gray-800);
    background-color: var(--gray-50);
}

/* ===================================
   LAYOUT COMPONENTS
   ================================== */

.modern-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.modern-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-4);
}

.modern-grid {
    display: grid;
    gap: var(--space-6);
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .modern-grid {
        grid-template-columns: 1fr 300px;
    }
}

@media (min-width: 1024px) {
    .modern-grid {
        grid-template-columns: 1fr 350px;
    }
}

/* Main Content Area */
.main-content {
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--space-8);
    margin: var(--space-6) 0;
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.sidebar-card {
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    padding: var(--space-6);
    border: 1px solid var(--gray-200);
}

/* ===================================
   CALCULATOR COMPONENTS
   ================================== */

.calculator-container {
    background: var(--white);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    padding: var(--space-8);
    margin: var(--space-6) 0;
    border: 1px solid var(--gray-200);
    position: relative;
    overflow: hidden;
}

.calculator-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
}

.calculator-header {
    text-align: center;
    margin-bottom: var(--space-8);
}

.calculator-title {
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: var(--space-2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
}

.calculator-description {
    font-size: var(--text-lg);
    color: var(--gray-600);
    max-width: 600px;
    margin: 0 auto;
}

/* Input Groups */
.input-group {
    margin-bottom: var(--space-6);
}

.input-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: var(--space-2);
}

.input-field {
    width: 100%;
    padding: var(--space-4);
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-lg);
    font-size: var(--text-base);
    transition: all var(--transition-fast);
    background: var(--white);
    color: var(--gray-900);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.input-field:invalid {
    border-color: var(--error-color);
}

.input-field:invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Input Row Layout */
.input-row {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;
    margin-bottom: var(--space-6);
}

@media (min-width: 640px) {
    .input-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .input-row.three-cols {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-6);
    border: none;
    border-radius: var(--radius-lg);
    font-size: var(--text-base);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: var(--white);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-800);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-300);
}

.btn-success {
    background: var(--success-color);
    color: var(--white);
}

.btn-success:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-warning {
    background: var(--warning-color);
    color: var(--white);
}

.btn-danger {
    background: var(--error-color);
    color: var(--white);
}

.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: var(--text-lg);
}

.btn-sm {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
}

/* Button Groups */
.btn-group {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    justify-content: center;
    margin: var(--space-6) 0;
}

/* Results Section */
.results-section {
    background: linear-gradient(135deg, var(--primary-light), var(--secondary-light));
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    margin: var(--space-8) 0;
    border: 1px solid var(--primary-color);
    position: relative;
}

.results-title {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: var(--space-6);
    text-align: center;
}

.results-grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .results-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .results-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.result-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    text-align: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-200);
    transition: all var(--transition-fast);
}

.result-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.result-label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: var(--space-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--primary-color);
    font-family: var(--font-family-mono);
}

.result-unit {
    font-size: var(--text-sm);
    color: var(--gray-500);
    margin-top: var(--space-1);
}

/* Calculator Display */
.calculator-display {
    background: var(--gray-900);
    color: var(--white);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
    font-family: var(--font-family-mono);
    font-size: var(--text-2xl);
    text-align: right;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    border: 2px solid var(--gray-700);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Calculator Button Grid */
.calculator-grid {
    display: grid;
    gap: var(--space-3);
    grid-template-columns: repeat(4, 1fr);
}

.calculator-grid.scientific {
    grid-template-columns: repeat(5, 1fr);
}

@media (max-width: 640px) {
    .calculator-grid.scientific {
        grid-template-columns: repeat(4, 1fr);
    }
}

.calc-btn {
    aspect-ratio: 1;
    border: none;
    border-radius: var(--radius-lg);
    font-size: var(--text-lg);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
}

.calc-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.calc-btn:active {
    transform: translateY(0);
}

.calc-btn.number {
    background: var(--gray-200);
    color: var(--gray-900);
}

.calc-btn.number:hover {
    background: var(--gray-300);
}

.calc-btn.operator {
    background: var(--primary-color);
    color: var(--white);
}

.calc-btn.operator:hover {
    background: var(--primary-hover);
}

.calc-btn.function {
    background: var(--secondary-color);
    color: var(--white);
    font-size: var(--text-base);
}

.calc-btn.function:hover {
    background: var(--secondary-hover);
}

.calc-btn.equals {
    background: var(--accent-color);
    color: var(--white);
}

.calc-btn.equals:hover {
    background: var(--accent-hover);
}

.calc-btn.clear {
    background: var(--error-color);
    color: var(--white);
}

/* Tabs */
.tab-container {
    margin-bottom: var(--space-8);
}

.tab-list {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: var(--space-6);
    overflow-x: auto;
    gap: var(--space-2);
}

.tab-button {
    padding: var(--space-3) var(--space-6);
    border: none;
    background: none;
    color: var(--gray-600);
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
    white-space: nowrap;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tab-button:hover {
    color: var(--primary-color);
    background: var(--gray-100);
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: var(--primary-light);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Info Sections */
.info-section {
    background: var(--gray-100);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    margin: var(--space-8) 0;
    border-left: 4px solid var(--primary-color);
}

.info-title {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.info-content {
    color: var(--gray-700);
    line-height: 1.7;
}

.info-content ul {
    margin: var(--space-4) 0;
    padding-left: var(--space-6);
}

.info-content li {
    margin-bottom: var(--space-2);
}

/* Formula Display */
.formula-display {
    background: var(--gray-900);
    color: var(--white);
    padding: var(--space-6);
    border-radius: var(--radius-lg);
    font-family: var(--font-family-mono);
    font-size: var(--text-lg);
    text-align: center;
    margin: var(--space-6) 0;
    border: 2px solid var(--primary-color);
    box-shadow: var(--shadow-md);
}

/* Progress Bars */
.progress-bar {
    width: 100%;
    height: 12px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: var(--space-4) 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    border-radius: var(--radius-full);
    transition: width var(--transition-slow);
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Alerts */
.alert {
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    margin: var(--space-4) 0;
    border: 1px solid;
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border-color: var(--success-color);
    color: #166534;
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: var(--warning-color);
    color: #92400e;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--error-color);
    color: #991b1b;
}

/* Loading States */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-300);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
}

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

/* Responsive Design */
@media (max-width: 640px) {
    .modern-container {
        padding: 0 var(--space-3);
    }
    
    .main-content {
        padding: var(--space-6);
        margin: var(--space-4) 0;
    }
    
    .calculator-container {
        padding: var(--space-6);
        margin: var(--space-4) 0;
    }
    
    .calculator-title {
        font-size: var(--text-2xl);
    }
    
    .btn-group {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .results-grid {
        grid-template-columns: 1fr;
    }
    
    .calculator-grid {
        gap: var(--space-2);
    }
    
    .calc-btn {
        min-height: 50px;
        font-size: var(--text-base);
    }
}

/* Print Styles */
@media print {
    .sidebar,
    .btn-group,
    .tab-list {
        display: none;
    }
    
    .main-content,
    .calculator-container {
        box-shadow: none;
        border: 1px solid var(--gray-300);
    }
    
    .results-section {
        background: var(--white);
        border: 1px solid var(--gray-300);
    }
}

/* Dark Mode Toggle */
.theme-toggle {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: 1000;
    background: var(--white);
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-full);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-lg);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-xl);
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !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: 0;
}

/* Focus Styles */
.btn:focus-visible,
.input-field:focus-visible,
.tab-button:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
