/* 401(k) Calculator Styles */
/* Prefix: fk- */

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --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);
}

body {
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.fk-body {
    width: 100%;
    box-sizing: border-box;
}

/* CMS compatibility - Force wide layout */
/* Override CMS article body constraints */
.c-matter--article .c-matter__body {
    max-width: 1170px !important;
    width: 100% !important;
}

/* Fallback for browsers without :has() support */
.ci-body {
    width: 100%;
    max-width: 1170px;
    margin: 0 auto;
}

/* Modern browsers with :has() support */
@media(min-width: 992px) {
    .c-matter--article .c-matter__body:has(.ci-body) {
        max-width: 1170px !important;
        width: auto !important;
    }
}

/* Ensure the calculator container itself can expand */
.c-matter--article .fk-body,
.c-matter--article .fk-container {
    max-width: 1170px !important;
    width: 100% !important;
}

@media (max-width: 950px) {
    .c-matter--article .c-matter__body {
        max-width: 750px !important;
        padding: 1.5rem;
    }
}

@media (max-width: 750px) {
    .c-matter--article .c-matter__body {
        max-width: 100% !important;
        margin: 10px;
        padding: 1rem;
        border-radius: 8px;
    }
}

/* Container and layout */
.fk-container {
    max-width: 1170px;
    margin: 2rem auto 4rem auto;
    padding: 0 2rem;
    background: transparent;
    box-sizing: border-box;
}

/* Two-column layout - CMS-friendly flat structure */
.fk-calculator-layout {
    display: grid !important;
    grid-template-columns: 0.48fr 0.52fr !important;
    gap: 24px !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    align-items: start !important;
}

/* CMS override - ensure layout doesn't collapse due to constrained parent */
.c-matter--article .fk-calculator-layout {
    display: grid !important;
    grid-template-columns: 0.48fr 0.52fr !important;
    gap: 24px !important;
}

.fk-form-column {
    background: #f7fafc;
    border: 2px solid #f3f4f6;
    border-radius: var(--radius-lg);
    padding: 26px;
    margin-bottom: 24px;
    min-width: 0;
    max-width: 100%;
    overflow: visible;
    height: fit-content;
    /* GPU layer isolation for stability */
    transform: translateZ(0);
    will-change: transform;
}

/* Sticky positioning - desktop only */
@media (min-width: 751px) {
    .fk-form-column {
        position: -webkit-sticky !important;
        position: sticky !important;
        top: 0 !important;
        align-self: start !important;
    }
}

.fk-results-column {
    min-width: 0;
    max-width: 100%;
    overflow: visible;
    width: 100%;
    box-sizing: border-box;
}

.fk-results-column * {
    max-width: 100%;
    box-sizing: border-box;
}

/* Header */
.fk-header {
    text-align: center;
    margin-bottom: 48px;
    padding-bottom: 0;
}

.fk-header p {
    max-width: none;
    margin: 0;
    line-height: 1.7;
    font-weight: 400;
}

/* Form section headings */
.fk-form-column h2,
.fk-chart-section h2 {
    font-weight: 500;
    margin-bottom: 20px;
    margin-top: 0px;
    letter-spacing: -0.01em;
    text-align: center;
}

/* Labels - direct children of form column (flat structure for CMS) */
.fk-form-column > label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    margin-top: 20px;
    letter-spacing: -0.005em;
    cursor: default !important;
}

.fk-form-column > label:first-of-type {
    margin-top: 0;
}

/* Slider input groups - label and input side by side */
.fk-slider-group {
    margin-bottom: 24px;
}

.fk-slider-group:first-of-type {
    margin-top: 0;
}

.fk-slider-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.fk-slider-row label {
    display: block;
    font-weight: 600;
    letter-spacing: -0.005em;
    cursor: default !important;
    flex: 1;
    margin: 0;
}

.fk-slider-row .fk-input-wrapper {
    width: auto;
    flex-shrink: 0;
    min-width: 130px;
    max-width: 140px;
}

/* Tooltip styles */
.fk-tooltip {
    display: inline-block;
    margin-left: 6px;
    width: 18px;
    height: 18px;
    background: #64748b;
    color: white;
    border-radius: 50%;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    line-height: 18px;
    transition: all 0.2s ease;
    vertical-align: middle;
    flex-shrink: 0;
}

.fk-tooltip:hover {
    background: #475569;
    transform: scale(1.1);
}

.fk-tooltip.active::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 400;
    white-space: normal;
    width: 280px;
    text-align: left;
    z-index: 10000;
    box-shadow: var(--shadow-lg);
    line-height: 1.5;
    pointer-events: none;
}

.fk-tooltip.active::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1e293b;
    z-index: 10001;
    pointer-events: none;
}

/* Input wrapper for currency and percent symbols */
.fk-input-wrapper {
    position: relative;
}

.fk-currency {
    position: absolute;
    left: 12px;
    top: 46%;
    transform: translateY(-50%);
    font-weight: 500;
    font-size: 1em;
    pointer-events: none;
    z-index: 2;
    color: #64748b;
}

.fk-unit {
    position: absolute;
    right: 35px;
    top: 50%;
    transform: translateY(-50%);
    font-weight: 500;
    font-size: 1em;
    pointer-events: none;
    z-index: 10;
    color: #64748b;
}

/* Input styles */
input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
    font-family: inherit;
    font-weight: 400;
}

/* Hide native steppers (all inputs use custom steppers) */
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;
}

/* Custom stepper buttons */
.fk-stepper {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    gap: 1px;
}

.fk-stepper-btn {
    width: 16px;
    height: 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    position: relative;
}

.fk-stepper-btn::before {
    content: '';
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    display: block;
}

.fk-stepper-btn--up::before {
    border-bottom: 4px solid #555;
    border-top: none;
}

.fk-stepper-btn--down::before {
    border-top: 4px solid #555;
    border-bottom: none;
}

.fk-stepper-btn:hover::before {
    border-bottom-color: #333 !important;
    border-top-color: #333 !important;
}

/* Show steppers on hover/focus */
.fk-input-group:hover .fk-stepper,
.fk-input-wrapper:hover .fk-stepper {
    opacity: 1;
    pointer-events: auto;
}

.fk-input-wrapper:has(input:focus) .fk-stepper {
    opacity: 1;
    pointer-events: auto;
}

/* Enable pointer events on buttons when stepper is visible */
.fk-input-group:hover .fk-stepper .fk-stepper-btn,
.fk-input-wrapper:hover .fk-stepper .fk-stepper-btn,
.fk-input-wrapper:has(input:focus) .fk-stepper .fk-stepper-btn {
    pointer-events: auto;
}

/* Add padding for inputs with custom steppers (currency fields) */
.fk-input-wrapper:has(.fk-stepper) input {
    padding-right: 35px;
}

/* Input padding for currency symbol */
.fk-input-wrapper:has(.fk-currency) input {
    padding-left: 28px;
}

/* Input padding for unit symbol with stepper (unit in middle, stepper on far right) */
.fk-has-unit-stepper input {
    padding-right: 65px !important;
}

input[type="text"]::placeholder {
    color: rgba(0, 0, 0, 0.55);
    opacity: 1;
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgb(16 185 129 / 0.08);
}

/* Slider styles */
.fk-input-group.fk-has-slider label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.fk-input-group.fk-has-slider .fk-input-wrapper {
    width: auto;
    flex-shrink: 0;
    min-width: 130px;
    max-width: 140px;
}

.fk-slider-wrapper {
    margin-bottom: 8px;
    position: relative;
    width: 100%;
}

.fk-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
    outline: none;
    margin: 12px 0 8px 0;
}

.fk-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #10b981;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.fk-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.fk-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #10b981;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
}

.fk-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.fk-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 4px;
}

/* Error messages */
.fk-error-message {
    margin-top: 4px;
    font-weight: 400;
    display: none;
    color: #ef4444;
    font-size: 0.875rem;
}

.fk-error-message.show {
    display: block;
}

/* Visual alert for capped values */
.fk-input-group.value-capped {
    animation: valueCappedPulse 1s ease-in-out;
}

@keyframes valueCappedPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

.fk-input-group.value-capped input {
    box-shadow: 0 0 0 2px #ffc107;
}

.fk-input-group.error input {
    box-shadow: 0 0 0 3px rgb(239 68 68 / 0.1);
}

/* Disclaimer text - simplified flat structure */
.fk-disclaimer-text {
    margin-top: 24px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: #f3f3f3;
    border-left: 3px solid #cbd5e1;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    color: #475569;
    line-height: 1.5;
}

/* Button styles */
.fk-download-section {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-top: 32px;
    margin-bottom: 0;
}

.fk-download-section .c-btn {
    flex: 1;
}

.fk-button-mobile {
    display: none;
}

/* Results section */
.fk-results-section {
    margin-top: 0;
    padding: 0;
    background: transparent;
    border: none;
}

.fk-results-section h2 {
    text-align: center;
    margin-bottom: 32px;
    letter-spacing: -0.025em;
}

.fk-results-heading {
    text-align: center;
    margin-bottom: 16px;
    margin-top: 0;
    letter-spacing: -0.01em;
}

.fk-main-result {
    background: #f8fafc;
    padding: 26px;
    border-radius: 12px;
    text-align: center;
    margin-bottom: 24px;
    border: 1px solid #e2e8f0;
}

.fk-main-result h2 {
    font-weight: 500;
    margin-bottom: 16px;
    letter-spacing: -0.01em;
}

.fk-main-result h2:last-of-type {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.fk-main-value {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--paletteColor3, #10b981);
}

.fk-explanation-text {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #475569;
}

.fk-breakdown {
    background: #f8fafc;
    padding: 26px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    margin-bottom: 24px;
}

/* Simplified breakdown - h3 is direct child */
.fk-breakdown h3 {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 0;
}

.fk-breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.fk-breakdown-item.fk-breakdown-divider {
    border-top: 1px solid #e2e8f0;
    margin-top: 8px;
    padding-top: 16px;
}

.fk-breakdown-label {
    font-size: 0.95rem;
    font-weight: 400;
}

.fk-breakdown-value {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.fk-breakdown-value.fk-highlight {
    color: var(--paletteColor3, #10b981);
}

/* Chart section */
.fk-chart-section {
    background: #f7fafc;
    border: 2px solid #f3f4f6;
    border-radius: var(--radius-lg);
    padding: 26px;
    margin-bottom: 32px;
    box-shadow: none;
}

.fk-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    cursor: pointer;
}

.fk-chart-header h2 {
    margin-bottom: 0;
    flex: 1;
}

.fk-chart-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-family: inherit;
    flex-shrink: 0;
}

.fk-chart-toggle:hover {
    background: #f1f5f9;
}

.fk-caret {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 8px solid #64748b;
    transition: transform 0.3s ease;
    display: block;
}

.fk-chart-section.collapsed .fk-caret {
    transform: rotate(180deg);
}

.fk-chart-toggle:hover .fk-caret {
    border-bottom-color: #475569;
}

.fk-chart-content {
    margin-top: 20px;
    overflow: hidden;
    max-height: 1000px;
    opacity: 1;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin-top 0.3s ease;
}

.fk-chart-section.collapsed .fk-chart-content {
    max-height: 0;
    margin-top: 0;
    opacity: 0;
    overflow: hidden;
}

.fk-chart-container {
    position: relative;
    height: 380px;
    width: 100%;
    contain: layout;
    min-height: 200px;
}

.fk-chart-container canvas {
    max-width: 100%;
    height: 380px !important;
    width: 100% !important;
}

.fk-download-btn {
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    font-family: inherit;
}

/* Responsive */
@media (max-width: 950px) {
    .fk-container {
        max-width: 750px;
        padding: 0 1.5rem;
        margin: 1.5rem auto 3rem auto;
    }
}

@media (max-width: 900px) {
    .fk-download-section {
        flex-direction: column;
    }
    
    .fk-download-section .c-btn {
        width: 100%;
    }
}

@media (max-width: 750px) {
    .fk-container {
        max-width: 100%;
        margin: 0.5rem auto 1rem auto;
        padding: 0;
    }
    
    .fk-calculator-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .fk-form-column {
        position: static !important;
    }
    
    .fk-results-column {
        position: static !important;
        min-height: 0 !important;
    }
    
    .fk-header {
        text-align: left;
        margin-bottom: 24px;
    }
    
    .fk-input-section h2,
    .fk-chart-section h2 {
        text-align: left;
    }
    
    .fk-main-result {
        text-align: left;
    }
    
    .fk-breakdown-header {
        text-align: left;
    }
    
    .fk-form-column {
        padding: 16px;
    }
    
    .fk-chart-section {
        padding: 16px;
    }
    
    .fk-results-section {
        padding: 0;
    }
    
    .fk-main-result {
        padding: 24px 16px;
    }
    
    .fk-breakdown {
        padding: 24px 16px;
    }
    
    .fk-input-section {
        margin-bottom: 20px;
        padding: 0;
    }
    
    .fk-download-desktop {
        display: none;
    }
    
    .fk-button-mobile {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin-top: 24px;
        width: 100%;
    }
    
    .fk-button-mobile .c-btn {
        width: 100%;
    }
    
    .fk-chart-container {
        height: auto;
    }
}

@media (max-width: 480px) {
    .fk-form-column {
        padding: 12px;
    }
    
    .fk-chart-section {
        padding: 12px;
    }
    
    .fk-main-result {
        padding: 20px 12px;
    }
    
    .fk-breakdown {
        padding: 20px 12px;
    }
    
    .fk-main-value {
        font-size: 2rem;
    }
    
    .fk-breakdown-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .fk-chart-container {
        height: auto;
    }
}

/* Print styles */
@media print {
    body {
        background: white;
    }
    
    .fk-container {
        box-shadow: none;
        margin: 0;
        padding: 0;
    }
    
    .fk-form-column,
    .fk-download-section,
    .fk-button-mobile {
        display: none;
    }
    
    .fk-results-section {
        background: white;
        border: 1px solid #333;
        padding: 30px;
    }
}

