:root {
    --primary: #1e3a8a;
    --secondary: #f59e0b;
    --bg-color: #ffffff;
    --text-color: #1f2937;
    --card-bg: #f8fafc;
    --input-bg: #ffffff;
    --border-color: #e2e8f0;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --radius: 12px;
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
}

:root[style*="--mode: dark"] {
    --primary: #3b82f6;
    --secondary: #fbbf24;
    --bg-color: #111827;
    --text-color: #f3f4f6;
    --card-bg: #1f2937;
    --input-bg: #374151;
    --border-color: #4b5563;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Mobile First - Reset & Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-color);
}

/* Main Container */
.emi-calculator-wrapper {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: var(--spacing-md);
    background: var(--bg-color);
    min-height: 100vh;
}

/* Mode Toggle - Mobile Optimized */
.emi-toggle-mode {
    /*position: fixed;*/
    top: 16px;
    right: 16px;
    z-index: 100;
}

.mode-toggle-btn {
    background: var(--primary);
    color: white;
    border: none;
    /*padding: 10px 16px;*/
    border-radius: 50px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow);
    /*min-width: 130px;*/
    justify-content: center;
    transition: all 0.3s ease;
    touch-action: manipulation;
}

.mode-toggle-btn:active {
    transform: scale(0.95);
}

.mode-icon {
    font-size: 16px;
}

/* Main Calculator Grid - Mobile First (Single Column) */
.emi-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    width: 100%;
    max-width: 100%;
    margin-top: 60px; /* Space for fixed toggle button */
}

/* Input Section (Left Panel) */
.emi-left {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    width: 100%;
}

.emi-left h3 {
    color: var(--text-color);
    font-size: 20px;
    font-weight: 700;
    margin-bottom: var(--spacing-lg);
    text-align: center;
    line-height: 1.3;
}

/* Input Groups - Mobile Optimized */
.input-group {
    margin-bottom: var(--spacing-xl);
    width: 100%;
}

.input-group label {
    display: block;
    color: var(--text-color);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    opacity: 0.9;
}
#rateVal{
    color: rgb(227, 170, 62);
}
#loanVal{
    color: rgb(227, 170, 62);
}
#tenureVal{
    color: rgb(227, 170, 62);
}

/* Range Slider Container */
.range-container {
    /*background: red;*/
    background: var(--input-bg);
    border-radius: 10px;
    padding: var(--spacing-md);
    border: 1px solid var(--border-color);
    margin-bottom: var(--spacing-md);
}

/* Slider Styling */
.emi-slider {
    width: 100%;
    height: 44px; /* Larger touch target */
    /*-webkit-appearance: none;*/
    /*background: transparent;*/
    margin: var(--spacing-sm) 0;
}

.emi-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    background: red;
    background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 4px;
    border: none;
}

.emi-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    margin-top: -14px;
}

.emi-slider::-moz-range-track {
    width: 100%;
    height: 8px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
    border-radius: 4px;
    border: none;
}

.emi-slider::-moz-range-thumb {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

/* Value Display - Mobile Optimized */
.range-value {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
}

.value-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(var(--primary-rgb, 30, 58, 138), 0.1);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.value-display span {
    color: var(--text-color);
    font-size: 15px;
    font-weight: 600;
}

.range-input {
    width: 100%;
    padding: 14px var(--spacing-md);
    background: var(--input-bg);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-color);
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    margin-top: var(--spacing-sm);
    transition: border-color 0.3s ease;
}

.range-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Apply Button - Mobile Optimized */
.emi-apply {
    width: 100%;
    padding: 18px;
    background: linear-gradient(135deg, var(--secondary) 0%, #eab308 100%);
    color: #1f2937;
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    margin: var(--spacing-xl) 0;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
    transition: all 0.3s ease;
    touch-action: manipulation;
    letter-spacing: 0.5px;
}

.emi-apply:active {
    transform: translateY(2px);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

/* Summary Section */
.emi-summary {
    background: var(--input-bg);
    border-radius: 10px;
    padding: var(--spacing-md);
    border: 1px solid var(--border-color);
    margin-top: var(--spacing-lg);
}

.summary-item {
    display: flex;
    justify-content: space-between;
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-label {
    color: var(--text-color);
    font-size: 15px;
    opacity: 0.8;
}

.summary-value {
    color: var(--primary);
    font-size: 16px;
    font-weight: 700;
}

/* Results Section (Right Panel) */
.emi-right {
    width: 100%;
}

/* EMI Card */
.emi-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: var(--spacing-lg);
    text-align: center;
}

.emi-label {
    color: var(--text-color);
    font-size: 16px;
    opacity: 0.8;
    margin-bottom: var(--spacing-sm);
    display: block;
}

.emi-amount {
    color: var(--primary);
    font-size: 42px;
    font-weight: 800;
    margin: var(--spacing-sm) 0;
    line-height: 1.1;
    letter-spacing: -0.5px;
}

.emi-breakdown {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-lg);
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    background: var(--input-bg);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.breakdown-item:first-child {
    color: var(--primary);
}

.breakdown-item:last-child {
    color: var(--secondary);
}

.breakdown-item span:first-child {
    font-size: 15px;
    font-weight: 600;
    opacity: 0.9;
}

.breakdown-item span:last-child {
    font-size: 18px;
    font-weight: 700;
}

/* Chart Container */
.chart-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: var(--spacing-lg);
    height: 280px;
    width: 100%;
    position: relative;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
    max-height: 240px;
}

/* Legend */
.emi-legend {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm);
    background: var(--input-bg);
    border-radius: 8px;
}

.legend-color {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    flex-shrink: 0;
}

.legend-item span:last-child {
    color: var(--text-color);
    font-size: 15px;
    font-weight: 600;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.emi-wrapper > * {
    animation: fadeIn 0.5s ease-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

.value-update {
    animation: pulse 0.3s ease;
}

/* Tablet Styles */
@media (min-width: 768px) {
    .emi-calculator-wrapper {
        padding: var(--spacing-xl);
        max-width: 800px;
        margin: 0 auto;
    }
    
    .emi-toggle-mode {
        position: absolute;
        top: var(--spacing-xl);
        right: var(--spacing-xl);
    }
    
    .emi-wrapper {
        margin-top: 0;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-xl);
        max-width: 800px;
        margin: 0 auto;
    }
    
    .emi-left h3 {
        font-size: 22px;
        text-align: left;
    }
    
    .range-value {
        flex-direction: row;
        align-items: center;
    }
    
    .value-display {
        flex: 1;
        min-width: 140px;
    }
    
    .range-input {
        width: 140px;
        margin-top: 0;
    }
    
    .emi-summary {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: var(--spacing-md);
    }
    
    .summary-item {
        flex-direction: column;
        text-align: center;
        padding: var(--spacing-md);
        border-bottom: none;
        border-right: 1px solid rgba(0, 0, 0, 0.05);
    }
    
    .summary-item:last-child {
        border-right: none;
    }
    
    .emi-breakdown {
        flex-direction: row;
        gap: var(--spacing-md);
    }
    
    .emi-legend {
        flex-direction: row;
        justify-content: center;
        gap: var(--spacing-xl);
    }
    
    .chart-container {
        height: 320px;
    }
}

/* Desktop Styles */
@media (min-width: 1024px) {
    .emi-calculator-wrapper {
        max-width: 100%;
        padding: 40px;
    }
    
    .emi-wrapper {
        grid-template-columns: 1fr 1fr;
        gap: 40px;
        max-width: 100%;
    }
    
    .emi-left,
    .emi-right .emi-card {
        padding: 32px;
    }
    
    .emi-amount {
        font-size: 48px;
    }
    
    .chart-container {
        height: 350px;
    }
    
    .mode-toggle-btn {
        /*min-width: 150px;*/
        padding: 12px 20px;
        font-size: 15px;
    }
}

/* Small Phones (under 375px) */
@media (max-width: 374px) {
    .emi-calculator-wrapper {
        padding: var(--spacing-sm);
    }
    
    .emi-left,
    .emi-right .emi-card,
    .chart-container,
    .emi-legend {
        padding: var(--spacing-md);
    }
    
    .emi-amount {
        font-size: 36px;
    }
    
    .breakdown-item span:first-child {
        font-size: 14px;
    }
    
    .breakdown-item span:last-child {
        font-size: 16px;
    }
    
    .mode-toggle-btn {
        /*min-width: 110px;*/
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* iOS Safari Specific Fixes */
@supports (-webkit-touch-callout: none) {
    .emi-slider {
        height: 48px;
    }
    
    .emi-slider::-webkit-slider-thumb {
        width: 40px;
        height: 40px;
        margin-top: -16px;
    }
    
    .range-input {
        font-size: 18px; /* Prevents zoom on focus */
        padding: 16px;
    }
    
    .emi-apply {
        padding: 20px;
    }
}

/* Android Chrome Specific */
@supports (-webkit-tap-highlight-color: transparent) {
    .emi-slider::-webkit-slider-thumb {
        -webkit-tap-highlight-color: transparent;
    }
}

/* Prevent text size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Fix for viewport units on mobile */
.emi-calculator-wrapper {
    border-radius:12px;
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* Hide number input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

/* Loading state for button */
.emi-apply.processing {
    opacity: 0.7;
    pointer-events: none;
}

/* Error state for inputs */
.range-input.error {
    border-color: #ef4444;
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}