/*
 * MortgageReady -- Component Styles
 *
 * Reusable UI components: buttons, cards, forms, badges, progress bars.
 * Consumer-grade polish: hover states, focus rings, transitions.
 */

/* ==================== BUTTONS ==================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

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

.btn-primary {
    background: var(--brand);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--brand-dark);
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.97);
    filter: brightness(0.9);
}

.btn-secondary {
    background: var(--bg-white);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg);
    border-color: var(--text-muted);
}

.btn-secondary:active:not(:disabled) {
    transform: scale(0.97);
    filter: brightness(0.95);
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
    border-radius: var(--radius);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* ==================== CARDS ==================== */

.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    margin-bottom: 16px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.card-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ==================== FORMS ==================== */

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    background: var(--bg-white);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(27, 106, 201, 0.1);
}

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

.form-input.error {
    border-color: var(--error);
}

.form-error {
    font-size: 12px;
    color: var(--error);
    margin-top: 4px;
}

/* Info toggle button */
.info-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid var(--brand);
    background: transparent;
    color: var(--brand);
    font-size: 11px;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    vertical-align: middle;
    margin-left: 4px;
    padding: 0;
    line-height: 1;
    transition: background 0.15s ease, color 0.15s ease;
}

.info-toggle:hover {
    background: var(--brand);
    color: white;
}

/* Expandable info panel */
.form-info {
    background: #EDF4FB;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Ask AI advisor link */
.ask-ai-link {
    display: inline-block;
    margin-top: 4px;
    font-size: 12px;
    font-weight: 500;
    color: var(--brand);
    text-decoration: none;
    cursor: pointer;
    transition: color 0.15s ease;
}

.ask-ai-link:hover {
    color: var(--brand-dark);
    text-decoration: underline;
}

/* Step-level AI help strip -- one link per wizard step, bottom of card */
.wizard-help-strip {
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
    text-align: center;
}

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

.input-currency::before {
    content: "$";
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 15px;
}

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

/* Toggle / boolean */
.form-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.form-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--brand);
}

/* ==================== WIZARD PROGRESS ==================== */

.wizard-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 32px;
}

.progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 80px;
}

.step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.progress-step.active .step-number {
    background: var(--brand);
    color: white;
}

.progress-step.completed .step-number {
    background: var(--success);
    color: white;
}

.step-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.progress-step.active .step-label {
    color: var(--brand);
}

.progress-step.completed .step-label {
    color: var(--success);
}

.progress-connector {
    flex: 1;
    height: 2px;
    background: var(--border);
    max-width: 60px;
    margin: 0 4px;
    margin-bottom: 20px; /* align with step-number center */
}

/* ==================== WIZARD NAV ==================== */

.wizard-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}

/* ==================== CHAT ==================== */

.chat-inner {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - 64px);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 0;
}

.chat-message {
    margin-bottom: 16px;
    display: flex;
    gap: 12px;
}

.chat-message.user {
    flex-direction: row-reverse;
}

.chat-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.6;
}

.chat-message.assistant .chat-bubble {
    background: var(--bg-white);
    border: 1px solid var(--border);
}

.chat-message.user .chat-bubble {
    background: var(--brand);
    color: white;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}

.chat-input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 15px;
    resize: none;
    min-height: 44px;
    max-height: 120px;
}

.chat-input-area textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(27, 106, 201, 0.1);
}

/* Chat bubble content styling */
.chat-bubble h3 {
    font-size: 16px;
    font-weight: 700;
    margin: 18px 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-light, #E5E5E5);
    color: var(--text);
}

.chat-bubble h3:first-child {
    margin-top: 0;
}

.chat-bubble h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 14px 0 6px;
    color: var(--text-secondary);
}

.chat-bubble p {
    margin: 0 0 10px;
    line-height: 1.6;
}

.chat-bubble p:last-child {
    margin-bottom: 0;
}

.chat-bubble ul {
    margin: 6px 0 12px 0;
    padding-left: 22px;
    line-height: 1.65;
}

.chat-bubble li {
    margin-bottom: 5px;
}

.chat-bubble li:last-child {
    margin-bottom: 0;
}

.chat-bubble hr {
    border: none;
    border-top: 2px solid var(--border-light, #E5E5E5);
    margin: 20px 0;
}

.chat-bubble strong {
    font-weight: 600;
}

.chat-bubble blockquote {
    margin: 8px 0;
    padding: 8px 12px;
    border-left: 3px solid var(--brand);
    background: #F7F8FA;
    border-radius: 0 6px 6px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ==================== CHAT TABLES ==================== */

.chat-table-wrap {
    margin: 12px 0;
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.chat-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--bg-white);
}

.chat-table thead {
    background: #F4F6F9;
    border-bottom: 2px solid var(--border);
}

.chat-table th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

.chat-table td {
    padding: 9px 14px;
    border-bottom: 1px solid #F0F0F0;
    color: var(--text);
    line-height: 1.4;
}

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

.chat-table tbody tr:hover {
    background: #FAFBFC;
}

/* Highlight total/summary rows (cells containing bold text) */
.chat-table tbody tr:last-child {
    font-weight: 600;
    background: #F0F7FF;
}

/* Mobile: tighter padding */
@media (max-width: 640px) {
    .chat-table th,
    .chat-table td {
        padding: 8px 10px;
        font-size: 13px;
    }
    .chat-table th {
        font-size: 11px;
    }
    .chat-table-wrap {
        margin: 8px -4px;
    }
}

/* Streaming cursor (blinking caret) */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 16px;
    background: var(--brand);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 0.8s step-end infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Tool execution indicator */
.tool-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    margin-top: 8px;
    color: var(--brand);
    font-size: 13px;
    font-weight: 500;
    animation: fadeIn 0.15s ease;
}

.tool-indicator .loading-spinner {
    width: 16px;
    height: 16px;
    border-width: 2px;
    flex-shrink: 0;
}

.tool-label {
    color: var(--text-secondary);
}

/* Chat report action buttons (Download PDF, Share, View Full Report) */
.chat-report-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light, #E5E5E5);
    flex-wrap: wrap;
}

.chat-report-actions .btn {
    font-size: 12px;
    padding: 7px 14px;
}

.chat-report-actions a.btn {
    text-decoration: none;
}

/* Report CTA -- appears above chat input after 2+ tool calls */
.report-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #E8F1FB 0%, #F0F7FF 100%);
    border: 1px solid #D0E3F7;
    border-radius: 10px;
    margin: 0 16px 8px;
    animation: ctaSlideIn 0.3s ease-out;
}

.report-cta-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.report-cta-btn {
    white-space: nowrap;
    font-size: 13px !important;
    padding: 8px 18px !important;
    box-shadow: 0 2px 6px rgba(27, 106, 201, 0.2);
}

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

@media (max-width: 640px) {
    .report-cta {
        flex-direction: column;
        gap: 8px;
        margin: 0 8px 8px;
    }
    .report-cta-btn {
        width: 100%;
    }
}

/* Suggestion chips */
.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0 16px;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    color: var(--brand);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.chip:hover {
    background: var(--brand-light);
    border-color: var(--brand);
}

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

/* Send button disabled state */
.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==================== REPORT ==================== */

.report-header {
    text-align: center;
    margin-bottom: 32px;
}

.report-score {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 32px;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 16px;
}

.score-number {
    font-size: 64px;
    font-weight: 800;
    line-height: 1;
    color: var(--brand);
}

.score-label {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

.score-grade {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    margin-top: 8px;
}

.grade-a { background: var(--success-bg); color: var(--success); }
.grade-b { background: var(--info-bg); color: var(--info); }
.grade-c { background: var(--warning-bg); color: var(--warning); }
.grade-d, .grade-f { background: var(--error-bg); color: var(--error); }

/* Report sections */
.report-section {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}

.report-section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

/* ==================== BADGES ==================== */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-pass {
    background: var(--success-bg);
    color: var(--success);
}

.badge-fail {
    background: var(--error-bg);
    color: var(--error);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

/* ==================== TABLE ==================== */

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

.data-table th,
.data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.data-table th {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    font-size: 14px;
}

.data-table .amount {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ==================== LOADING ==================== */

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==================== TOAST ==================== */

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: white;
    background: var(--text);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

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

/* ==================== MOBILE RESPONSIVE ==================== */

@media (max-width: 640px) {

    /* --- Header --- */
    .header-nav {
        gap: 2px;
    }

    .nav-btn {
        padding: 8px 12px;
        font-size: 13px;
        min-height: 44px;
    }

    .logo {
        font-size: 16px;
    }

    /* --- Wizard progress bar --- */
    .wizard-progress {
        gap: 0;
        padding: 0 4px;
    }

    .progress-step {
        min-width: 48px;
    }

    .step-number {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .step-label {
        font-size: 10px;
    }

    .progress-connector {
        max-width: 28px;
        margin: 0 2px;
        margin-bottom: 16px;
    }

    /* --- Chat --- */
    .chat-inner {
        height: calc(100vh - var(--header-height) - 40px);
    }

    .chat-bubble {
        max-width: 90%;
    }

    .chip {
        padding: 10px 14px;
        font-size: 12px;
        min-height: 44px;
    }

    .chat-input-area {
        gap: 6px;
    }

    .chat-input-area textarea {
        font-size: 14px;
        min-height: 40px;
    }

    .btn-send {
        padding: 8px 14px;
        font-size: 13px;
        min-height: 44px;
    }

    /* --- Chat report actions (stack vertically on mobile) --- */
    .chat-report-actions {
        flex-direction: column;
    }

    .chat-report-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* --- Report: score ring --- */
    .report-score-ring {
        width: 120px !important;
        height: 120px !important;
    }

    /* --- Report: summary stats row (4 items -> 2x2 grid) --- */
    .report-stats-row {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 16px !important;
        justify-items: center;
    }

    /* --- Report: affordability cards (stack vertically) --- */
    .report-afford-card {
        min-width: 0 !important;
        flex-basis: 100% !important;
    }

    /* --- Report: student loan cards (stack vertically) --- */
    .report-loan-card {
        min-width: 0 !important;
        flex-basis: 100% !important;
    }

    .report-loan-cards {
        flex-direction: column !important;
    }

    /* --- Report: action items (allow wrapping) --- */
    .report-action-header {
        flex-wrap: wrap;
        gap: 4px;
    }

    /* --- Report: button row (stack vertically) --- */
    .report-actions {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 20px 16px !important;
    }

    .report-actions .btn {
        margin: 0 !important;
        width: 100%;
        max-width: 280px;
    }

    /* --- Report: section padding tighter on mobile --- */
    .report-section {
        padding: 16px;
    }

    /* --- Toast: don't overflow on narrow screens --- */
    .toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
        text-align: center;
    }
}
