/* ============================================
   401K CALCULATOR - CSS
   Version 1.0
============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

.k401-wrap * { box-sizing: border-box; margin: 0; padding: 0; }

.k401-wrap {
    --blue:        #0D9488;
    --darkblue:    #0F2A3D;
    --cyan:        #14B8A6;
    --amber:       #E8A33D;
    --red:         #E0554F;
    --grad:        #0D9488;
    --grad-soft:   rgba(13,148,136,0.08);
    --white:       #FFFFFF;
    --bg:          #F2F7F6;
    --card-bg:     #FFFFFF;
    --border:      rgba(13,148,136,0.14);
    --text:        #0F2A3D;
    --text-muted:  #5C7A80;
    --shadow-card: 0 32px 80px rgba(15,42,61,0.16), 0 8px 24px rgba(13,148,136,0.10);
    --shadow-btn:  0 12px 32px rgba(13,148,136,0.40);
    --radius-xl:   24px;
    --radius-lg:   16px;
    --radius-md:   12px;
    --radius-sm:   8px;
    font-family: 'Inter', sans-serif;
    position: relative;
    padding: 32px 20px 60px;
    background: var(--bg);
    min-height: 100%;
    color: var(--text);
}

.k401-blob { position: absolute; border-radius: 50%; filter: blur(70px); pointer-events: none; z-index: 0; }
.k401-blob-1 { width: 380px; height: 380px; background: rgba(13,148,136,0.13); top: -100px; left: -100px; }
.k401-blob-2 { width: 320px; height: 320px; background: rgba(15,42,61,0.08); bottom: 0; right: -100px; }

.k401-card { position: relative; z-index: 1; max-width: 860px; margin: 0 auto; }

/* ---- Header ---- */
.k401-header { background: var(--grad); border-radius: var(--radius-xl); padding: 26px 32px; display: flex; align-items: center; justify-content: space-between; gap: 16px; position: relative; overflow: hidden; box-shadow: var(--shadow-card); margin-bottom: 20px; }
.k401-header::after { content: ''; position: absolute; width: 260px; height: 260px; background: rgba(255,255,255,0.06); border-radius: 50%; top: -100px; right: -60px; }
.k401-header-left { display: flex; align-items: center; gap: 16px; position: relative; z-index: 1; }
.k401-header-icon { width: 50px; height: 50px; background: rgba(255,255,255,0.18); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; flex-shrink: 0; backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.25); }
.k401-header-text h1 { color: #fff; font-size: 19px; font-weight: 800; letter-spacing: -0.4px; }
.k401-header-text p { color: rgba(255,255,255,0.78); font-size: 12px; margin-top: 4px; }
.k401-icon-btn { width: 40px; height: 40px; background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.28); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; position: relative; z-index: 1; transition: background 0.2s; }
.k401-icon-btn:hover { background: rgba(255,255,255,0.26); }

/* ---- History panel ---- */
.k401-history-panel { max-height: 0; overflow: hidden; transition: max-height 0.35s ease; background: var(--card-bg); border-radius: var(--radius-xl); box-shadow: var(--shadow-card); }
.k401-history-panel.k401-history-open { max-height: 420px; overflow-y: auto; margin-bottom: 20px; }
.k401-history-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; font-size: 13px; font-weight: 800; color: var(--text); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card-bg); }
.k401-history-close { background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; line-height: 1; }
.k401-history-list { padding: 14px 24px 20px; display: flex; flex-direction: column; gap: 10px; }
.k401-history-empty { font-size: 13px; color: var(--text-muted); padding: 20px 0; text-align: center; }
.k401-history-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--bg); border: 1.5px solid var(--border); border-radius: var(--radius-md); padding: 12px 16px; cursor: pointer; }
.k401-history-item:hover { border-color: var(--blue); }
.k401-history-item-name { font-size: 13.5px; font-weight: 700; color: var(--text); }
.k401-history-item-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.k401-history-item-btn { border: 1.5px solid var(--border); background: var(--white); color: var(--red); font-family: 'Inter', sans-serif; font-size: 11.5px; font-weight: 700; border-radius: 7px; padding: 6px 11px; cursor: pointer; flex-shrink: 0; }
.k401-history-io-row { display: flex; gap: 10px; padding: 0 24px 18px; }
.k401-history-io-btn { flex: 1; border: 1.5px solid var(--border); background: var(--white); color: var(--text); font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 700; border-radius: var(--radius-sm); padding: 9px 10px; cursor: pointer; }
.k401-history-io-btn:hover { border-color: var(--blue); color: var(--blue); }

/* ---- Explainer ---- */
.k401-explainer { background: var(--card-bg); border-radius: var(--radius-xl); box-shadow: var(--shadow-card); border: 1px solid var(--border); margin-bottom: 20px; overflow: hidden; }
.k401-explainer-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: var(--grad-soft); border: none; cursor: pointer; font-size: 13.5px; font-weight: 700; color: var(--text); font-family: 'Inter', sans-serif; }
.k401-explainer-toggle svg { color: var(--blue); transition: transform 0.25s ease; flex-shrink: 0; }
#k401_explainer_arrow.k401-explainer-arrow-open { transform: rotate(180deg); }
.k401-explainer-body { max-height: 0; overflow: hidden; transition: max-height 0.4s ease; padding: 0 24px; }
.k401-explainer-body.k401-explainer-open { max-height: 420px; padding: 16px 24px; }
.k401-explainer-body p { font-size: 12.5px; color: var(--text-muted); line-height: 1.65; margin-bottom: 10px; }
.k401-explainer-body p:last-child { margin-bottom: 0; }
.k401-explainer-body strong { color: var(--text); }

/* ---- Mode tabs ---- */
.k401-mode-tabs { display: flex; gap: 8px; margin-bottom: 20px; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 6px; box-shadow: var(--shadow-card); }
.k401-mode-tab { flex: 1; background: none; border: none; color: var(--text-muted); font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 700; border-radius: var(--radius-md); padding: 12px 8px; cursor: pointer; transition: all 0.15s; }
.k401-mode-tab:hover { color: var(--blue); }
.k401-mode-tab.k401-mode-active { background: var(--grad); color: #fff; }

.k401-mode-panel { background: var(--card-bg); border-radius: var(--radius-xl); box-shadow: var(--shadow-card); border: 1px solid var(--border); padding: 24px 28px; margin-bottom: 20px; }

/* ---- Fields ---- */
.k401-field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.k401-field { margin-bottom: 16px; }
.k401-field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 7px; text-transform: uppercase; letter-spacing: 0.4px; }
.k401-hint-inline { text-transform: none; font-weight: 500; opacity: 0.75; font-size: 11px; }
.k401-input, .k401-plain-input {
    width: 100%; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    padding: 11px 12px; font-family: 'Inter', sans-serif; font-size: 13.5px; font-weight: 600; color: var(--text);
    background: var(--white); outline: none; transition: border-color 0.2s;
}
.k401-input:focus, .k401-plain-input:focus { border-color: var(--blue); }

.k401-unit-input-wrap { display: flex; gap: 6px; }
.k401-unit-input-wrap .k401-plain-input { flex: 1; min-width: 0; }
.k401-unit-static { display: flex; align-items: center; padding: 0 12px; font-size: 12.5px; font-weight: 700; color: var(--text-muted); background: var(--bg); border-radius: var(--radius-sm); border: 1.5px solid var(--border); flex-shrink: 0; white-space: nowrap; }

/* ---- Result ---- */
.k401-result { background: var(--card-bg); border-radius: var(--radius-xl); box-shadow: var(--shadow-card); border: 1px solid var(--border); padding: 24px 28px; }
.k401-result-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.k401-result-badge { font-size: 13px; font-weight: 800; color: var(--text); }
.k401-input-recap { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; line-height: 1.5; }
.k401-input-recap:empty { display: none; margin: 0; }

.k401-due-card { background: var(--grad); border-radius: var(--radius-lg); padding: 22px; text-align: center; margin-bottom: 16px; position: relative; overflow: hidden; }
.k401-due-card::after { content: ''; position: absolute; width: 160px; height: 160px; background: rgba(255,255,255,0.06); border-radius: 50%; top: -70px; right: -50px; }
.k401-due-label { color: rgba(255,255,255,0.8); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; position: relative; }
.k401-due-value { color: #fff; font-size: 32px; font-weight: 900; letter-spacing: -0.5px; margin: 6px 0; position: relative; word-break: break-word; }
.k401-due-sub { color: rgba(255,255,255,0.85); font-size: 12px; font-weight: 500; position: relative; }

.k401-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.k401-stats:empty { display: none; margin-bottom: 0; }
.k401-stat-card { background: var(--bg); border-radius: var(--radius-md); padding: 14px; text-align: center; border: 1px solid var(--border); }
.k401-stat-icon { font-size: 16px; margin-bottom: 4px; }
.k401-stat-value { font-size: 15.5px; font-weight: 800; color: var(--text); word-break: break-word; }
.k401-stat-label { font-size: 10.5px; font-weight: 600; color: var(--text-muted); margin-top: 2px; }

.k401-breakdown-card { background: var(--bg); border-radius: var(--radius-md); border: 1px solid var(--border); padding: 16px; margin-bottom: 14px; }
.k401-breakdown-title { font-size: 12.5px; font-weight: 800; color: var(--text); margin-bottom: 10px; }
.k401-table-wrap { overflow-x: auto; }
.k401-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.k401-table th { text-align: left; font-weight: 700; color: var(--text-muted); padding: 6px 8px; border-bottom: 1.5px solid var(--border); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.3px; white-space: nowrap; }
.k401-table td { padding: 8px; border-bottom: 1px solid var(--border); color: var(--text); font-weight: 600; white-space: nowrap; }
.k401-table tr:last-child td { border-bottom: none; }
.k401-table tr.k401-table-total td { font-weight: 800; color: var(--blue); border-top: 2px solid var(--border); }

.k401-actions-row { margin-bottom: 10px; }
.k401-save-btn { width: 100%; background: var(--grad); color: #fff; border: none; font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 800; border-radius: var(--radius-md); padding: 14px; cursor: pointer; box-shadow: var(--shadow-btn); }
.k401-export-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.k401-export-btn { background: var(--white); border: 1.5px solid var(--border); color: var(--text); font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 700; border-radius: var(--radius-sm); padding: 11px 6px; cursor: pointer; }
.k401-export-btn:hover { border-color: var(--blue); color: var(--blue); }

.k401-footer-note { font-size: 10.5px; color: var(--text-muted); text-align: center; line-height: 1.5; }

/* ---- Segmented toggle (Traditional / Roth / Compare) ---- */
.k401-toggle-row { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; cursor: default; margin-bottom: 0; }
.k401-toggle-row span:first-child { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.k401-seg-toggle { display: flex; gap: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 5px; width: 100%; }
.k401-seg-btn { flex: 1; background: none; border: none; color: var(--text-muted); font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 700; border-radius: var(--radius-sm); padding: 9px 6px; cursor: pointer; }
.k401-seg-btn:hover { color: var(--blue); }
.k401-seg-btn.k401-seg-active { background: var(--grad); color: #fff; }

/* ---- Employer match card ---- */
.k401-overall-card { background: var(--grad-soft); border: 1.5px dashed var(--blue); border-radius: var(--radius-md); padding: 14px 16px; margin-bottom: 16px; }
.k401-overall-head { font-size: 12px; font-weight: 800; color: var(--text); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.4px; }
.k401-match-row { display: flex; align-items: center; gap: 8px; }
.k401-match-row .k401-unit-input-wrap { flex: 1; min-width: 0; }
.k401-match-of { font-size: 11px; font-weight: 600; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }

/* ---- Checkbox column (exemptions) ---- */
.k401-check-col { display: flex; flex-direction: column; gap: 10px; }
.k401-check-inline { display: flex; align-items: center; gap: 9px; font-size: 12.5px; font-weight: 600; color: var(--text); cursor: pointer; text-transform: none; }
.k401-check-inline input { accent-color: var(--blue); width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; }

/* ---- Currency select (searchable dropdown) ---- */
.k401-currency-select-wrap { position: relative; }
.k401-currency-select-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 11px 12px; font-family: 'Inter', sans-serif; font-size: 13.5px; font-weight: 600; color: var(--text); background: var(--white); cursor: pointer; }
.k401-currency-select-btn svg { color: var(--blue); flex-shrink: 0; }
.k401-currency-dropdown { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50; background: white; border: 1.5px solid var(--border); border-radius: var(--radius-md); box-shadow: 0 12px 32px rgba(15,42,61,0.18); max-height: 280px; display: flex; flex-direction: column; }
.k401-currency-search { border: none; border-bottom: 1.5px solid var(--border); padding: 10px 12px; font-family: 'Inter', sans-serif; font-size: 13px; outline: none; }
.k401-currency-list { overflow-y: auto; }
.k401-currency-option { padding: 9px 12px; font-size: 12.5px; font-weight: 600; color: var(--text); cursor: pointer; }
.k401-currency-option:hover { background: var(--grad-soft); color: var(--blue); }
.k401-currency-option-empty { padding: 12px; font-size: 12px; color: var(--text-muted); text-align: center; }

/* ---- Traditional vs Roth compare card ---- */
.k401-compare-card { background: var(--bg); border-radius: var(--radius-md); border: 1px solid var(--border); padding: 16px; margin-bottom: 14px; }
.k401-compare-title { font-size: 12.5px; font-weight: 800; color: var(--text); margin-bottom: 12px; }
.k401-compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.k401-compare-col { background: var(--white); border: 1.5px solid var(--border); border-radius: var(--radius-md); padding: 14px; }
.k401-compare-col-title { font-size: 11.5px; font-weight: 800; color: var(--blue); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 10px; }
.k401-compare-row { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 12px; }
.k401-compare-row:first-of-type { border-top: none; padding-top: 0; }
.k401-compare-key { color: var(--text-muted); font-weight: 500; }
.k401-compare-val { color: var(--text); font-weight: 700; text-align: right; }

/* ---- Field label with help button ---- */
.k401-field label.k401-label-help { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.k401-field label.k401-label-help span:first-child { flex: 1; }
.k401-help-btn {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--grad-soft); border: 1px solid var(--border); color: var(--blue);
    font-size: 11px; font-weight: 800; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    font-family: 'Inter', sans-serif; transition: all 0.2s;
}
.k401-help-btn:hover { background: var(--grad); color: white; border-color: transparent; }

/* ---- Help popover modal ---- */
.k401-help-overlay { display: none; position: fixed; inset: 0; background: rgba(18,23,43,0.55); z-index: 9999; align-items: center; justify-content: center; padding: 20px; }
.k401-help-overlay.k401-help-open { display: flex; }
.k401-help-popover { background: white; border-radius: var(--radius-lg); padding: 24px; max-width: 380px; width: 100%; box-shadow: 0 24px 60px rgba(0,0,0,0.3); }
.k401-help-popover-title { font-size: 16px; font-weight: 800; color: var(--blue); margin-bottom: 10px; }
.k401-help-popover-text { font-size: 13.5px; color: var(--text); line-height: 1.65; margin-bottom: 18px; }
.k401-help-close { width: 100%; padding: 10px; background: var(--grad); color: white; border: none; border-radius: var(--radius-sm); font-size: 13px; font-weight: 700; font-family: 'Inter', sans-serif; cursor: pointer; }

/* ---- Match explanation note ---- */
.k401-note-box { background: rgba(232,163,61,0.12); border: 1.5px solid rgba(232,163,61,0.4); border-radius: var(--radius-md); padding: 12px 14px; font-size: 12px; color: var(--text); line-height: 1.55; margin-bottom: 14px; }
.k401-note-box strong { color: var(--text); }

/* ---- Match window result banner ---- */
.k401-window-banner { background: var(--grad-soft); border: 1.5px solid var(--blue); border-radius: var(--radius-md); padding: 14px 16px; font-size: 13px; color: var(--text); line-height: 1.6; margin-bottom: 16px; }
.k401-window-banner strong { color: var(--blue); font-size: 15px; }

/* ---- Responsive ---- */
@media (max-width: 780px) {
    .k401-field-grid { grid-template-columns: 1fr; }
    .k401-stats { grid-template-columns: 1fr 1fr; }
    .k401-compare-grid { grid-template-columns: 1fr; }
    .k401-seg-toggle { flex-direction: column; }
}
