/* ============================================================
   Debt Tracker PWA — Design System & Styles
   Mobile-first · Dark/Light theme · Finance app aesthetic
   ============================================================ */

/* ----- CSS Custom Properties (Design Tokens) ----- */
:root {
    /* Palette — dark theme (default) */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --accent-blue: #0f3460;
    --accent-teal: #53d769;
    --accent-red: #e94560;
    --accent-orange: #f5a623;
    --text-primary: #f0f0f0;
    --text-secondary: #a0a8c0;
    --text-muted: #6b7280;
    --border-color: #2a3a5c;
    --input-bg: #0d1b33;
    --overlay: rgba(10, 10, 20, 0.7);
    --card-hover-bg: rgba(255, 255, 255, 0.03);
    --btn-primary-text: #111;
    --summary-gradient-end: var(--accent-blue);

    /* Loan type colors */
    --type-cc: #e94560;
    --type-mortgage: #4a9ff5;
    --type-personal: #a855f7;

    /* DTI gauge colors */
    --dti-green: #53d769;
    --dti-yellow: #f5a623;
    --dti-red: #e94560;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.3);
    --shadow-elevated: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-button: 0 2px 8px rgba(0, 0, 0, 0.2);

    /* Typography */
    --font-family:
        system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    --font-mono:
        "SF Mono", SFMono-Regular, "Consolas", "Liberation Mono", Menlo,
        monospace;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;

    /* Layout */
    --nav-height: 60px;
    --max-width: 600px;
    --header-height: 0px;
}

/* ----- Light Theme Override ----- */
[data-theme="light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8edf2;
    --accent-blue: #0f3460;
    --accent-teal: #2ea043;
    --accent-red: #cf222e;
    --accent-orange: #d4830a;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border-color: #e0e0e0;
    --input-bg: #f9f9f9;
    --overlay: rgba(0, 0, 0, 0.4);
    --card-hover-bg: rgba(0, 0, 0, 0.02);
    --btn-primary-text: #fff;
    --summary-gradient-end: #d6e4f0;

    --type-cc: #cf222e;
    --type-mortgage: #0969da;
    --type-personal: #8250df;

    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-button: 0 1px 4px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .btn-primary {
    color: var(--btn-primary-text);
}

[data-theme="light"] .fab {
    color: var(--btn-primary-text);
}

[data-theme="light"] .badge-cc {
    background-color: rgba(207, 34, 46, 0.12);
}

[data-theme="light"] .badge-mortgage {
    background-color: rgba(9, 105, 218, 0.12);
}

[data-theme="light"] .badge-personal {
    background-color: rgba(130, 80, 223, 0.12);
}

[data-theme="light"] .toast-info {
    background-color: rgba(9, 105, 218, 0.2);
    color: var(--accent-blue);
    border-color: rgba(9, 105, 218, 0.35);
}

[data-theme="light"] .toast-success {
    background-color: rgba(46, 160, 67, 0.2);
    border-color: rgba(46, 160, 67, 0.35);
}

[data-theme="light"] .toast-error {
    background-color: rgba(207, 34, 46, 0.2);
    border-color: rgba(207, 34, 46, 0.35);
}

[data-theme="light"] .toast-warning {
    background-color: rgba(212, 131, 10, 0.2);
    border-color: rgba(212, 131, 10, 0.35);
}

[data-theme="light"] .strategy-toggle .strategy-btn.active {
    background-color: var(--accent-blue);
    color: #fff;
}

[data-theme="light"] .segmented-control input[type="radio"]:checked + label {
    background-color: var(--accent-blue);
    color: #fff;
}

[data-theme="light"] .loan-card-footer {
    background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .summary-card {
    background: linear-gradient(
        135deg,
        var(--bg-secondary),
        var(--summary-gradient-end)
    );
}

/* ----- Reset & Base ----- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--accent-teal);
    text-decoration: none;
    transition: opacity var(--transition-fast);
}

a:hover {
    opacity: 0.85;
}

img {
    max-width: 100%;
    display: block;
}

/* ----- Typography ----- */
h1,
h2,
h3,
h4 {
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-primary);
}

h1 {
    font-size: 1.75rem;
    margin-bottom: var(--space-md);
}
h2 {
    font-size: 1.375rem;
    margin-bottom: var(--space-sm);
}
h3 {
    font-size: 1.125rem;
    margin-bottom: var(--space-sm);
}
h4 {
    font-size: 1rem;
    margin-bottom: var(--space-xs);
}

.text-muted {
    color: var(--text-muted);
}
.text-secondary {
    color: var(--text-secondary);
}
.text-accent {
    color: var(--accent-teal);
}
.text-danger {
    color: var(--accent-red);
}
.text-money {
    font-family: var(--font-mono);
    font-weight: 600;
}

/* ----- Layout ----- */
#app {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--space-md);
    padding-bottom: calc(var(--nav-height) + var(--space-xl));
    min-height: 100vh;
    min-height: 100dvh;
}

.page-header {
    margin-bottom: var(--space-lg);
}

.page-header h1 {
    margin-bottom: var(--space-xs);
}

.page-header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ----- Cards ----- */
.card {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    border: 1px solid var(--border-color);
    transition:
        transform var(--transition-base),
        box-shadow var(--transition-base);
}

.card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-elevated);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
    gap: var(--space-sm);
}

.card-header h3 {
    margin-bottom: 0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-body {
    margin-bottom: var(--space-md);
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    flex-wrap: wrap;
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

/* ----- Badges ----- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge-cc {
    background-color: rgba(233, 69, 96, 0.2);
    color: var(--type-cc);
}

.badge-mortgage {
    background-color: rgba(74, 159, 245, 0.2);
    color: var(--type-mortgage);
}

.badge-personal {
    background-color: rgba(168, 85, 247, 0.2);
    color: var(--type-personal);
}

.badge-strategy {
    background-color: rgba(83, 215, 105, 0.15);
    color: var(--accent-teal);
    font-size: 0.65rem;
}

/* ----- Stats Grid (used in loan cards) ----- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm) var(--space-md);
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.stat-value.positive {
    color: var(--accent-teal);
}

.stat-value.negative {
    color: var(--accent-red);
}

/* ----- Summary Card ----- */
.summary-card {
    background: linear-gradient(
        135deg,
        var(--bg-secondary),
        var(--accent-blue)
    );
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    box-shadow: var(--shadow-elevated);
}

.summary-card h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.summary-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--space-md);
}

.summary-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--font-mono);
    margin-bottom: 2px;
}

.summary-stat-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ----- Buttons ----- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    min-height: 44px;
    min-width: 44px;
    padding: var(--space-sm) var(--space-md);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Primary – teal / green */
.btn-primary {
    background-color: var(--accent-teal);
    color: #111;
    border-color: var(--accent-teal);
    box-shadow: var(--shadow-button);
}

.btn-primary:hover:not(:disabled) {
    background-color: #45c55a;
    border-color: #45c55a;
}

/* Danger – red */
.btn-danger {
    background-color: var(--accent-red);
    color: #fff;
    border-color: var(--accent-red);
}

.btn-danger:hover:not(:disabled) {
    background-color: #d13350;
    border-color: #d13350;
}

/* Secondary – outlined */
.btn-secondary {
    background-color: transparent;
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--text-secondary);
}

/* Ghost – no border */
.btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
    border-color: transparent;
    padding: var(--space-xs) var(--space-sm);
}

.btn-ghost:hover:not(:disabled) {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

/* Small */
.btn-sm {
    min-height: 36px;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8rem;
}

/* Full width */
.btn-block {
    width: 100%;
}

/* Icon button */
.btn-icon {
    padding: var(--space-sm);
    min-width: 44px;
    min-height: 44px;
    border-radius: var(--radius-sm);
}

/* Floating Action Button */
.fab {
    position: fixed;
    bottom: calc(var(--nav-height) + var(--space-md));
    right: var(--space-md);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--accent-teal);
    color: #111;
    border: none;
    box-shadow: var(--shadow-elevated);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    z-index: 50;
}

.fab:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 40px rgba(83, 215, 105, 0.3);
}

.fab:active {
    transform: scale(0.95);
}

/* Button Group */
.btn-group {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

/* ----- Strategy Toggle (prominent buttons) ----- */
.strategy-toggle {
    display: flex;
    gap: 2px;
    background-color: var(--input-bg);
    border-radius: var(--radius-sm);
    padding: 2px;
    margin-bottom: var(--space-md);
}

.strategy-toggle .strategy-btn {
    flex: 1;
    min-height: 44px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: calc(var(--radius-sm) - 2px);
    transition: all var(--transition-base);
    padding: var(--space-sm);
}

.strategy-toggle .strategy-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

.strategy-toggle .strategy-btn.active {
    background-color: var(--accent-blue);
    color: var(--text-primary);
    box-shadow: var(--shadow-button);
}

/* ----- Forms ----- */
.form-group {
    margin-bottom: var(--space-md);
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    min-height: 44px;
    padding: var(--space-sm) var(--space-md);
    background-color: var(--input-bg);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 1rem;
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
    appearance: none;
    -webkit-appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent-teal);
    box-shadow: 0 0 0 3px rgba(83, 215, 105, 0.15);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input.error,
.form-select.error,
.form-input.input-error,
.form-select.input-error {
    border-color: var(--accent-red);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

.form-error {
    font-size: 0.75rem;
    color: var(--accent-red);
    margin-top: var(--space-xs);
    display: none;
}

.form-error.visible {
    display: block;
}

/* Per-field inline validation error message */
.field-error {
    font-size: 0.75rem;
    color: var(--accent-red);
    margin-top: var(--space-xs);
    display: none;
    line-height: 1.3;
}

.field-error.visible {
    display: block;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

/* Biweekly payment note */
.biweekly-note {
    font-size: 0.78rem;
    color: var(--accent-orange);
    margin-top: var(--space-xs);
    padding: var(--space-sm);
    background-color: rgba(245, 166, 35, 0.08);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-orange);
}

/* Select arrow */
.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a8c0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Currency input wrapper */
.input-currency {
    position: relative;
}

.input-currency::before {
    content: var(--currency-symbol, "$");
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1rem;
    z-index: 1;
    pointer-events: none;
}

.input-currency .form-input {
    padding-left: 28px;
}

/* Percentage input wrapper */
.input-percent {
    position: relative;
}

.input-percent::after {
    content: "%";
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1rem;
    pointer-events: none;
}

.input-percent .form-input {
    padding-right: 32px;
}

/* Segmented control (APR / APY toggle) */
.segmented-control {
    display: flex;
    background-color: var(--input-bg);
    border-radius: var(--radius-sm);
    padding: 2px;
    border: 1.5px solid var(--border-color);
    overflow: hidden;
}

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

.segmented-control label {
    flex: 1;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all var(--transition-base);
    border-radius: calc(var(--radius-sm) - 2px);
    user-select: none;
    -webkit-user-select: none;
}

.segmented-control input[type="radio"]:checked + label {
    background-color: var(--accent-blue);
    color: var(--text-primary);
    box-shadow: var(--shadow-button);
}

.segmented-control label:hover {
    color: var(--text-primary);
}

/* Rate type row */
.rate-row {
    display: flex;
    gap: var(--space-sm);
    align-items: flex-end;
}

.rate-row .input-percent {
    flex: 1;
}

.rate-row .segmented-control {
    flex: 0 0 140px;
    margin-bottom: 0;
}

/* Toggle switch */
.toggle-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
}

.toggle {
    position: relative;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

.toggle input {
    display: none;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background-color: var(--border-color);
    border-radius: 14px;
    cursor: pointer;
    transition: background-color var(--transition-base);
}

.toggle-slider::after {
    content: "";
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: #fff;
    top: 3px;
    left: 3px;
    transition: transform var(--transition-base);
}

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

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

/* ----- Inline strategy select (in loan card footer) ----- */
.strategy-select-inline {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.strategy-select-inline .form-select {
    min-height: 36px;
    font-size: 0.8rem;
    padding: 4px 32px 4px 10px;
    width: auto;
    min-width: 120px;
}

/* ----- Bottom Navigation ----- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-inner {
    display: flex;
    width: 100%;
    max-width: var(--max-width);
    align-items: center;
    justify-content: space-around;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 64px;
    min-height: 44px;
    padding: var(--space-xs);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color var(--transition-base);
    cursor: pointer;
    border: none;
    background: none;
    font-family: var(--font-family);
    gap: 2px;
}

.nav-item:hover {
    color: var(--text-secondary);
}

.nav-item.active {
    color: var(--accent-teal);
}

.nav-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-icon svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    stroke: currentColor;
}

/* ----- Toast Notifications ----- */
.toast-container {
    position: fixed;
    top: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    z-index: 9999;
    pointer-events: none;
    padding: var(--space-sm) var(--space-md);
    padding-top: calc(env(safe-area-inset-top, 0px) + var(--space-sm));
    gap: var(--space-xs);
    max-width: 340px;
    width: 100%;
}

.toast {
    max-width: 320px;
    width: auto;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 500;
    pointer-events: auto;
    box-shadow: var(--shadow-elevated);
    transform: translateX(120%);
    opacity: 0;
    transition:
        transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    cursor: pointer;
    line-height: 1.3;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast-info {
    background-color: rgba(15, 52, 96, 0.75);
    color: var(--text-primary);
    border: 1px solid rgba(74, 159, 245, 0.4);
}

.toast-success {
    background-color: rgba(83, 215, 105, 0.25);
    color: var(--accent-teal);
    border: 1px solid rgba(83, 215, 105, 0.4);
}

.toast-error {
    background-color: rgba(233, 69, 96, 0.25);
    color: var(--accent-red);
    border: 1px solid rgba(233, 69, 96, 0.4);
}

.toast-warning {
    background-color: rgba(245, 166, 35, 0.25);
    color: var(--accent-orange);
    border: 1px solid rgba(245, 166, 35, 0.4);
}

/* ----- Loading Spinner ----- */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    gap: var(--space-md);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-teal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Inline spinner for buttons */
.btn .spinner-inline {
    width: 18px;
    height: 18px;
    border-width: 2px;
    animation: spin 0.6s linear infinite;
}

/* ----- Empty State ----- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-2xl) var(--space-lg);
    gap: var(--space-md);
}

.empty-state-icon {
    font-size: 3rem;
    opacity: 0.4;
    margin-bottom: var(--space-sm);
}

.empty-state h3 {
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.empty-state p {
    color: var(--text-muted);
    font-size: 0.9rem;
    max-width: 280px;
}

/* ----- Loan Card ----- */
.loan-card {
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-card);
    margin-bottom: var(--space-md);
    overflow: hidden;
    transition:
        transform var(--transition-base),
        box-shadow var(--transition-base);
}

.loan-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-elevated);
}

.loan-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    gap: var(--space-sm);
}

.loan-card-vendor {
    font-size: 1.1rem;
    font-weight: 700;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.payoff-priority {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 6px;
    border-radius: 50%;
    background: var(--accent-teal);
    color: #111;
    font-size: 0.75rem;
    font-weight: 800;
    flex-shrink: 0;
}

.loan-card-body {
    padding: 0 var(--space-md) var(--space-md);
}

.loan-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-top: 1px solid var(--border-color);
    background-color: rgba(0, 0, 0, 0.1);
    flex-wrap: wrap;
}

.loan-card-actions {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

/* ----- Payoff Timeline / Gantt Chart Area ----- */
.chart-container {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-lg);
    box-shadow: var(--shadow-card);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.chart-container h3 {
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-color);
}

.chart-canvas-wrap {
    position: relative;
    width: 100%;
    min-height: 200px;
}

.chart-canvas-wrap canvas {
    display: block;
    width: 100%;
}

/* ----- Auth Pages ----- */
.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--nav-height) - var(--space-2xl));
    min-height: calc(100dvh - var(--nav-height) - var(--space-2xl));
    padding: var(--space-lg);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--shadow-elevated);
    border: 1px solid var(--border-color);
}

.auth-logo {
    text-align: center;
    margin-bottom: var(--space-lg);
}

.auth-logo h1 {
    font-size: 1.5rem;
    margin-bottom: var(--space-xs);
}

.auth-logo .subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.auth-footer {
    text-align: center;
    margin-top: var(--space-lg);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-footer a {
    font-weight: 600;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin: var(--space-lg) 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background-color: var(--border-color);
}

/* ----- Settings Page ----- */
.settings-section {
    margin-bottom: var(--space-xl);
}

/* Export buttons row */
.export-buttons {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.settings-section h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-color);
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: var(--space-sm) 0;
    gap: var(--space-md);
}

.settings-row-label {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.settings-row-value {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: right;
}

/* ----- Confirm Dialog ----- */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background-color: var(--overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: var(--space-md);
    animation: fadeIn 0.15s ease;
}

.dialog {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 360px;
    width: 100%;
    box-shadow: var(--shadow-elevated);
    animation: slideUp 0.2s ease;
}

.dialog h3 {
    margin-bottom: var(--space-sm);
}

.dialog p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: var(--space-lg);
}

.dialog-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ----- Payment Form (quick form) ----- */
.payment-form {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    box-shadow: var(--shadow-card);
}

.payment-form h2 {
    margin-bottom: var(--space-lg);
}

/* ----- Utility Classes ----- */
.flex {
    display: flex;
}
.flex-col {
    flex-direction: column;
}
.flex-wrap {
    flex-wrap: wrap;
}
.items-center {
    align-items: center;
}
.justify-between {
    justify-content: space-between;
}
.justify-center {
    justify-content: center;
}
.gap-xs {
    gap: var(--space-xs);
}
.gap-sm {
    gap: var(--space-sm);
}
.gap-md {
    gap: var(--space-md);
}
.gap-lg {
    gap: var(--space-lg);
}
.w-full {
    width: 100%;
}
.text-center {
    text-align: center;
}
.text-right {
    text-align: right;
}
.mt-sm {
    margin-top: var(--space-sm);
}
.mt-md {
    margin-top: var(--space-md);
}
.mt-lg {
    margin-top: var(--space-lg);
}
.mb-sm {
    margin-bottom: var(--space-sm);
}
.mb-md {
    margin-bottom: var(--space-md);
}
.mb-lg {
    margin-bottom: var(--space-lg);
}
.hidden {
    display: none !important;
}

/* ----- DTI (Debt-to-Income) Card ----- */
.dti-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    box-shadow: var(--shadow-card);
}

.dti-card h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.dti-value {
    font-size: 2rem;
    font-weight: 700;
    font-family: var(--font-mono);
    margin-bottom: var(--space-xs);
}

.dti-value.dti-green {
    color: var(--dti-green);
}
.dti-value.dti-yellow {
    color: var(--dti-yellow);
}
.dti-value.dti-red {
    color: var(--dti-red);
}

.dti-bar {
    width: 100%;
    height: 8px;
    background-color: var(--input-bg);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: var(--space-sm) 0;
}

.dti-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width var(--transition-slow);
}

.dti-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ----- Payment History Table ----- */
.payment-history {
    margin-top: var(--space-lg);
}

.payment-history h3 {
    font-size: 0.9rem;
    margin-bottom: var(--space-md);
    color: var(--text-secondary);
}

.payment-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.payment-table th {
    text-align: left;
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: var(--space-sm) var(--space-sm);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.payment-table td {
    padding: var(--space-sm) var(--space-sm);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: var(--font-mono);
    white-space: nowrap;
}

.payment-table tr:last-child td {
    border-bottom: none;
}

.payment-table-empty {
    color: var(--text-muted);
    text-align: center;
    padding: var(--space-lg);
    font-style: italic;
    font-size: 0.85rem;
}

/* Responsive: make table scroll horizontally on small screens */
.payment-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(-1 * var(--space-md));
    padding: 0 var(--space-md);
}

/* ----- Offline Banner ----- */
.offline-banner {
    display: none;
    background-color: var(--accent-orange);
    color: #111;
    text-align: center;
    padding: var(--space-xs) var(--space-md);
    font-size: 0.8rem;
    font-weight: 600;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
}

body.is-offline .offline-banner {
    display: block;
}

/* ----- Sync Status / Offline Indicator ----- */
.sync-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
    padding: var(--space-xs) var(--space-md);
}

.offline-indicator {
    display: inline-block;
    color: var(--accent-orange);
    font-weight: 600;
    margin-left: 0.25em;
}

body.is-offline .sync-status .offline-indicator {
    animation: pulse-offline 2s ease-in-out infinite;
}

@keyframes pulse-offline {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ----- Scrollbar Styling ----- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-muted);
}

/* ----- Responsive ----- */
@media (min-width: 640px) {
    #app {
        padding: var(--space-lg) var(--space-xl);
        padding-bottom: calc(var(--nav-height) + var(--space-2xl));
    }

    .summary-stat-value {
        font-size: 1.5rem;
    }

    .auth-card {
        padding: var(--space-2xl);
    }
}

/* Landscape / larger phones */
@media (min-width: 480px) {
    .loan-card-footer {
        flex-wrap: nowrap;
    }
}

/* Safe area for bottom nav (notched phones) */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .bottom-nav {
        height: calc(var(--nav-height) + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
    }

    #app {
        padding-bottom: calc(
            var(--nav-height) + env(safe-area-inset-bottom) + var(--space-xl)
        );
    }

    .fab {
        bottom: calc(
            var(--nav-height) + env(safe-area-inset-bottom) + var(--space-md)
        );
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print — hide nav, etc. */
@media print {
    .bottom-nav,
    .fab,
    .toast-container,
    .offline-banner {
        display: none !important;
    }

    #app {
        padding-bottom: 0;
    }

    body {
        background: #fff;
        color: #000;
    }

    .card,
    .loan-card,
    .summary-card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* ----- Theme transition (smooth color changes) ----- */
body,
.card,
.loan-card,
.summary-card,
.bottom-nav,
.auth-card,
.dialog,
.form-input,
.form-select,
.btn,
.toast,
.chart-container,
.payment-form,
.dti-card {
    transition:
        background-color var(--transition-base),
        border-color var(--transition-base),
        color var(--transition-base),
        box-shadow var(--transition-base);
}

/* ----- Amortization Schedule Section ----- */
.amort-section {
    margin-bottom: var(--space-md);
}

.amort-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
}

.amort-header h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 600;
}

.amort-loan-select {
    margin: var(--space-sm) 0;
    font-size: 0.85rem;
}

.amort-min-payment {
    margin: var(--space-xs) 0 var(--space-sm);
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.payment-table-combined th[colspan] {
    text-align: center;
    border-bottom: none;
    padding-bottom: 2px;
}

.payment-table-combined th[rowspan] {
    vertical-align: middle;
}

.amort-loan-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: var(--space-sm) 0;
}

.amort-scroll {
    max-height: 340px;
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: var(--space-sm);
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

/* Sticky header row in the amortization table */
.amort-scroll .payment-table thead th {
    position: sticky;
    top: 0;
    background-color: var(--card-bg);
    z-index: 1;
}

/* ============================================================
   Admin Portal
   ============================================================ */

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.admin-table th,
.admin-table td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.admin-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.admin-user-email {
    font-weight: 500;
}
.admin-user-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.admin-actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.badge-admin {
    background: var(--accent-teal);
    color: #fff;
}
.badge-danger {
    background: var(--danger);
    color: #fff;
}
.badge-premium {
    background: #f59e0b;
    color: #000;
}
.btn-warning {
    background: #f59e0b;
    color: #000;
    border: none;
}
.btn-warning:hover {
    background: #d97706;
}
.search-row {
    display: flex;
    gap: 8px;
}
.search-row .form-input {
    flex: 1;
}
.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}
