:root {
    --bg-color: #f4f6f9;
    --card-bg: #ffffff;
    --text-color: #333333;
    --primary-color: #0056b3;
    --border-color: #dddddd;
    --accent-green: #2e7d32;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

span[title] {
    text-decoration: underline dotted;
    cursor: help;
}

.page-title-row {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 25px;
}

h1 {
    text-align: center;
    color: #111;
    margin: 0;
    font-size: 1.8rem;
}

.instructions-link {
    position: absolute;
    right: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--primary-color);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
}

.instructions-link:hover,
.instructions-link:focus-visible {
    text-decoration: underline;
}

.instructions-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
}

@media (max-width: 520px) {
    .page-title-row {
        justify-content: space-between;
    }

    h1 {
        text-align: left;
        font-size: 1.45rem;
    }

    .instructions-link {
        position: static;
    }
}

/* Responsive Input Grid Layout */
.grid-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.card h2 {
    margin-top: 0;
    margin-bottom: 0;
    font-size: 1.2rem;
    color: var(--primary-color);
}

.card-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--bg-color);
    padding-bottom: 8px;
    margin-bottom: 15px;
}

.gear-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: #aaa;
    padding: 0 2px;
    line-height: 1;
    transition: color 0.2s;
}

.gear-btn:hover {
    color: var(--primary-color);
}

.form-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.form-group label {
    font-weight: 500;
    font-size: 0.9rem;
    flex: 1;
}

.form-group input {
    width: 130px;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    text-align: right;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.input-affix-wrap {
    display: inline-flex;
    align-items: center;
    width: 130px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: #fff;
    transition: border-color 0.15s;
}

.input-affix-wrap:focus-within {
    border-color: var(--primary-color);
}

.input-affix-wrap .affix {
    padding: 6px 3px 6px 8px;
    font-size: 0.9rem;
    color: #555;
    flex-shrink: 0;
    user-select: none;
    pointer-events: none;
}

.input-affix-wrap .affix-suffix {
    padding: 6px 8px 6px 3px;
}

.input-affix-wrap input,
.input-affix-wrap input:focus {
    flex: 1;
    min-width: 0;
    width: auto;
    border: none;
    outline: none;
    padding: 6px 4px;
    background: transparent;
    border-radius: 0;
}

.input-affix-wrap:has(.input-error-highlight) {
    border-color: #c62828;
}

.output-value {
    width: 130px;
    text-align: right;
    font-weight: 600;
    font-size: 0.95rem;
}

/* Responsive Data Tables */
.table-responsive {
    overflow-x: auto;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    padding: 15px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 900px;
}

th {
    background-color: var(--bg-color);
    color: #444;
    font-weight: 600;
    text-align: right;
    padding: 10px;
    border-bottom: 2px solid var(--border-color);
}

th:first-child, th:nth-child(5) {
    text-align: left;
}

td {
    padding: 8px 10px;
    border-bottom: 1px solid #eeeeee;
    text-align: right;
}

td:first-child, td:nth-child(5) {
    text-align: left;
}

tr:hover {
    background-color: #f9fbfd;
}

.divider-col {
    width: 20px;
    background-color: var(--bg-color);
    padding: 0;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex: none; /* prevent flex: 1 from .form-group label stretching this */
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #ccc;
    border-radius: 24px;
    transition: background-color 0.25s;
    width: 45px;
    padding: 0;
    border: none;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: #fff;
    border-radius: 50%;
    transition: transform 0.25s;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary-color);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.input-error-highlight {
    border-color: #c62828 !important;
    color: #c62828;
}

.input-error {
    color: #c62828;
    font-size: 0.8rem;
    margin: -4px 0 8px 0;
    text-align: right;
    min-height: 1em;
}

.fixed-payment-savings {
    color: var(--accent-green);
    font-size: 0.8rem;
    margin: -4px 0 8px 0;
    text-align: right;
    min-height: 1em;
}

.fix-btn {
    margin-left: 6px;
    padding: 2px 8px;
    font-size: 0.78rem;
    border: 1px solid #c62828;
    border-radius: 3px;
    background: #fff;
    color: #c62828;
    cursor: pointer;
}

.fix-btn:hover {
    background: #c62828;
    color: #fff;
}

@media (max-width: 600px) {
    body { padding: 10px; }
    .form-group { flex-direction: column; align-items: flex-start; }
    .form-group input, .output-value { width: 100%; text-align: left; margin-top: 4px; }
}

.min-pay-summary {
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--bg-color);
    font-size: 0.82rem;
    font-weight: 700;
    color: #111;
    text-align: center;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-dialog {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 24px;
    width: 360px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}

.modal-dialog h3 {
    margin-top: 0;
    margin-bottom: 18px;
    font-size: 1.05rem;
    color: var(--primary-color);
}

.modal-hint {
    font-size: 0.78rem;
    color: #888;
    margin: 6px 0 16px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

.modal-actions button {
    padding: 7px 18px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 0.88rem;
}

.modal-actions .btn-primary {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.modal-actions .btn-primary:hover {
    background: #003d82;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--bg-color);
}

.btn {
    padding: 7px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s;
}

.btn-outline {
    border-color: var(--border-color);
    background: #fff;
    color: var(--text-color);
}

.btn-outline:hover {
    background: var(--bg-color);
}

.btn-transfer {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.btn-transfer:hover {
    background: #003d82;
}

.modal-dialog-wide {
    width: 520px;
    max-width: calc(100vw - 40px);
    max-height: 90vh;
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.modal-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px 14px;
    border-bottom: 2px solid var(--bg-color);
    border-radius: 8px 8px 0 0;
    background: var(--card-bg);
}

.modal-header h3 {
    margin: 0;
}

.modal-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    color: #aaa;
    padding: 0 2px;
    transition: color 0.15s;
}

.modal-close-btn:hover {
    color: #333;
}

.modal-body {
    overflow-y: auto;
    padding: 16px 24px 24px;
    flex: 1;
    min-height: 0;
}

.modal-body p {
    font-size: 0.88rem;
    margin: 0 0 8px;
    color: #555;
}

.modal-tips {
    margin: 2px 0 12px;
    padding-left: 20px;
    font-size: 0.88rem;
    color: #555;
    line-height: 1.7;
}

.modal-tips li {
    margin-bottom: 2px;
}

.input-warn {
    font-size: 0.8rem;
    color: #7a5800;
    background: #fff8e1;
    border: 1px solid #f9a825;
    border-radius: 4px;
    padding: 6px 10px;
    margin-bottom: 10px;
    line-height: 1.5;
}

.xfer-summary {
    margin-top: 16px;
    padding: 12px 14px;
    background: #f0f7ff;
    border: 1px solid #b3d1f0;
    border-radius: 6px;
    font-size: 0.83rem;
}

.xfer-summary-title {
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #555;
    margin-bottom: 8px;
}

.xfer-summary-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    color: #444;
}

.xfer-summary-divider {
    border-top: 1px solid #b3d1f0;
    margin: 6px 0;
}

.xfer-summary-total {
    font-weight: 600;
}

.xfer-summary-savings {
    font-weight: 700;
    font-size: 0.88rem;
    margin-top: 2px;
}

.limit-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    border: 1px solid currentColor;
    white-space: nowrap;
}

.modal-section-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #888;
    margin: 16px 0 8px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--bg-color);
}

.promo-warning {
    background: #fff5f5;
    border: 1px solid #e57373;
    border-radius: 6px;
    padding: 14px 16px;
    margin-top: 16px;
    font-size: 0.83rem;
    color: #b71c1c;
    line-height: 1.6;
}

.promo-warning strong {
    display: block;
    margin-bottom: 8px;
}

.promo-warning ol {
    margin: 0;
    padding-left: 20px;
}

.promo-warning li {
    margin-bottom: 8px;
}

.promo-warning .adjust-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.promo-warning .adjust-row input[type="checkbox"] {
    width: auto;
    border: none;
    padding: 0;
}

.promo-warning .adjust-row label {
    font-weight: 500;
    flex: none;
}
