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

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
        sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    padding: 20px;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 30px;
}

h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #3498db;
}

.top-section {
    margin-bottom: 30px;
    padding: 20px;
    border-radius: 6px;
    background-color: #fafafa;
    border: 1px solid #e0e0e0;
}

.top-section .section-title {
    font-size: 1.3rem;
    color: #2c3e50;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
}

.top-input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.top-input-grid.horizontal {
    display: flex;
    align-items: flex-start;
    gap: 30px;
    width: 100%;
}

.top-input-grid.horizontal .input-group {
    flex: 1;
    max-width: none;
}

/* Annuitized expense rows sit inside a parent .input-group, so remove the
   extra bottom margin and label spacing on the nested row to keep rows tight. */
.top-input-grid.horizontal.annuitized-row {
    gap: 15px;
}

.top-input-grid.horizontal.annuitized-row .input-group {
    margin-bottom: 0;
}

.top-input-grid.horizontal.annuitized-row .input-group label {
    font-size: 0.9rem;
}

.top-person-column {
    display: flex;
    flex-direction: column;
}

.top-person-column .person-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #3498db;
}

.ages-universal {
    margin-bottom: 30px;
}

.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.input-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: #3498db;
}

.currency-input-wrapper {
    position: relative;
}

.currency-input-wrapper .currency-symbol {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #555;
    font-size: 1rem;
    pointer-events: none;
}

.currency-input-wrapper input {
    padding-left: 22px;
}

.percent-input-wrapper {
    position: relative;
}

.percent-input-wrapper .percent-symbol {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #555;
    font-size: 1rem;
    pointer-events: none;
}

.percent-input-wrapper input {
    padding-right: 26px;
}

.portfolio-composition {
    margin-bottom: 30px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
    padding: 0;
    accent-color: #3498db;
    cursor: pointer;
}

.checkbox-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.expense-row {
    margin-bottom: 15px;
}

/* Mirrors .input-group / .input-group label's box shape (label line, then
   control) so the +/- buttons land on the same line as the other fields'
   inputs under ordinary top-aligned flex layout, instead of fighting the flex
   cross-axis alignment with no label of their own. */
.expense-row-actions {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
    flex: 0 0 auto;
}

.expense-row-actions-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.expense-row-actions-buttons {
    display: flex;
    gap: 6px;
}

.expense-row-btn {
    width: 32px;
    height: 42px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #f5f5f5;
    color: #2c3e50;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.expense-row-btn:hover:not(:disabled) {
    background-color: #e0e0e0;
}

.expense-row-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.expense-row-label {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    user-select: none;
}

.expense-row-label:hover {
    color: #3498db;
}

.tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
    margin-left: 8px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: #3498db;
    color: white;
    text-align: center;
    line-height: 16px;
    font-size: 12px;
    font-weight: bold;
}

.tooltip:hover {
    background-color: #2980b9;
}

.tooltip .tooltip-text {
    visibility: hidden;
    width: 200px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 4px;
    padding: 8px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.tooltip .tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

.input-tabs {
    margin-bottom: 30px;
}

.tab-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 20px;
}

.tab-button {
    padding: 10px 18px;
    font-size: 1rem;
    font-weight: 600;
    color: #666;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.tab-button:hover {
    color: #2c3e50;
}

.tab-button.active {
    color: #2c3e50;
    border-bottom-color: #3498db;
}

.tab-panel {
    margin-bottom: 0;
}

.actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 30px;
}

.preset-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}

.actions button {
    padding: 12px 30px;
    font-size: 1.1rem;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.actions button:hover {
    background-color: #2980b9;
}

.actions button#calculate-btn {
    width: 100%;
    background-color: #3498db;
}

.actions button#calculate-btn:hover {
    background-color: #2980b9;
}

.actions button#save-scenario-btn {
    background-color: #27ae60;
}

.actions button#save-scenario-btn:hover {
    background-color: #1e8449;
}

.actions button#load-scenario-btn,
.actions button#reset-btn {
    background-color: #e74c3c;
}

.actions button#load-scenario-btn:hover,
.actions button#reset-btn:hover {
    background-color: #c0392b;
}

.results-tabs {
    margin-top: 30px;
}

.advanced-options-row {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 20px;
    margin: 0 0 12px 0;
    padding-left: 0;
}

.advanced-options-row.standalone {
    margin-left: calc(50% + 15px);
}

.advanced-options-row .input-group {
    margin-bottom: 0;
}

.advanced-options-row .checkbox-group label,
.advanced-options-row label {
    margin-bottom: 0;
}

.advanced-options-row .link-button {
    white-space: nowrap;
}

.advanced-options-row .checkbox-group {
    margin-bottom: 0;
}

.average-return-display {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 20px;
    padding: 12px;
    background-color: #f5f5f5;
    border-radius: 4px;
}

.advanced-stock-returns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
    max-height: 50vh;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid #eee;
    border-radius: 4px;
    margin-bottom: 20px;
}

.advanced-stock-return-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.advanced-stock-return-row label {
    font-size: 0.85rem;
    font-weight: 500;
    color: #555;
}

.sequence-inputs {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: nowrap;
}

.sequence-inputs .input-group {
    margin-bottom: 0;
    flex: 1 1 0;
    min-width: 0;
}

.sequence-inputs .input-group input {
    width: 100%;
}

.sequence-inputs button {
    padding: 10px 20px;
    font-size: 1rem;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    background-color: #c0392b;
}

.sequence-inputs button:hover {
    background-color: #a93226;
}

.reset-sequence-btn {
    background-color: #27ae60;
}

.reset-sequence-btn:hover {
    background-color: #1e8449;
}

#advanced-stock-returns-modal .actions {
    flex-direction: row;
}

.result-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
    padding: 8px 0;
}

#result-total-balance {
    color: #3498db;
}

.table-scroll {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

.projection-table {
    width: 100%;
    border-collapse: collapse;
}

.projection-table th,
.projection-table td {
    padding: 8px 12px;
    text-align: right;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
    white-space: nowrap;
}

.projection-table th {
    position: sticky;
    top: 0;
    background-color: #fafafa;
    color: #555;
    font-weight: 600;
}

.projection-table th:first-child,
.projection-table td:first-child {
    text-align: center;
}

.projection-table tbody tr:nth-child(even) {
    background-color: #fafafa;
}

.projection-table td.total-cell {
    font-weight: 600;
    color: #2c3e50;
}

.projection-table td.rmd-excess-cell {
    background-color: #fff3cd;
    color: #8a6100;
    font-weight: 600;
}

.projection-table tbody tr.selected-row {
    background-color: #d6eaf8;
}

/* Fix the Expense Projection table to fixed layout so the Temporary and One Time
   columns stay the same width regardless of whether any individual expense is
   non-zero. Without this, auto-layout expands a column as soon as one cell's
   content (e.g. "$10,000 / $0 / $0") is wider than the all-zero case. */
#expense-projection-table {
    table-layout: fixed;
}

#expense-projection-table th:nth-child(1),
#expense-projection-table td:nth-child(1) {
    width: 5%;
}

#expense-projection-table th:nth-child(2),
#expense-projection-table td:nth-child(2) {
    width: 8%;
}

#expense-projection-table th:nth-child(3),
#expense-projection-table td:nth-child(3) {
    width: 11%;
}

#expense-projection-table th:nth-child(4),
#expense-projection-table td:nth-child(4) {
    width: 15%;
}

#expense-projection-table th:nth-child(5),
#expense-projection-table td:nth-child(5) {
    width: 11%;
}

#expense-projection-table th:nth-child(6),
#expense-projection-table td:nth-child(6),
#expense-projection-table th:nth-child(7),
#expense-projection-table td:nth-child(7),
#expense-projection-table th:nth-child(8),
#expense-projection-table td:nth-child(8) {
    width: 14%;
}

#expense-projection-table th:nth-child(9),
#expense-projection-table td:nth-child(9) {
    width: 12%;
}

/* Keep the combined Income Projection table columns evenly sized so the wider
   "Social Security" and "Portfolio Withdrawal" headers don't squeeze others. */
#income-projection-table {
    table-layout: fixed;
}

#income-projection-table th:nth-child(1),
#income-projection-table td:nth-child(1) {
    width: 8%;
}

#income-projection-table th:nth-child(2),
#income-projection-table td:nth-child(2) {
    width: 10%;
}

#income-projection-table th:nth-child(3),
#income-projection-table td:nth-child(3),
#income-projection-table th:nth-child(5),
#income-projection-table td:nth-child(5) {
    width: 15%;
}

#income-projection-table th:nth-child(4),
#income-projection-table td:nth-child(4) {
    width: 18%;
}

#income-projection-table th:nth-child(6),
#income-projection-table td:nth-child(6) {
    width: 19%;
}

#income-projection-table th:nth-child(7),
#income-projection-table td:nth-child(7) {
    width: 15%;
}

.link-button {
    background: none;
    border: none;
    color: #3498db;
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 4px 0;
}

.link-button:hover {
    color: #2980b9;
}

dialog#tax-tables-modal,
dialog#advanced-stock-returns-modal {
    width: min(700px, 90vw);
    max-height: 85vh;
    overflow-y: auto;
    border: none;
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

dialog#tax-tables-modal::backdrop,
dialog#advanced-stock-returns-modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 -10px 20px;
    padding: 0 10px 15px;
    border-bottom: 2px solid #3498db;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #555;
    margin-right: -5px;
}

.tax-table-group {
    margin-bottom: 25px;
}

.tax-table-group h3 {
    font-size: 1.1rem;
    color: #2c3e50;
    margin-bottom: 12px;
}

.tax-bracket-columns {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
}

.tax-bracket-columns>div {
    flex: 1;
    min-width: 220px;
}

.tax-bracket-columns h4 {
    font-size: 0.95rem;
    color: #555;
    margin-bottom: 8px;
}

.tax-bracket-table {
    width: 100%;
    border-collapse: collapse;
}

.tax-bracket-table th,
.tax-bracket-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}

.tax-bracket-table th {
    color: #555;
    font-weight: 600;
}

.tax-bracket-table .currency-input-wrapper input {
    padding: 6px 6px 6px 20px;
    font-size: 0.9rem;
}

.tax-bracket-table .percent-input-wrapper input {
    width: 55px;
    padding: 6px 20px 6px 6px;
    font-size: 0.9rem;
}

.tax-table-group .top-input-grid + .top-input-grid {
    margin-top: 15px;
}

.currency-input-wrapper input:disabled,
.percent-input-wrapper input:disabled,
input[type="number"]:disabled {
    background-color: #eee;
    color: #888;
    cursor: not-allowed;
}

.copyright-notice {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #ddd;
    text-align: center;
    font-size: 0.85rem;
    color: #666;
}

.copyright-notice a {
    color: #0066cc;
    text-decoration: none;
}

.copyright-notice a:hover {
    text-decoration: underline;
}

.version-label {
    margin-top: 4px;
    font-size: 0.8rem;
    color: #999;
}
