/* ===============================================
   PERCENTAGE CALCULATOR - OPTIMIZED STYLES
   =============================================== */

/* Consolidated CSS custom properties for better performance */
:root {
    /* Primary color system */
    --primary-color: #3B82F6;
    --secondary-color: #10B981;
    --accent-color: #8B5CF6;
    
    /* Text colors */
    --text-color: #111827;
    --text-secondary: #4B5563;
    --text-tertiary: #6B7280;
    
    /* Background colors */
    --bg-primary: #FFFFFF;
    --bg-secondary: #F9FAFB;
    --bg-tertiary: #F3F4F6;
    
    /* Utility colors */
    --border-color: #E5E7EB;
    --danger-color: #EF4444;
    --success-color: #10B981;
    --warning-color: #F59E0B;
    
    /* Percentage-specific colors */
    --percentage-positive: #10B981;
    --percentage-negative: #EF4444;
    --percentage-neutral: #6B7280;
    
    /* Shadows and borders - optimized */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-base: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    /* Gray scale - simplified */
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
}

/* Dark theme using optimized color variables */
[data-theme="dark"] {
    --text-color: #F9FAFB;
    --text-secondary: #D1D5DB;
    --text-tertiary: #9CA3AF;
    --bg-primary: #111827;
    --bg-secondary: #1F2937;
    --bg-tertiary: #374151;
    --border-color: #374151;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    --gray-100: #374151;
    --gray-200: #4B5563;
    --gray-300: #6B7280;
    --gray-400: #9CA3AF;
}

/* Optimized body styles */
body {
    background: var(--bg-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Hero section - simplified for better performance */
.tool-hero {
    margin-top: 0;
    padding: 120px 0 80px;
    position: relative;
    background: linear-gradient(135deg, var(--bg-primary) 0%, rgba(59, 130, 246, 0.1) 30%, rgba(16, 185, 129, 0.1) 70%, var(--bg-primary) 100%);

}

/* Simplified hero background effect */
.tool-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--bg-tertiary);
    opacity: 0.3;
    pointer-events: none;
}

.hero-content {
    text-align: center;
    max-width: 700px;
    margin: 0 auto;
    position: relative;
    z-index: 3;
}

.hero-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: var(--radius-2xl);
    display: flex;
    align-items: center;    justify-content: center;
    margin: 0 auto 2rem;
}

.hero-icon i {
    font-size: 2.5rem;
    color: white;
}

.hero-content h1 {
    font-size: clamp(2.5rem, 5vw, 3.5rem);
    font-weight: 800;
    color: var(--text-color);
    margin-bottom: 1.5rem;
    line-height: 1.1;
}

.hero-content p {
    font-size: 1.25rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* ===============================================
   CALCULATOR MAIN SECTION
   =============================================== */

.calculator-main {
    padding: 80px 0 120px;
    background: var(--bg-primary);
    position: relative;
}

.calculator-container {
    max-width: 900px;    margin: 0 auto;
    background: var(--bg-primary);
    border-radius: var(--radius-2xl);
    border: 1px solid var(--border-color);
    overflow: hidden;
    position: relative;
}

.calculator-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary-color);
}

/* Optimized calculator tabs */
.calculator-tabs {
    display: flex;
    flex-wrap: wrap;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 2px;
}

.calculator-tabs::-webkit-scrollbar {
    display: none;
}

/* Optimized tab button */
.tab-button {
    flex: 1 1 140px;
    max-width: 200px;
    padding: 1rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    position: relative;
    text-align: center;
    line-height: 1.3;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    will-change: transform;
}

.tab-button:hover {
    background: var(--bg-tertiary);
    color: var(--text-color);
}

.tab-button.active {
    color: var(--primary-color);
    background: var(--bg-primary);
    font-weight: 600;
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-color);
}

/* ===============================================
   CALCULATOR CARD
   =============================================== */

.calculator-card {
    padding: 2.5rem;
}

/* ===============================================
   DISPLAY AREA
   =============================================== */

.calculator-display {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-radius: var(--radius-xl);
    padding: 2rem;
    margin-bottom: 2.5rem;
    border: 1px solid var(--border-color);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.calculator-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-tertiary);
    opacity: 0.3;
    pointer-events: none;
}

.display-result {
    position: relative;
    z-index: 2;
    margin-bottom: 1rem;
}

.result-value {
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: 800;
    color: var(--primary-color);
    line-height: 1;
    display: inline-block;
}

.result-unit {
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 600;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

.display-formula {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
    position: relative;
    z-index: 2;
}

/* ===============================================
   INPUT SECTIONS
   =============================================== */

.calculator-inputs {
    position: relative;
}

.input-section {
    display: none;
}

.input-section.active {
    display: block;
}

.section-info {
    text-align: center;
    margin-bottom: 2.5rem;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.section-info h3 {
    color: var(--text-color);
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.section-info h3 i {
    color: var(--primary-color);
}

.section-info p {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.5;
    margin: 0;
}

/* Optimized form inputs */
.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-color);
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

.help-icon {
    position: relative;
    cursor: help;
    color: var(--text-tertiary);
    font-size: 0.875rem;
}

.help-icon:hover {
    color: var(--primary-color);
}

/* Optimized form input with reduced transitions */
.form-input {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color);
    background: var(--bg-primary);
    will-change: border-color;
    min-height: 44px; /* Touch-friendly minimum */
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-input:hover {
    border-color: var(--primary-color);
}

.form-input::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

/* Input with currency/unit styling */
.input-with-currency,
.input-with-unit {
    position: relative;
    display: flex;
    align-items: center;
}

.currency-symbol,
.input-unit {
    position: absolute;
    color: var(--text-secondary);
    font-weight: 600;
    pointer-events: none;
    z-index: 2;
}

.currency-symbol {
    left: 1rem;
}

.input-unit {
    right: 1rem;
}

.input-with-currency .form-input {
    padding-left: 2.5rem;
}

.input-with-unit .form-input {
    padding-right: 2.5rem;
}

/* ===============================================
   CALCULATION TYPE SELECTOR (RADIO BUTTONS)
   =============================================== */

.calculation-type-selector {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.75rem;    border-radius: var(--radius-base);
}

.radio-option:hover {
    background: var(--bg-tertiary);
}

.radio-option input[type="radio"] {
    display: none;
}

.radio-custom {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    position: relative;
    min-width: 20px;
}

.radio-option input[type="radio"]:checked + .radio-custom {
    border-color: var(--primary-color);
    background: var(--primary-color);
}

.radio-option input[type="radio"]:checked + .radio-custom::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
}

.radio-text {
    color: var(--text-color);
    font-weight: 500;
    font-size: 0.95rem;
}

/* ===============================================
   TIP PRESETS
   =============================================== */

.tip-presets {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.preset-btn {
    flex: 1;
    min-width: 60px;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);    color: var(--text-color);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    min-height: 44px; /* Touch-friendly */
}

.preset-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.preset-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

/* Optimized results preview */
.results-preview {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-top: 1.5rem;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.result-item:last-child {
    border-bottom: none;
}

.result-label {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.95rem;
}

.result-item .result-value {
    color: var(--text-color);
    font-weight: 700;
    font-size: 1.1rem;
}

/* Optimized grade letter styles */
.grade-letter {
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-base);
    font-weight: 700;
    font-size: 0.95rem;
}

.grade-letter.grade-a { background: var(--success-color); color: white; }
.grade-letter.grade-b { background: var(--primary-color); color: white; }
.grade-letter.grade-c { background: var(--warning-color); color: white; }
.grade-letter.grade-d { background: var(--text-tertiary); color: white; }
.grade-letter.grade-f { background: var(--danger-color); color: white; }
.grade-letter.grade-b { background: var(--info-color); color: white; }
.grade-letter.grade-c { background: var(--warning-color); color: white; }
.grade-letter.grade-d { background: #F97316; color: white; }
.grade-letter.grade-f { background: var(--danger-color); color: white; }

/* ===============================================
   ACTION BUTTONS
   =============================================== */

.calculator-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2.5rem;
    flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
    flex: 1;
    min-width: 140px;
    padding: 1rem 2rem;
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    min-height: 44px; /* Touch-friendly */
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-color);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-color);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* ===============================================
   RESPONSIVE DESIGN
   =============================================== */

@media (max-width: 768px) {
    .calculator-card {
        padding: 1.5rem;
    }
    
    .calculator-tabs {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1px;
    }
    
    .tab-button {
        min-width: unset;
        max-width: unset;
        text-align: center;
        padding: 0.875rem 0.5rem;
        font-size: 0.8rem;
        min-height: 56px;
        border-radius: 0;
    }
    
    .calculator-actions {
        flex-direction: column;
    }
    
    .btn-primary,
    .btn-secondary {
        min-width: unset;
    }
    
    .tip-presets {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .calculation-type-selector {
        padding: 1rem;
    }
    
    .section-info {
        padding: 1rem;
    }
    
    .section-info h3 {
        font-size: 1.25rem;
        flex-direction: column;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .hero-content h1 {
        font-size: 2rem;
    }
    
    .hero-content p {
        font-size: 1rem;
    }
    
    .calculator-main {
        padding: 40px 0 80px;
    }
    
    .tool-hero {
        padding: 100px 0 60px;
    }
    
    .result-value {
        font-size: 2.5rem;
    }
    
    .result-unit {
        font-size: 1.5rem;
    }
    
    .calculator-tabs {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 1px;
    }
    
    .tab-button {
        font-size: 0.75rem;
        padding: 0.75rem 0.25rem;
        min-height: 50px;
        line-height: 1.2;
    }
}

/* ===============================================
   ACCESSIBILITY IMPROVEMENTS
   =============================================== */

/* Focus indicators for keyboard navigation */
.tab-button:focus,
.form-input:focus,
.btn-primary:focus,
.btn-secondary:focus,
.preset-btn:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .calculator-container {
        border: 2px solid var(--text-color);
    }
    
    .form-input {
        border-width: 2px;
    }
    
    .btn-primary,
    .btn-secondary {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .hero-icon {
        animation: none;
    }
}

/* Optimized tooltip styles */
.help-icon[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    padding: 8px 12px;
    background: var(--text-color);
    color: var(--bg-primary);
    border-radius: var(--radius-base);
    font-size: 0.8rem;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

.help-icon[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 2px;
    border: 4px solid transparent;
    border-top-color: var(--text-color);
    z-index: 1000;
}

/* Optimized focus styles */
.tab-button:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast support */
@media (prefers-contrast: high) {
    .tab-button {
        border: 1px solid currentColor;
    }
}
