/* ----- LAYOUT & THEME ----- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; min-height: 100vh; display: flex; flex-direction: column; }
.header {
    position: relative;
    color: #fff;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(0,0,0,0.2);
    background-image: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), url('Canary-Wharf.jpg');
    background-size: cover;
    background-position: center 85%;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
}
.header h1 { font-size: 1.5rem; font-weight: 600; }
.header p { font-size: 0.9rem; opacity: 0.9; margin-top: 0.25rem; }
.riskspace-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f5f5f5;
    position: relative;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #fff;
    padding-bottom: 8rem; /* Prevents messages hiding under input */
}

.input-area {
    position: sticky;
    bottom: 0;
    background: #f9fafb;
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    z-index: 10;
}

/* ----- CHAT BUBBLES ----- */
.message { display: flex; margin-bottom: 1rem; animation: slideIn 0.3s ease-out; }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.message.user { justify-content: flex-end; }
.message.ai   { justify-content: flex-start; }
.message-bubble { max-width: 75%; padding: 0.75rem 1rem; border-radius: 1rem; word-wrap: break-word; line-height: 1.4; }
.message.user .message-bubble { background: #2563eb; color: #fff; border-bottom-right-radius: 0.25rem; }
.message.ai   .message-bubble { background: #f3f4f6; color: #1f2937; border-bottom-left-radius: 0.25rem; }
.message-time { font-size: 0.7rem; color: #6b7280; margin-top: 0.3rem; text-align: right; }
.message.ai .message-time { text-align: left; }

/* ----- TYPING INDICATOR ----- */
.typing-indicator { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem; background: #f3f4f6; border-radius: 1rem; border-bottom-left-radius: 0.25rem; max-width: 60px; }
.typing-dots { display: flex; gap: 3px; }
.typing-dots span { width: 6px; height: 6px; background: #6b7280; border-radius: 50%; animation: typing 1.4s infinite ease-in-out both; }
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* ----- RESULTS & STATS ----- */
.results-container { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 0.5rem; padding: 1rem; margin: 0.5rem 0; }
.chart-container { width: 100%; height: 300px; margin: 1rem 0; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 1rem; margin: 1rem 0; }
.stat-card { background: #fff; padding: 0.75rem; border-radius: 0.5rem; border: 1px solid #e2e8f0; text-align: center; }
.stat-value { font-size: 1.25rem; font-weight: 600; color: #1f2937; }
.stat-label { font-size: 0.75rem; color: #6b7280; margin-top: 0.25rem; }

/* ----- INPUT AREA ----- */
.input-container { display: flex; align-items: flex-end; gap: 0.5rem; background: #fff; border-radius: 1.5rem; padding: 0.5rem; border: 1px solid #d1d5db; }
.input-field { flex: 1; border: none; outline: none; resize: none; font-family: inherit; font-size: 0.95rem; line-height: 1.4; padding: 0.6rem 0.8rem; max-height: 120px; min-height: 20px; background: transparent; }
.input-field::placeholder { color: #9ca3af; }
.send-button { width: 36px; height: 36px; border-radius: 50%; border: none; background: #2563eb; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s; font-size: 1rem; }
.send-button:hover:not(:disabled) { background: #1d4ed8; }
.send-button:disabled { background: #9ca3af; cursor: not-allowed; }

/* ----- CONNECTION STATUS & INSIGHT ----- */
.connection-status {
    position: absolute;
    top: 50%;
    right: 1.5rem;
    transform: translateY(-50%);
    padding: 0.25rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8rem;
    font-weight: 500;
    z-index: 10;
    text-shadow: none;
}

.connection-status.connected    { background: rgba(209, 250, 229, 0.9); color: #065f46; border: 1px solid #a7f3d0; }
.connection-status.disconnected { background: rgba(254, 226, 226, 0.9); color: #991b1b; border: 1px solid #fca5a5; }

@media (max-width: 768px) {
    .connection-status {
        top: 0.5rem;
        transform: none;
        right: 0.5rem;
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
        border-radius: 0.25rem;
    }
}
.insight-container { background: #eef2ff; border: 1px solid #c7d2fe; border-left: 4px solid #4f46e5; border-radius: 0.5rem; padding: 1rem; margin-top: 1rem; }
.insight-container strong { color: #4338ca; }

/* ----- RISK PORTAL HEADER/NAVIGATION ----- */
.main-header {
    position: sticky;
    top: 0;
    z-index: 50;
    width: 100%;
    border-bottom: 1px solid #e5e7eb;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    height: 4rem;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: inherit;
}

.nav-logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1f2937;
}

.nav-menu {
    display: none;
    align-items: center;
    gap: 0.25rem;
}

.nav-item {
    position: relative;
}

.nav-link {
    display: inline-flex;
    height: 2.5rem;
    align-items: center;
    justify-content: center;
    border-radius: 0.375rem;
    background: transparent;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    color: #374151;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
}

.nav-link:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.nav-dropdown {
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 0.375rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    padding: 1rem;
    width: 25rem;
    display: none;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    z-index: 50;
}

.nav-item:hover .nav-dropdown {
    display: grid;
}

.nav-dropdown-item {
    display: block;
    padding: 0.75rem;
    border-radius: 0.375rem;
    text-decoration: none;
    color: inherit;
    transition: background 0.2s ease;
}

.nav-dropdown-item:hover {
    background: #f3f4f6;
}

.nav-dropdown-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: #1f2937;
    margin-bottom: 0.25rem;
}

.nav-dropdown-desc {
    font-size: 0.75rem;
    color: #6b7280;
    line-height: 1.3;
}

.mobile-menu-button {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 2.5rem;
    width: 2.5rem;
    border: none;
    background: transparent;
    color: #374151;
    cursor: pointer;
    border-radius: 0.25rem;
}

.mobile-menu-button:hover {
    background: #f3f4f6;
}

/* Mobile Navigation */
.mobile-nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    display: none;
}

.mobile-nav-overlay.active {
    display: block;
}

.mobile-nav {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 300px;
    background: #fff;
    z-index: 50;
    padding: 2rem 1rem;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.mobile-nav.active {
    transform: translateX(0);
}

.mobile-nav-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.mobile-nav-link {
    font-size: 1.125rem;
    font-weight: 500;
    color: #1f2937;
    text-decoration: none;
    padding: 0.5rem 0;
}

.mobile-nav-subitem {
    margin-left: 1rem;
    padding: 0.25rem 0;
}

.mobile-nav-sublink {
    font-size: 0.875rem;
    color: #6b7280;
    text-decoration: none;
}

@media (min-width: 768px) {
    .nav-menu {
        display: flex;
    }

    .mobile-menu-button {
        display: none;
    }
}
