/* =============================================
   EMI Calculator — Custom Styles
   ============================================= */

/* ---- Preset Buttons ---- */
.emi-preset-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.emi-preset-btn:hover,
.emi-preset-btn.active {
    background: #2280a0;
    color: #fff;
    border-color: #2280a0;
    box-shadow: 0 4px 12px rgba(34,128,160,0.25);
    transform: translateY(-1px);
}

/* ---- Main Grid ---- */
.emi-main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}
@media (max-width: 900px) {
    .emi-main-grid { grid-template-columns: 1fr; }
}

/* ---- Input Card ---- */
.emi-inputs-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* ---- Input Group ---- */
.emi-input-group { display: flex; flex-direction: column; gap: 10px; }
.emi-input-group label {
    font-size: 13px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ---- Input Row (label + value input) ---- */
.emi-input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

/* ---- Currency / Value Input Box ---- */
.emi-value-box {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1.5px solid #cbd5e1;
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.2s;
    background: #f8fafc;
}
.emi-value-box:focus-within {
    border-color: #2280a0;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(34,128,160,0.12);
}
.emi-value-box .unit {
    padding: 0 10px;
    font-size: 14px;
    font-weight: 700;
    color: #94a3b8;
    background: transparent;
    border-right: 1.5px solid #e2e8f0;
    height: 42px;
    display: flex;
    align-items: center;
    user-select: none;
}
.emi-value-box .unit-right {
    border-right: none;
    border-left: 1.5px solid #e2e8f0;
}
.emi-value-box input {
    width: 100px;
    padding: 0 12px;
    height: 42px;
    font-size: 15px;
    font-weight: 700;
    color: #0f172a;
    border: none;
    outline: none;
    background: transparent;
    text-align: right;
    font-family: 'Inter', sans-serif;
}
.emi-value-box input[type="number"]::-webkit-inner-spin-button,
.emi-value-box input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }

/* ---- Slider ---- */
.emi-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;
    border-radius: 999px;
    background: #e2e8f0;
    outline: none;
    cursor: pointer;
    position: relative;
}
.emi-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #2280a0;
    cursor: pointer;
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(34,128,160,0.4);
    transition: box-shadow 0.2s, transform 0.15s;
}
.emi-slider::-webkit-slider-thumb:hover {
    box-shadow: 0 2px 14px rgba(34,128,160,0.55);
    transform: scale(1.15);
}
.emi-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #2280a0;
    cursor: pointer;
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(34,128,160,0.4);
}
.emi-slider-range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 600;
    color: #94a3b8;
    margin-top: -4px;
}

/* ---- Tenure Toggle ---- */
.tenure-toggle {
    display: inline-flex;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}
.tenure-toggle button {
    padding: 5px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    background: transparent;
    color: #64748b;
    transition: all 0.2s;
}
.tenure-toggle button.active {
    background: #fff;
    color: #2280a0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* ---- Results Column ---- */
.emi-results-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ---- Monthly EMI Result ---- */
.emi-monthly-card {
    background: linear-gradient(135deg, #2280a0 0%, #1a6a80 100%);
    border-radius: 16px;
    padding: 28px;
    color: #fff;
    box-shadow: 0 8px 24px rgba(34,128,160,0.3);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.emi-monthly-card .label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.8;
}
.emi-monthly-card .amount {
    font-size: 40px;
    font-weight: 900;
    letter-spacing: -1px;
    line-height: 1.1;
    transition: all 0.3s ease;
}
.emi-monthly-card .sub {
    font-size: 12px;
    opacity: 0.7;
    margin-top: 4px;
}

/* ---- Secondary Stats Grid ---- */
.emi-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.emi-stat-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 18px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.emi-stat-card .stat-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #94a3b8;
}
.emi-stat-card .stat-amount {
    font-size: 20px;
    font-weight: 800;
    color: #0f172a;
    transition: all 0.3s ease;
}
.emi-stat-card.interest .stat-amount { color: #ef4444; }
.emi-stat-card.total .stat-amount { color: #0f172a; }

/* ---- Chart Card ---- */
.emi-chart-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}
.emi-chart-card canvas { max-width: 220px; max-height: 220px; }
.emi-chart-legend {
    display: flex;
    gap: 20px;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
}
.emi-chart-legend .legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
    flex-shrink: 0;
}
.legend-dot.principal { background: #2280a0; }
.legend-dot.interest { background: #f97316; }

/* ---- Action Bar ---- */
.emi-action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.emi-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
    cursor: pointer;
    transition: all 0.18s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.emi-action-btn:hover {
    border-color: #2280a0;
    color: #2280a0;
    background: #f0f9ff;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(34,128,160,0.15);
}
.emi-action-btn.success {
    border-color: #22c55e;
    color: #16a34a;
    background: #f0fdf4;
}

/* ---- Table Section ---- */
.emi-table-section {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 1px 6px rgba(0,0,0,0.04);
}
.emi-table-toggle {
    width: 100%;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 700;
    color: #334155;
    background: #f8fafc;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid transparent;
}
.emi-table-toggle:hover { background: #f1f5f9; }
.emi-table-toggle.open { border-bottom-color: #e2e8f0; }
.emi-table-toggle .toggle-icon {
    transition: transform 0.25s;
    font-size: 13px;
    color: #94a3b8;
}
.emi-table-toggle.open .toggle-icon { transform: rotate(180deg); }

#table-container { display: none; }
#table-container.open { display: block; }

.table-responsive { overflow-x: auto; }
#amortization-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
#amortization-table thead th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    padding: 12px 16px;
    text-align: right;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #64748b;
    border-bottom: 1.5px solid #e2e8f0;
    white-space: nowrap;
}
#amortization-table thead th:first-child { text-align: center; }
#amortization-table tbody tr {
    transition: background 0.15s;
    border-bottom: 1px solid #f1f5f9;
}
#amortization-table tbody tr:hover { background: #f8fafc; }
#amortization-table tbody td {
    padding: 11px 16px;
    text-align: right;
    color: #334155;
    font-weight: 500;
}
#amortization-table tbody td:first-child {
    text-align: center;
    font-weight: 700;
    color: #94a3b8;
    font-size: 12px;
}
#amortization-table tbody td.principal-cell { color: #2280a0; font-weight: 700; }
#amortization-table tbody td.interest-cell { color: #f97316; font-weight: 600; }
#amortization-table tbody td.balance-cell { color: #0f172a; font-weight: 700; }

/* ---- Pagination ---- */
.emi-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 16px;
    border-top: 1px solid #f1f5f9;
    flex-wrap: wrap;
}
.page-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1.5px solid #e2e8f0;
    background: #fff;
    font-size: 13px;
    font-weight: 700;
    color: #475569;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.page-btn:hover { border-color: #2280a0; color: #2280a0; background: #f0f9ff; }
.page-btn.active { background: #2280a0; border-color: #2280a0; color: #fff; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Animations ---- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}
.emi-animate { animation: fadeInUp 0.35s ease both; }

@keyframes numPulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.04); }
    100% { transform: scale(1); }
}
.num-pulse { animation: numPulse 0.25s ease; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
    .emi-inputs-card { padding: 20px; gap: 22px; }
    .emi-monthly-card .amount { font-size: 30px; }
    .emi-stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .emi-action-bar { flex-direction: column; }
    .emi-action-btn { width: 100%; justify-content: center; }
    .emi-value-box input { width: 80px; font-size: 14px; }
}

/* ---- Print / PDF ---- */
@media print {
    body * { visibility: hidden; }
    #emi-print-area, #emi-print-area * { visibility: visible; }
    #emi-print-area {
        position: absolute; top: 0; left: 0;
        width: 100%; padding: 20px;
    }
    .emi-action-bar, .emi-table-toggle, #toggle-table { display: none !important; }
    #table-container { display: block !important; }
}

/* ---- Currency Selector ---- */
.emi-currency-select select {
    padding: 8px 32px 8px 16px;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    transition: all 0.2s;
}
.emi-currency-select select:hover, .emi-currency-select select:focus {
    border-color: #2280a0;
    box-shadow: 0 2px 8px rgba(34,128,160,0.15);
}
