/* ==========================================================================
   Education Loan EMI Calculator - Grey & Red Theme
   ========================================================================== */

:root {
    --bg-page: #f3f4f6;
    --card-bg: #ffffff;
    --text-main: #18181b;
    --text-muted: #52525b;
    --text-light: #71717a;
    
    --primary-red: #dc2626;
    --primary-red-hover: #b91c1c;
    --primary-red-dark: #991b1b;
    
    --pill-bg: #fef2f2;
    --pill-text: #dc2626;
    --pill-border: #fecaca;
    
    --red-card-bg: #fef2f2;
    --red-card-border: #fecaca;
    
    --grey-card-bg: #f4f4f5;
    --grey-card-border: #e4e4e7;
    
    --grey-chart: #374151;
    --red-chart: #dc2626;

    --input-border: #d4d4d8;
    --input-focus-border: #dc2626;
    --slider-track: #e4e4e7;
    --shadow-card: 0 8px 30px rgba(0, 0, 0, 0.08);
    --border-radius-lg: 14px;
    --border-radius-md: 10px;
    --border-radius-sm: 6px;

    --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Base Resets */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-family);
}

body {
    background-color: var(--bg-page);
    color: var(--text-main);
    min-height: 100vh;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Top Branding Header with Logo */
.header-container {
    width: 100%;
    max-width: 980px;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
}

.brand-header {
    display: flex;
    align-items: center;
    gap: 20px;
    background: #ffffff;
    padding: 16px 28px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-card);
    border: 1px solid #e4e4e7;
    width: 100%;
}

.brand-logo {
    height: 64px;
    width: auto;
    object-fit: contain;
}

.brand-info {
    display: flex;
    flex-direction: column;
}

.brand-title {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.brand-subtitle {
    font-size: 0.85rem;
    color: var(--primary-red);
    font-weight: 700;
}

/* Calculator Standalone Card Container */
.calculator-card {
    background: var(--card-bg);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-card);
    border: 1px solid #e4e4e7;
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    width: 100%;
    max-width: 980px;
    overflow: hidden;
}

/* Left Side: Form */
.calc-left {
    padding: 32px 36px;
    border-right: 1px solid #f4f4f5;
}

.calc-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.3px;
}

.title-icon {
    color: var(--primary-red);
    font-size: 1.1rem;
}

.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    align-items: flex-start;
}

.form-row.single-col {
    display: block;
}

.field-group {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Floating Outlined Input Styles */
.outlined-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    border: 1.5px solid var(--input-border);
    border-radius: var(--border-radius-sm);
    padding: 0 12px;
    height: 46px;
    background: var(--card-bg);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.outlined-input-wrap:focus-within {
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.input-prefix {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary-red);
    margin-right: 8px;
    user-select: none;
}

.outlined-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

.floating-label {
    position: absolute;
    top: -9px;
    left: 10px;
    background: var(--card-bg);
    padding: 0 5px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    pointer-events: none;
}

.words-helper {
    font-size: 0.72rem;
    color: #71717a;
    margin-top: 5px;
    font-weight: 500;
}

.words-label {
    color: #a1a1aa;
    font-weight: 500;
}

#words-text {
    color: var(--text-main);
    font-weight: 600;
}

/* Slider Header & Badges */
.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.field-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
}

.pill-badge {
    background: var(--pill-bg);
    color: var(--pill-text);
    border: 1px solid var(--pill-border);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 700;
}

/* Custom Red Range Slider */
.purple-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--slider-track);
    outline: none;
    margin: 6px 0;
    cursor: pointer;
}

.purple-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 21px;
    height: 21px;
    border-radius: 50%;
    background: var(--primary-red);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.35);
    transition: transform 0.15s ease;
}

.purple-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.slider-range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-light);
    font-weight: 500;
}

.field-note {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 5px;
    line-height: 1.3;
}

/* Rate of Interest row header */
.roi-input-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 8px;
}

.roi-wrap {
    width: 150px;
    min-width: 140px;
}

/* Radio Group Custom Styles */
.info-icon {
    color: var(--text-light);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 50%;
    transition: color 0.15s ease;
}

.info-icon:hover {
    color: var(--primary-red);
}

.radio-group {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-top: 8px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
}

.radio-label input[type="radio"] {
    display: none;
}

.custom-radio {
    width: 16px;
    height: 16px;
    border: 2px solid var(--primary-red);
    border-radius: 50%;
    display: inline-block;
    position: relative;
    transition: all 0.2s ease;
}

.radio-label input[type="radio"]:checked + .custom-radio::after {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--primary-red);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.custom-select {
    width: 100%;
    height: 40px;
    padding: 0 10px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--input-border);
    background: var(--card-bg);
    color: var(--text-main);
    font-size: 0.82rem;
    font-weight: 600;
    outline: none;
    margin-top: 6px;
}

.custom-select:focus {
    border-color: var(--input-focus-border);
}

.partial-box {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
}

.partial-box input {
    width: 90px;
    padding: 4px 8px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    font-weight: 700;
}

.form-divider {
    height: 1px;
    background: #f4f4f5;
    margin: 26px 0;
}

/* Right Side: Results Panel */
.calc-right {
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--card-bg);
}

/* Chart Box */
.chart-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.donut-wrapper {
    position: relative;
    width: 250px;
    height: 250px;
}

.donut-svg {
    width: 100%;
    height: 100%;
}

.donut-center-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}

.donut-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.2;
}

.chart-legend-row {
    display: flex;
    gap: 16px;
    margin-top: 12px;
}

.legend-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.legend-box {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.principal-box {
    background: var(--grey-chart);
}

.interest-box {
    background: var(--red-chart);
}

/* EMI Result Card */
.emi-result-card {
    background: var(--red-card-bg);
    border: 1.5px solid var(--red-card-border);
    border-radius: var(--border-radius-md);
    padding: 16px;
    text-align: center;
}

.emi-card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 4px;
}

.emi-card-amount {
    font-size: 2.35rem;
    font-weight: 800;
    color: var(--primary-red);
    letter-spacing: -0.5px;
}

/* Key Takeaway Insight Card */
.takeaway-card {
    background: var(--grey-card-bg);
    border: 1px solid var(--grey-card-border);
    border-radius: var(--border-radius-md);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: var(--text-main);
    line-height: 1.35;
}

.takeaway-icon {
    color: var(--primary-red);
    font-size: 1.1rem;
    flex-shrink: 0;
}

.takeaway-text strong {
    color: var(--primary-red);
    font-weight: 700;
}

/* Two Sub Result Cards */
.results-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.sub-result-card {
    background: var(--grey-card-bg);
    border: 1px solid var(--grey-card-border);
    border-radius: var(--border-radius-md);
    padding: 14px 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.sub-card-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.25;
    margin-bottom: 6px;
}

.sub-card-label small {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-muted);
}

.sub-card-val {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-main);
}

#display-total-interest {
    color: var(--primary-red);
}

/* Action Buttons Wrap */
.view-details-wrap {
    display: flex;
    gap: 10px;
    margin-top: 4px;
    width: 100%;
}

.view-details-wrap .purple-btn {
    flex: 1;
}

.view-details-wrap .email-btn {
    grid-column: span 2;
}

.purple-btn {
    width: 100%;
    padding: 11px 14px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    background: var(--primary-red);
    color: #ffffff;
}

.purple-btn:hover {
    background: var(--primary-red-hover);
}

.pdf-btn {
    background: #27272a;
}

.pdf-btn:hover {
    background: #18181b;
}

.email-btn {
    background: var(--primary-red-dark);
}

.email-btn:hover {
    background: #7f1d1d;
}

/* Modal Overlay & Card Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(18, 18, 18, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 20px;
}

.modal-overlay.hidden {
    display: none !important;
}

.modal-card {
    background: #ffffff;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 480px;
    overflow: hidden;
    animation: modalPop 0.25s ease-out;
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    background: #fafafa;
    border-bottom: 1px solid #e4e4e7;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-red);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    padding: 20px;
}

.custom-textarea {
    width: 100%;
    height: 80px;
    padding: 10px 12px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--input-border);
    outline: none;
    font-size: 0.85rem;
    resize: none;
    margin-top: 4px;
}

.custom-textarea:focus {
    border-color: var(--input-focus-border);
}

/* --- Download Modal Underline Input Styles --- */
.dl-field {
    margin-bottom: 18px;
    position: relative;
}

.dl-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.dl-required {
    color: var(--primary-red);
    margin-left: 2px;
}

.dl-optional {
    color: #a1a1aa;
    font-weight: 400;
    font-size: 0.72rem;
    text-transform: none;
    letter-spacing: 0;
}

.dl-input {
    width: 100%;
    border: none;
    border-bottom: 1.5px solid #d4d4d8;
    border-radius: 0;
    background: transparent;
    outline: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    padding: 6px 0;
    transition: border-color 0.2s ease;
    font-family: var(--font-family);
}

.dl-input:focus {
    border-bottom-color: var(--primary-red);
}

.dl-input.dl-invalid {
    border-bottom-color: var(--primary-red);
}

.dl-select {
    width: 100%;
    border: none;
    border-bottom: 1.5px solid #d4d4d8;
    border-radius: 0;
    background: transparent;
    outline: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    padding: 6px 0;
    cursor: pointer;
    font-family: var(--font-family);
    transition: border-color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2371717a' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 4px center;
    padding-right: 20px;
}

.dl-select:focus {
    border-bottom-color: var(--primary-red);
}

.dl-error {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--primary-red);
    margin-top: 4px;
    min-height: 16px;
}


.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid #e4e4e7;
    background: #fafafa;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-btn {
    border: none;
    padding: 8px 18px;
    border-radius: var(--border-radius-sm);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
}

.modal-btn.primary {
    background: var(--primary-red);
    color: #ffffff;
}

.modal-btn.primary:hover {
    background: var(--primary-red-hover);
}

.modal-btn.secondary {
    background: #e4e4e7;
    color: var(--text-main);
}

.modal-btn.secondary:hover {
    background: #d4d4d8;
}

/* Print & PDF Export Formatting */
@media print {
    body {
        background: #ffffff !important;
        padding: 0 !important;
    }

    .header-container {
        display: none !important;
    }

    .calculator-card {
        box-shadow: none !important;
        border: 1px solid #d4d4d8 !important;
        max-width: 100% !important;
    }

    .view-details-wrap, .schedule-btn-group {
        display: none !important;
    }

    .amortization-section {
        display: block !important;
        margin-top: 20px !important;
    }
}

.btn-chevron {
    transition: transform 0.25s ease;
}

.purple-btn.expanded .btn-chevron {
    transform: rotate(180deg);
}

/* Amortization Collapsible Section */
.amortization-section {
    margin-top: 24px;
    width: 100%;
    max-width: 980px;
}

.amortization-section.hidden {
    display: none;
}

.amortization-card {
    background: var(--card-bg);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-card);
    border: 1px solid #e4e4e7;
    padding: 24px;
}

.schedule-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.schedule-header-row h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
}

.schedule-btn-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.view-switcher-btns {
    display: flex;
    background: var(--slider-track);
    padding: 2px;
    border-radius: 6px;
}

.sch-view-btn {
    border: none;
    background: transparent;
    padding: 5px 12px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
}

.sch-view-btn.active {
    background: var(--card-bg);
    color: var(--primary-red);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.sch-action-btn {
    background: var(--card-bg);
    border: 1px solid var(--input-border);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
}

.table-container {
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

.sch-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.sch-table th {
    position: sticky;
    top: 0;
    background: #27272a;
    color: #ffffff;
    font-weight: 700;
    padding: 10px;
    text-align: left;
}

.sch-table td {
    padding: 10px;
    border-bottom: 1px solid #f4f4f5;
    color: var(--text-main);
}

.phase-tag {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 8px;
}

.phase-tag.study {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.phase-tag.repayment {
    background: #f4f4f5;
    color: #27272a;
    border: 1px solid #e4e4e7;
}

.hidden {
    display: none !important;
}

/* Responsive — Tablet (≤850px) */
@media (max-width: 850px) {
    body {
        padding: 20px 16px;
        justify-content: flex-start;
        align-items: stretch;
    }

    .header-container {
        width: 100%;
    }

    .brand-header {
        flex-direction: row;
        align-items: center;
        gap: 14px;
        padding: 14px 20px;
    }

    .brand-logo {
        height: 48px;
    }

    .calculator-card {
        grid-template-columns: 1fr;
        max-width: 100%;
    }

    .calc-left {
        border-right: none;
        border-bottom: 1px solid #f4f4f5;
        padding: 24px 20px;
    }

    .calc-right {
        padding: 24px 20px;
    }

    .form-row {
        flex-direction: column;
        gap: 14px;
    }

    /* Center chart and reduce size on tablet */
    .donut-wrapper {
        width: 200px;
        height: 200px;
    }

    /* View Details wrap: single button should take full width */
    .view-details-wrap {
        grid-template-columns: 1fr;
    }

    /* Schedule header stacks on tablet */
    .schedule-header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .amortization-card {
        padding: 18px 16px;
    }

    .amortization-section {
        margin-top: 16px;
    }
}

/* Responsive — Mobile (≤600px) */
@media (max-width: 600px) {
    body {
        padding: 14px 12px;
    }

    .brand-header {
        gap: 10px;
        padding: 12px 16px;
    }

    .brand-logo {
        height: 40px;
    }

    .brand-title {
        font-size: 1.1rem;
    }

    .brand-subtitle {
        font-size: 0.78rem;
    }

    .calc-left {
        padding: 20px 16px;
    }

    .calc-right {
        padding: 20px 16px;
    }

    /* Shrink donut chart on mobile */
    .donut-wrapper {
        width: 180px;
        height: 180px;
    }

    /* EMI amount slightly smaller */
    .emi-card-amount {
        font-size: 1.9rem;
    }

    /* Result cards stack if needed */
    .results-two-col {
        grid-template-columns: 1fr 1fr;
    }

    /* Schedule header group wraps */
    .schedule-btn-group {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Table font smaller on mobile, still scrollable */
    .sch-table {
        font-size: 0.72rem;
    }

    .sch-table th,
    .sch-table td {
        padding: 8px 6px;
        white-space: nowrap;
    }

    /* Modal fits small screens */
    .modal-card {
        max-width: 100%;
        border-radius: 10px;
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 12px 16px;
        flex-direction: column-reverse;
        gap: 8px;
    }

    .modal-btn {
        width: 100%;
        padding: 10px 14px;
        text-align: center;
    }
}

/* Responsive — Small phones (≤400px) */
@media (max-width: 400px) {
    .brand-header {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }

    .donut-wrapper {
        width: 160px;
        height: 160px;
    }

    .emi-card-amount {
        font-size: 1.65rem;
    }

    .results-two-col {
        grid-template-columns: 1fr;
    }

    .sub-result-card {
        padding: 12px 8px;
    }

    .amortization-card {
        padding: 14px 12px;
    }

    .roi-input-header {
        flex-wrap: wrap;
    }

    .roi-wrap {
        width: 100%;
        min-width: unset;
    }
}
