* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: #f0f2f5;
    height: 100vh;
    overflow: hidden;
}

.chat-container {
    display: flex;
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: #1a365d;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 16px;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: #1a365d;
}

.sidebar-nav {
    padding: 12px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    color: #4a5568;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item:hover {
    background: #edf2f7;
}

.nav-item.active {
    background: #ebf4ff;
    color: #2b6cb0;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid #e2e8f0;
}

/* Logged-in user block */
.user-section {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    margin-bottom: 14px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.user-avatar {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    background: #1a365d;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
}

.user-meta {
    flex: 1 1 auto;
    min-width: 0;
}

.user-meta strong {
    display: block;
    font-size: 13px;
    color: #1a202c;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-meta p {
    margin: 0;
    font-size: 11px;
    color: #718096;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-logout {
    flex: 0 0 auto;
    background: none;
    border: none;
    color: #718096;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
}

.user-logout:hover {
    color: #c53030;
    background: #fff5f5;
}

.help-section {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
    color: #4a5568;
}

.help-section strong {
    font-size: 13px;
}

.help-section p {
    font-size: 12px;
    color: #718096;
}

.support-link {
    font-size: 13px;
    color: #2b6cb0;
    text-decoration: none;
    font-weight: 500;
}

.support-link:hover {
    text-decoration: underline;
}

/* Main Chat */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    /* Stay within the flex slot even when a message contains a wide table;
       without this the max-content table widens the whole panel and pushes the
       header actions (home/menu) off-screen. */
    min-width: 0;
    overflow: hidden;
}

.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-info h1 {
    font-size: 20px;
    color: #1a202c;
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    /* Never let the header buttons (home / menu) be squeezed out of view. */
    flex-shrink: 0;
}

.header-btn {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    color: #4a5568;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-btn:hover {
    background: #f7fafc;
    border-color: #2b6cb0;
    color: #2b6cb0;
}

/* Dropdown Menu */
.menu-wrapper {
    position: relative;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    padding: 8px 0;
    min-width: 220px;
    z-index: 100;
    border: 1px solid #e2e8f0;
}

.dropdown-menu.active {
    display: block;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 20px;
    border: none;
    background: none;
    font-size: 14px;
    color: #4a5568;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.15s;
}

.menu-item:hover {
    background: #f7fafc;
}

.menu-item svg {
    flex-shrink: 0;
    color: #718096;
}

.menu-divider {
    height: 1px;
    background: #e2e8f0;
    margin: 6px 0;
}

.new-chat-nav {
    border: 1px dashed #cbd5e0;
    margin-top: 4px;
}

.ai-badge {
    font-size: 11px;
    background: #ebf4ff;
    color: #2b6cb0;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    vertical-align: middle;
}

.header-info p {
    font-size: 13px;
    color: #718096;
    margin-top: 4px;
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    /* Contain wide content so tables scroll inside their own wrapper rather
       than widening the whole chat panel. */
    min-width: 0;
}

.message-group {
    display: flex;
    gap: 12px;
    max-width: 75%;
    /* Let the group shrink so its flex children can too (prevents wide tables
       from pushing content past the chat column). */
    min-width: 0;
}

/* Bot replies can contain wide tables — give them more of the column width. */
.message-group:not(.user) {
    max-width: 92%;
}

.message-group.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.bot-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: #1a365d;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    /* Allow this flex item to shrink below its content's intrinsic width so a
       wide table is contained here and scrolls inside .table-wrap instead of
       overflowing the chat column and getting clipped. */
    min-width: 0;
}

/* The bot bubble must also be allowed to shrink for the same reason. */
.message-content .message {
    max-width: 100%;
}

.message-sender {
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #48bb78;
    border-radius: 50%;
}

.status-text {
    font-size: 12px;
    color: #718096;
    font-weight: 400;
}

.message {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    color: #2d3748;
}

.bot-message {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px 12px 12px 12px;
}

.user-message {
    background: #2b6cb0;
    color: white;
    border-radius: 12px 4px 12px 12px;
}

.message ul {
    margin: 8px 0;
    padding-left: 20px;
}

.message li {
    margin: 4px 0;
}

.message p + p {
    margin-top: 8px;
}

.message strong {
    font-weight: 600;
}

.message-time {
    font-size: 11px;
    color: #a0aec0;
    margin-top: 2px;
}

.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}

.feedback-btn {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.5;
}

.feedback-btn:hover {
    opacity: 1;
    border-color: #2b6cb0;
    background: #ebf4ff;
}

.feedback-btn.selected {
    opacity: 1;
    border-color: #2b6cb0;
    background: #ebf4ff;
}

.message-group.user .message-time {
    text-align: right;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px 12px 12px 12px;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #a0aec0;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Reasoning Pipeline */
.reasoning-pipeline {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px 12px 12px 12px;
    padding: 16px 20px;
    min-width: 380px;
    max-width: 500px;
}

.pipeline-header {
    font-size: 14px;
    font-weight: 700;
    color: #1a202c;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e2e8f0;
}

.pipeline-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.pipeline-step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #4a5568;
    padding: 4px 0;
    animation: fadeInStep 0.3s ease;
}

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

.pipeline-step.active {
    color: #2d3748;
    font-weight: 500;
}

.pipeline-step.active .step-icon {
    animation: pulse 1s infinite;
}

.pipeline-step.completed {
    color: #718096;
    font-weight: 400;
}

.step-status {
    font-size: 12px;
    width: 16px;
    text-align: center;
    color: #48bb78;
    font-weight: 600;
}

.pipeline-step.active .step-status {
    color: #2b6cb0;
}

.step-icon {
    font-size: 14px;
    width: 20px;
    text-align: center;
}

.step-text {
    flex: 1;
}

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

/* Progress bar */
.pipeline-progress {
    height: 3px;
    background: #e2e8f0;
    border-radius: 2px;
    overflow: hidden;
}

.pipeline-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #2b6cb0, #4299e1);
    border-radius: 2px;
    width: 0%;
    transition: width 0.5s ease;
}

/* Input Area */
.input-area {
    padding: 16px 24px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}

/* Operating unit (country) selector in the header (left of the home icon) */
.ou-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 8px;
}

.ou-label {
    font-size: 12px;
    color: #718096;
    font-weight: 500;
    white-space: nowrap;
}

#operatingUnitSelect {
    font-size: 13px;
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: #2d3748;
    cursor: pointer;
    min-width: 150px;
    max-width: 220px;
}

#operatingUnitSelect:focus {
    outline: none;
    border-color: #2b6cb0;
    box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.1);
}

/* Operating-unit badge shown at the top of each bot message */
.ou-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #2b6cb0;
    background: #ebf4ff;
    border: 1px solid #bee3f8;
    padding: 3px 10px;
    border-radius: 999px;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.ou-badge-icon {
    flex-shrink: 0;
    opacity: 0.8;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 8px 16px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: #2b6cb0;
    box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.1);
}

#messageInput {
    flex: 1;
    border: none;
    background: none;
    font-size: 14px;
    color: #2d3748;
    outline: none;
    padding: 4px 0;
}

#messageInput::placeholder {
    color: #a0aec0;
}

.attach-btn,
.mic-btn,
.send-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    color: #718096;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-btn:hover,
.mic-btn:hover {
    color: #4a5568;
    background: #edf2f7;
}

.send-btn {
    background: #2b6cb0;
    color: white;
    padding: 8px;
}

.send-btn:hover {
    background: #2c5282;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .message-group {
        max-width: 90%;
    }

    .welcome-section {
        padding: 20px;
    }

    .prompt-chips {
        justify-content: center;
    }
}

/* Welcome Section */
.welcome-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    flex: 1;
}

.welcome-title {
    font-size: 22px;
    font-weight: 700;
    color: #1a202c;
    margin-bottom: 8px;
}

.welcome-subtitle {
    font-size: 14px;
    color: #718096;
    margin-bottom: 28px;
}

.prompt-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: 700px;
}

.prompt-chip {
    background: #fff;
    border: 1px solid #2b6cb0;
    color: #2b6cb0;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.prompt-chip:hover {
    background: #ebf4ff;
    border-color: #2c5282;
    color: #2c5282;
}

.prompt-chip:active {
    background: #2b6cb0;
    color: #fff;
}


/* Data Table (inside bot messages) */
/* Horizontal scroll wrapper for wide tables */
.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 8px 0;
}

.data-table {
    /* Fit the bubble when it can; when there are many columns, keep the natural
       width and let .table-wrap scroll horizontally rather than squashing text. */
    width: 100%;
    min-width: max-content;
    border-collapse: collapse;
    font-size: 13px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

.data-table thead th {
    background: #edf2f7;
    color: #2d3748;
    font-weight: 600;
    text-align: left;
    padding: 8px 12px;
    border-bottom: 2px solid #cbd5e0;
    white-space: nowrap;
}

.data-table tbody tr:nth-child(even) {
    background: #f7fafc;
}

.data-table tbody tr:hover {
    background: #ebf4ff;
}

.data-table td {
    padding: 6px 12px;
    border-bottom: 1px solid #e2e8f0;
    color: #2d3748;
    vertical-align: top;
}


/* Chat History Sidebar */
.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    margin-bottom: 12px;
    background: #2b6cb0;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: #2c5282;
}

.chat-history-section {
    flex: 1;
    overflow-y: auto;
}

.history-label {
    font-size: 11px;
    text-transform: uppercase;
    color: #a0aec0;
    font-weight: 600;
    letter-spacing: 0.5px;
    padding: 0 4px;
    margin-bottom: 8px;
    display: block;
}

.chat-history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-history-item {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    border: none;
    background: none;
    text-align: left;
    width: 100%;
    font-family: inherit;
}

.chat-history-item:hover {
    background: #edf2f7;
}

.chat-history-item.active {
    background: #ebf4ff;
}

.chat-history-item .chat-title {
    font-size: 13px;
    color: #2d3748;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.chat-history-item .chat-time {
    font-size: 11px;
    color: #a0aec0;
    margin-top: 2px;
}
