/* Interest Rate App — Premium Design System v2 */

/* ── Animated Background ── */
@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,0.3); }
    50% { box-shadow: 0 0 20px 4px rgba(99,102,241,0.15); }
}
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

:root {
    /* Brand — Rich indigo/violet */
    --brand: #6366f1;
    --brand-light: #818cf8;
    --brand-dark: #4f46e5;
    --brand-deeper: #3730a3;
    --brand-50: #eef2ff;
    --brand-100: #e0e7ff;
    --brand-600: #4f46e5;
    --brand-700: #4338ca;
    --brand-glow: rgba(99,102,241,0.25);

    /* Accent — Warm amber for key values */
    --accent: #f59e0b;
    --accent-light: #fbbf24;
    --accent-dark: #d97706;

    /* Surfaces — Warm with depth */
    --surface-bg: #f1f5f9;
    --surface-card: rgba(255,255,255,0.72);
    --surface-card-solid: #ffffff;
    --surface-muted: rgba(241,245,249,0.8);
    --surface-dark: #0f172a;
    --surface-dark-light: #1e293b;

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-on-dark: #f8fafc;
    --text-on-dark-muted: #94a3b8;

    /* Borders */
    --border-light: rgba(226,232,240,0.6);
    --border-default: #cbd5e1;
    --border-glass: rgba(255,255,255,0.3);

    /* Status */
    --success: #10b981;
    --success-bg: #ecfdf5;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --error: #ef4444;
    --error-bg: #fef2f2;

    /* Shadows — Layered with color tint */
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.04), 0 1px 3px rgba(15,23,42,0.06);
    --shadow-md: 0 4px 6px rgba(15,23,42,0.04), 0 2px 4px rgba(15,23,42,0.06);
    --shadow-lg: 0 10px 25px rgba(15,23,42,0.08), 0 4px 10px rgba(15,23,42,0.05);
    --shadow-xl: 0 20px 40px rgba(15,23,42,0.12), 0 8px 16px rgba(15,23,42,0.08);
    --shadow-glow: 0 4px 20px rgba(99,102,241,0.15);
    --shadow-card: 0 1px 3px rgba(15,23,42,0.04), 0 4px 12px rgba(15,23,42,0.03);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Glass */
    --glass-bg: rgba(255,255,255,0.65);
    --glass-border: rgba(255,255,255,0.25);
    --glass-blur: blur(16px);

    /* Rating colors — Richer gradients */
    --rate-aaa: #059669;
    --rate-aa1: #10b981;
    --rate-aa2: #34d399;
    --rate-aa3: #6ee7b7;
    --rate-a1: #f59e0b;
    --rate-a2: #d97706;
    --rate-a3: #ea580c;
    --rate-baa1: #dc2626;

    /* Legacy compat aliases */
    --brand-blue: var(--brand);
    --brand-blue-light: var(--brand-light);
    --brand-blue-dark: var(--brand-dark);
    --brand-blue-50: var(--brand-50);
    --brand-blue-100: var(--brand-100);
    --brand-blue-600: var(--brand-600);
    --brand-blue-700: var(--brand-700);
    --surface-card-legacy: #ffffff;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: 'Heebo', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--surface-bg);
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(99,102,241,0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(245,158,11,0.04) 0%, transparent 50%);
    background-attachment: fixed;
    color: var(--text-primary);
    direction: rtl;
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Login Page ── */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(-45deg, #0f172a, #1e1b4b, #312e81, #1e293b);
    background-size: 300% 300%;
    animation: gradientShift 12s ease infinite;
    position: relative;
}
.login-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 30% 20%, rgba(99,102,241,0.15) 0%, transparent 50%),
        radial-gradient(circle at 70% 80%, rgba(139,92,246,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.login-card {
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255,255,255,0.1);
    padding: 44px 40px;
    width: 100%;
    max-width: 440px;
    position: relative;
    animation: fadeInUp 0.5s ease-out;
}

.logo-section {
    text-align: center;
    margin-bottom: 28px;
}
.logo-section img {
    height: 42px;
    margin-bottom: 14px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}
.logo-section h1 {
    font-size: 26px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.logo-section p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 6px;
    font-weight: 300;
}

.auth-tabs {
    display: flex;
    gap: 4px;
    background: var(--surface-muted);
    padding: 4px;
    border-radius: var(--radius-full);
    margin-bottom: 28px;
}
.auth-tab {
    flex: 1;
    text-align: center;
    padding: 10px;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.auth-tab.active {
    background: white;
    color: var(--brand);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.auth-form { display: none; }
.auth-form.active { display: block; animation: fadeInUp 0.3s ease-out; }

.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.2px;
}
.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 16px;
    font-family: inherit;
    transition: all 0.2s ease;
    direction: ltr;
    text-align: left;
    background: rgba(255,255,255,0.8);
}
.form-input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-glow);
    background: white;
}
.form-input[name="full_name"] {
    direction: rtl;
    text-align: right;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    gap: 8px;
    position: relative;
    overflow: hidden;
}
.btn-primary {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: white;
    width: 100%;
    box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--brand-light) 0%, var(--brand) 100%);
    box-shadow: 0 6px 20px rgba(99,102,241,0.4);
    transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-secondary {
    background: transparent;
    border: 2px solid var(--brand);
    color: var(--brand);
}
.btn-secondary:hover {
    background: var(--brand-50);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 16px;
    font-size: 14px;
    border-radius: var(--radius-full);
}
.btn-ghost:hover {
    background: rgba(99,102,241,0.06);
    color: var(--brand);
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    margin-bottom: 16px;
    display: none;
    animation: slideDown 0.3s ease-out;
}
.alert-error { background: var(--error-bg); color: var(--error); border: 1px solid #fecaca; }
.alert-success { background: var(--success-bg); color: #166534; border: 1px solid #bbf7d0; }

.verification-section { display: none; }
.verification-section .code-input {
    font-size: 24px;
    letter-spacing: 8px;
    text-align: center;
    max-width: 200px;
    margin: 0 auto;
    display: block;
}

.link-text {
    color: var(--brand);
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.15s;
}
.link-text:hover { color: var(--brand-dark); text-decoration: underline; }

.divider-or {
    display: flex;
    align-items: center;
    margin: 20px 0;
    gap: 12px;
}
.divider-or::before, .divider-or::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-default), transparent);
}
.divider-or span {
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
}

/* ── Company Chips ── */
.company-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0;
    min-height: 24px;
}
.company-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    background: rgba(255,255,255,0.7);
    backdrop-filter: blur(8px);
    border: 1.5px solid var(--chip-color, var(--border-default));
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}
.company-chip:hover {
    background: var(--brand-50);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.chip-sector {
    font-size: 11px;
    color: var(--text-muted);
    margin-right: 2px;
}
.chip-remove {
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    color: var(--text-muted);
    margin-right: 2px;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.chip-remove:hover {
    background: var(--error);
    color: white;
}

/* ── Dashboard Header ── */
.app-header {
    background: linear-gradient(135deg, var(--surface-dark) 0%, #1e1b4b 50%, var(--surface-dark-light) 100%);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 4px 20px rgba(15,23,42,0.3);
    border-bottom: 1px solid rgba(99,102,241,0.2);
}
.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}
.header-right img {
    height: 34px;
    filter: brightness(0) invert(1) drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}
.header-right h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-on-dark);
    letter-spacing: -0.3px;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.credits-badge {
    background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(139,92,246,0.2));
    color: var(--brand-light);
    padding: 6px 16px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 600;
    border: 1px solid rgba(99,102,241,0.3);
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
}
.credits-badge:hover {
    background: linear-gradient(135deg, rgba(99,102,241,0.3), rgba(139,92,246,0.3));
    border-color: rgba(99,102,241,0.5);
    transform: translateY(-1px);
}

.user-name {
    color: var(--text-on-dark-muted);
    font-size: 14px;
}

.logout-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    padding: 6px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-on-dark-muted);
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
}
.logout-btn:hover {
    background: rgba(239,68,68,0.15);
    border-color: rgba(239,68,68,0.3);
    color: #fca5a5;
}

/* ── Tabs ── */
.tabs-container {
    background: var(--surface-dark);
    padding: 0 28px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.tabs-container::-webkit-scrollbar { height: 0; }
.tabs {
    display: flex;
    gap: 2px;
    min-width: max-content;
}
.tab {
    padding: 13px 20px;
    font-size: 13.5px;
    font-weight: 500;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}
.tab:hover {
    color: rgba(255,255,255,0.8);
}
.tab.active {
    color: white;
    border-bottom-color: var(--brand-light);
    font-weight: 600;
}
.tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 20%;
    right: 20%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--brand-light), transparent);
    filter: blur(4px);
}

/* ── Content ── */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px;
    animation: fadeInUp 0.4s ease-out;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeInUp 0.3s ease-out; }

.card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-card);
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}
.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card-header h2 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.2px;
}

/* Controls row */
.controls-row {
    display: flex;
    gap: 16px;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding: 16px 20px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.control-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.control-group select, .control-group input[type="date"] {
    padding: 9px 14px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    min-width: 140px;
    direction: ltr;
    background: rgba(255,255,255,0.8);
    transition: all 0.2s ease;
}
.control-group select:focus, .control-group input:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px var(--brand-glow);
    background: white;
}

/* ── Rate Table ── */
.rate-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}
.rate-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    direction: rtl;
    text-align: center;
}
.rate-table th {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 12px 14px;
    font-weight: 700;
    font-size: 11px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-light);
    position: sticky;
    top: 0;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.rate-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(226,232,240,0.5);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    transition: background 0.15s ease;
}
.rate-table tbody tr:hover {
    background: rgba(99,102,241,0.04);
}
.rate-table .maturity-col {
    font-weight: 700;
    background: linear-gradient(90deg, #f8fafc, transparent);
    text-align: right;
    padding-right: 16px;
    color: var(--text-secondary);
}

/* Rating-specific colors — with better contrast */
.rate-aaa { color: var(--rate-aaa); font-weight: 700; }
.rate-aa1 { color: var(--rate-aa1); font-weight: 500; }
.rate-aa2 { color: var(--rate-aa2); font-weight: 500; }
.rate-aa3 { color: var(--rate-aa3); font-weight: 500; }
.rate-a1 { color: var(--rate-a1); font-weight: 500; }
.rate-a2 { color: var(--rate-a2); font-weight: 500; }
.rate-a3 { color: var(--rate-a3); font-weight: 500; }
.rate-baa1 { color: var(--rate-baa1); font-weight: 700; }

/* ── Charts ── */
.chart-container {
    position: relative;
    width: 100%;
    height: 400px;
}

/* ── Stat Cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--brand), var(--brand-light));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}
.stat-value {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
    letter-spacing: -0.5px;
}
.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* ── Chatbot ── */
.chat-toggle {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand) 0%, #8b5cf6 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(99,102,241,0.35);
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: pulseGlow 3s ease-in-out infinite;
}
.chat-toggle:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 12px 32px rgba(99,102,241,0.45);
}

.chat-panel {
    position: fixed;
    bottom: 92px;
    left: 24px;
    width: 380px;
    max-height: 520px;
    background: var(--surface-card-solid);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-light);
    display: none;
    flex-direction: column;
    z-index: 300;
    overflow: hidden;
}
.chat-panel.open {
    display: flex;
    animation: fadeInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-header {
    background: linear-gradient(135deg, var(--surface-dark) 0%, #1e1b4b 100%);
    color: white;
    padding: 18px 22px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat-close {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.chat-close:hover { background: rgba(255,255,255,0.2); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    max-height: 360px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-msg {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    max-width: 85%;
    line-height: 1.5;
    direction: rtl;
    animation: fadeInUp 0.2s ease-out;
}
.chat-msg.bot {
    background: var(--surface-muted);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.chat-msg.user {
    background: linear-gradient(135deg, var(--brand) 0%, #7c3aed 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(99,102,241,0.2);
}

.chat-input-row {
    display: flex;
    gap: 8px;
    padding: 14px 16px;
    border-top: 1px solid var(--border-light);
    background: rgba(248,250,252,0.5);
}
.chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: 14px;
    direction: rtl;
    transition: all 0.2s ease;
    background: white;
}
.chat-input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-glow);
}
.chat-send {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.chat-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}

/* ── Chat Enhancements ── */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
}
.chat-suggestion {
    background: var(--brand-50);
    border: 1px solid var(--brand-100);
    color: var(--brand-dark);
    border-radius: var(--radius-full);
    padding: 5px 12px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    direction: rtl;
}
.chat-suggestion:hover {
    background: var(--brand-100);
    border-color: var(--brand);
    transform: translateY(-1px);
}
.chat-msg.typing .typing-dots {
    display: inline-flex;
    gap: 3px;
}
.chat-msg.typing .typing-dots span {
    animation: typingBounce 1.2s infinite;
    font-size: 20px;
    line-height: 1;
}
.chat-msg.typing .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-msg.typing .typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}
.chat-msg.bot strong { color: var(--brand-dark); }
.chat-msg.bot .chat-heading {
    font-weight: 600;
    font-size: 13px;
    margin: 6px 0 3px;
    color: var(--text-primary);
}
.chat-msg.bot .chat-bullet {
    padding-right: 12px;
    position: relative;
    margin: 2px 0;
}
.chat-msg.bot .chat-bullet::before {
    content: "•";
    position: absolute;
    right: 0;
    color: var(--brand);
}
.chat-msg.bot .chat-bullet .chat-num { color: var(--brand); font-weight: 600; }
.chat-msg.bot .chat-bullet .chat-num + * { margin-right: 4px; }
.chat-table {
    margin: 6px 0;
    font-size: 12px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.chat-table-row {
    display: flex;
}
.chat-table-row:first-child {
    background: var(--surface-muted);
    font-weight: 600;
}
.chat-table-row:not(:last-child) {
    border-bottom: 1px solid var(--border-light);
}
.chat-table-cell {
    flex: 1;
    padding: 3px 6px;
    text-align: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Bonus Credits Modal ── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 400;
    display: none;
}
.modal-backdrop.show { display: block; }
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface-card-solid);
    border-radius: var(--radius-xl);
    padding: 32px;
    z-index: 500;
    width: 90%;
    max-width: 420px;
    display: none;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-light);
}
.modal.show {
    display: block;
    animation: fadeInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Methodology Page ── */
.methodology-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 24px;
}
.methodology-container h1 {
    font-size: 28px;
    margin-bottom: 8px;
    font-weight: 800;
    letter-spacing: -0.3px;
}
.methodology-container h2 {
    font-size: 20px;
    margin-top: 36px;
    margin-bottom: 12px;
    color: var(--brand);
    font-weight: 700;
}
.methodology-container p {
    margin-bottom: 12px;
    color: var(--text-secondary);
}
.methodology-container ul {
    padding-right: 24px;
    margin-bottom: 16px;
}
.methodology-container li {
    margin-bottom: 8px;
    color: var(--text-secondary);
}
.methodology-container .back-link {
    display: inline-block;
    margin-bottom: 24px;
    color: var(--brand);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.15s;
}
.methodology-container .back-link:hover { color: var(--brand-dark); }

/* ── Loading Spinner ── */
.spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border-light);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    gap: 12px;
}

/* ── Clickable Rate Cells ── */
.clickable-cell {
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}
.clickable-cell:hover {
    background: rgba(99,102,241,0.08) !important;
    font-weight: 600;
}
.clickable-cell:active {
    background: rgba(99,102,241,0.15) !important;
}

/* ── Search Dropdown ── */
.search-dropdown {
    position: relative;
    min-width: 200px;
}
.sd-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.sd-input {
    width: 100%;
    padding: 9px 32px 9px 12px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    direction: rtl;
    background: rgba(255,255,255,0.8);
    transition: all 0.2s ease;
}
.sd-input:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px var(--brand-glow);
    background: white;
}
.sd-arrow {
    position: absolute;
    left: 10px;
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    transition: transform 0.2s;
}
.sd-clear {
    position: absolute;
    left: 28px;
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    padding: 2px;
    transition: color 0.15s;
}
.sd-clear:hover { color: var(--error); }
.sd-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-card-solid);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 150;
    max-height: 300px;
    overflow-y: auto;
    margin-top: 4px;
    animation: slideDown 0.15s ease-out;
}
.sd-item {
    padding: 10px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    direction: rtl;
    transition: all 0.15s ease;
    border-bottom: 1px solid rgba(226,232,240,0.3);
}
.sd-item:last-child { border-bottom: none; }
.sd-item:hover, .sd-item.highlighted {
    background: var(--brand-50);
}
.sd-item.selected {
    background: var(--brand-100);
    font-weight: 600;
}
.sd-item-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sd-badge {
    font-size: 11px;
    color: var(--text-muted);
}
.sd-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ── Sector Badge ── */
.sector-badge {
    display: inline-block;
    padding: 2px 10px;
    background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(139,92,246,0.08));
    border: 1px solid rgba(99,102,241,0.12);
    border-radius: var(--radius-full);
    font-size: 11px;
    color: var(--brand-dark);
    white-space: nowrap;
}

/* ── Rating Badges ── */
.rating-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.3px;
}
.rating-aaa { background: linear-gradient(135deg, #d1fae5, #a7f3d0); color: #065f46; }
.rating-aa1 { background: linear-gradient(135deg, #d1fae5, #bbf7d0); color: #047857; }
.rating-aa2 { background: #ecfdf5; color: #059669; }
.rating-aa3 { background: #ecfdf5; color: #10b981; }
.rating-a1 { background: linear-gradient(135deg, #fef9c3, #fef08a); color: #854d0e; }
.rating-a2 { background: #fef9c3; color: #a16207; }
.rating-a3 { background: linear-gradient(135deg, #fff7ed, #fed7aa); color: #c2410c; }
.rating-baa1 { background: linear-gradient(135deg, #fef2f2, #fecaca); color: #dc2626; }
.rating-baa2 { background: #fef2f2; color: #b91c1c; }
.rating-baa3 { background: #fef2f2; color: #991b1b; }

/* ── Data Table ── */
.dt-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.dt-count {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}
.dt-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}
.dt-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    direction: ltr;
}
.dt-table th {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 12px 14px;
    font-weight: 700;
    font-size: 11px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-light);
    white-space: nowrap;
    position: sticky;
    top: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.dt-sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.dt-sortable:hover {
    background: rgba(99,102,241,0.06);
}
.dt-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(226,232,240,0.5);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    transition: background 0.15s;
}
.dt-table tbody tr:hover {
    background: rgba(99,102,241,0.04);
}
.dt-clickable { cursor: pointer; }
.dt-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 16px;
}
.dt-page-btn {
    padding: 7px 13px;
    border: 1px solid var(--border-light);
    background: var(--surface-card-solid);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    transition: all 0.2s ease;
}
.dt-page-btn:hover:not(:disabled):not(.active) {
    border-color: var(--brand);
    color: var(--brand);
}
.dt-page-btn.active {
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: white;
    border-color: var(--brand);
    box-shadow: 0 2px 8px rgba(99,102,241,0.25);
}
.dt-page-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.dt-page-dots {
    padding: 0 4px;
    color: var(--text-muted);
}
.dt-export {
    font-size: 12px !important;
    padding: 4px 12px !important;
}

/* ── Checkbox label ── */
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}
.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--brand);
}
.rating-checkboxes {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ── Rate Detail Modal ── */
.rate-detail-modal {
    max-width: 800px;
    width: 95%;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: var(--radius-xl);
}
.rate-detail-modal .stats-grid {
    grid-template-columns: repeat(4, 1fr);
}
.rate-detail-modal .stats-grid .stat-card {
    padding: 12px 8px;
}
.rate-detail-modal .stats-grid .stat-value {
    font-size: 22px;
}
.rate-detail-modal .rate-table th,
.wp-section .rate-table th {
    text-align: right;
}
.rate-detail-modal .rate-table td,
.wp-section .rate-table td {
    text-align: right;
}

/* ── Disclaimer Footer ── */
.disclaimer-footer {
    max-width: 1200px;
    margin: 40px auto 20px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    text-align: center;
}
.disclaimer-footer p {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.8;
    direction: rtl;
}

/* ── Working Paper Overlay ── */
.wp-overlay {
    position: fixed;
    inset: 0;
    background: var(--surface-bg);
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(99,102,241,0.04) 0%, transparent 60%);
    z-index: 600;
    display: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.wp-overlay.show { display: block; }
.wp-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px;
    animation: fadeInUp 0.3s ease-out;
}
.wp-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 3px solid transparent;
    border-image: linear-gradient(90deg, var(--brand), var(--brand-light), transparent) 1;
}
.wp-header h2 {
    font-size: 22px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.wp-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}
.wp-close {
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(8px);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    width: 38px;
    height: 38px;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.wp-close:hover {
    background: var(--error-bg);
    border-color: var(--error);
    color: var(--error);
}

.wp-section {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 22px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-card);
}
.wp-section h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--brand-dark);
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(99,102,241,0.1);
    letter-spacing: -0.1px;
}

/* Rate decomposition bar */
.wp-decomp {
    display: flex;
    align-items: stretch;
    border-radius: var(--radius-md);
    overflow: hidden;
    height: 52px;
    margin: 16px 0;
    direction: ltr;
    box-shadow: var(--shadow-sm);
}
.wp-decomp-seg {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    padding: 0 10px;
    white-space: nowrap;
    transition: filter 0.2s;
}
.wp-decomp-seg:hover { filter: brightness(1.1); }
.wp-decomp-seg.rf { background: linear-gradient(135deg, #64748b, #94a3b8); }
.wp-decomp-seg.spread { background: linear-gradient(135deg, var(--brand-dark), var(--brand)); }
.wp-decomp-seg.pdp { background: linear-gradient(135deg, #ea580c, #f97316); }

/* Methodology notes */
.wp-notes {
    list-style: none;
    padding: 0;
}
.wp-notes li {
    padding: 10px 14px;
    margin-bottom: 4px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(99,102,241,0.04), rgba(139,92,246,0.04));
    border: 1px solid rgba(99,102,241,0.08);
    color: var(--text-secondary);
    font-size: 13px;
    position: relative;
    padding-right: 32px;
    transition: background 0.2s;
}
.wp-notes li:hover {
    background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(139,92,246,0.06));
}
.wp-notes li::before {
    content: '✓';
    position: absolute;
    right: 12px;
    color: var(--brand);
    font-weight: 700;
}

/* Bond detail in working paper */
.wp-bond-row {
    cursor: pointer;
    transition: all 0.15s ease;
}
.wp-bond-row:hover {
    background: rgba(99,102,241,0.06) !important;
}

/* Cash flow table */
.wp-cf-table {
    width: 100%;
    font-size: 12px;
    border-collapse: collapse;
    direction: ltr;
    text-align: center;
}
.wp-cf-table th {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 10px 8px;
    font-weight: 700;
    font-size: 11px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-light);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.wp-cf-table td {
    padding: 7px 8px;
    border-bottom: 1px solid rgba(226,232,240,0.5);
}
.wp-cf-table tr:last-child td { border-bottom: none; }
.wp-cf-table .cf-total {
    font-weight: 700;
    background: linear-gradient(135deg, rgba(99,102,241,0.06), rgba(99,102,241,0.02));
}

/* Print styles */
@media print {
    .wp-header button,
    .wp-close,
    .chat-toggle,
    .chat-panel { display: none !important; }
    .wp-overlay { position: static; }
    .wp-container { padding: 0; }
    .wp-section { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; backdrop-filter: none; background: white; }
    .card { backdrop-filter: none; background: white; }
    body { background: white; background-image: none; }
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .login-card { padding: 28px 24px; }
    .app-header { padding: 10px 14px; }
    .app-header h1 { font-size: 15px; }
    .main-content { padding: 14px; }

    /* Controls: stack vertically, full width, right-aligned */
    .controls-row {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
        padding: 14px;
    }
    .control-group {
        width: 100%;
        text-align: right;
    }
    .control-group label {
        text-align: right;
        display: block;
    }
    .control-group select,
    .control-group input[type="date"],
    .control-group input[type="number"] {
        width: 100%;
        min-width: unset;
        font-size: 16px;
        padding: 10px 12px;
    }

    /* Buttons full width on mobile */
    .controls-row .btn {
        width: 100% !important;
        padding: 12px 24px !important;
    }

    /* Methodology link: full width, centered */
    .controls-row .btn-ghost {
        text-align: center;
        padding: 8px 16px;
    }

    /* Search dropdowns full width */
    .search-dropdown { min-width: 100%; width: 100%; }
    .sd-input { font-size: 16px; padding: 10px 32px 10px 12px; }

    /* Charts */
    .chart-container { height: 320px; touch-action: pan-y; }

    /* Stats grid */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 12px; text-align: right; }
    .stat-card .stat-value { font-size: 20px; }
    .stat-card .stat-label { font-size: 12px; }

    /* Chat panel */
    .chat-panel { width: calc(100% - 32px); left: 16px; right: 16px; }
    .chat-toggle { width: 50px; height: 50px; font-size: 20px; bottom: 16px; left: 16px; }

    /* Header */
    .header-left .user-name { display: none; }
    .header-right img { height: 28px; }
    .credits-badge { font-size: 12px; padding: 4px 10px; }
    .logout-btn { font-size: 12px; padding: 4px 10px; }

    /* Tabs: horizontal scroll */
    .tabs-container { padding: 0 12px; }
    .tabs { gap: 0; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
    .tab { padding: 12px 10px; font-size: 11px; white-space: nowrap; flex-shrink: 0; }

    /* Rating checkboxes: right-aligned row */
    .rating-checkboxes { gap: 10px; justify-content: flex-start; }

    /* Cards */
    .card { padding: 14px; }
    .card-header { flex-direction: column; align-items: flex-start; gap: 4px; }
    .card-header h2 { font-size: 16px; }

    /* Company chips */
    .company-chips { gap: 6px; }
    .company-chip { font-size: 12px; padding: 5px 10px; }

    /* Maturity range inputs inline */
    .maturity-range-row {
        display: flex;
        gap: 8px;
        align-items: center;
        width: 100%;
    }
    .maturity-range-row input { flex: 1; }

    /* Modals */
    .rate-detail-modal { padding: 16px; width: 98%; }
    .modal { width: 95%; padding: 24px; }

    /* Working paper */
    .wp-container { padding: 10px; }
    .wp-header { flex-direction: column; gap: 10px; }
    .wp-header h2 { font-size: 16px; }
    .wp-header > div:last-child { align-self: flex-end; }
    .wp-subtitle { font-size: 11px; word-break: break-word; }
    .wp-section { padding: 12px; }
    .wp-section h3 { font-size: 14px; margin-bottom: 10px; }
    .wp-decomp { height: 36px; flex-wrap: nowrap; }
    .wp-decomp-seg { font-size: 9px; padding: 0 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .wp-cf-table { font-size: 10px; }
    .wp-cf-table th { padding: 6px 4px; font-size: 9px; }
    .wp-cf-table td { padding: 5px 4px; }
    .wp-notes li { font-size: 12px; padding: 8px 10px; padding-right: 28px; }

    /* Tables inside working paper & rate detail: horizontal scroll */
    .wp-section .table-scroll-wrapper,
    .rate-detail-modal .table-scroll-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -12px;
        padding: 0 12px;
    }
    .wp-section .rate-table,
    .rate-detail-modal .rate-table {
        font-size: 11px;
        min-width: 500px;  /* Force horizontal scroll rather than squish */
    }
    .wp-section .rate-table th,
    .wp-section .rate-table td,
    .rate-detail-modal .rate-table th,
    .rate-detail-modal .rate-table td {
        padding: 6px 5px;
        white-space: nowrap;
    }
    .wp-cf-table { min-width: 480px; }

    /* Rate detail modal: fix stats overflow */
    .rate-detail-modal .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .rate-detail-modal .stats-grid .stat-value { font-size: 18px; }
    .rate-detail-modal .stats-grid .stat-card { padding: 10px 6px; }
    .rate-detail-modal { max-height: 90vh; }

    /* Charts inside WP and rate detail: shorter on mobile */
    .wp-chart-container { height: 200px !important; }

    /* Formula line in WP */
    .wp-formula { font-size: 12px !important; }
    .wp-formula span { font-size: 15px !important; }

    /* Hide spacer divs */
    .controls-row > div[style*="flex:1"] { display: none; }

    /* Disable backdrop-filter on mobile for performance */
    .card, .stat-card, .wp-section, .controls-row {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(255,255,255,0.92);
    }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .rate-table { font-size: 11px; }
    .rate-table th, .rate-table td { padding: 6px 6px; }
    .tab { padding: 10px 8px; font-size: 10px; }
    .app-header h1 { font-size: 14px; }
    .main-content { padding: 8px; }

    /* Working paper extra small */
    .wp-container { padding: 6px; }
    .wp-section { padding: 10px; }
    .wp-header h2 { font-size: 14px; }
    .wp-decomp { height: 32px; }
    .wp-decomp-seg { font-size: 8px; }
    .wp-cf-table { font-size: 9px; }
    .wp-cf-table th { font-size: 8px; }

    /* Rate detail extra small */
    .rate-detail-modal { padding: 12px; }
    .rate-detail-modal .stats-grid .stat-value { font-size: 16px; }
}
