:root {
    --primary-color: #0d83ff;
    --primary-dark: #0b5cd6;
    --primary-soft: #e4f1ff;
    --accent-color: #f8bf60;
    --sidebar-bg: #051633;
    --sidebar-border: rgba(255, 255, 255, 0.06);
    --surface: #ffffff;
    --surface-alt: #f6f8fb;
    --shadow-soft: 0 20px 45px rgba(15, 33, 74, 0.12);
    --text-muted: #6c7a92;
    --border-muted: rgba(136, 152, 170, 0.2);
    --chat-gradient: radial-gradient(circle at top, rgba(10, 133, 255, 0.1), transparent 65%);
    --bs-primary: var(--primary-color);
    --bs-primary-rgb: 13, 131, 255;
    --bs-link-color: var(--primary-color);
    --bs-link-hover-color: var(--primary-dark);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #f8fbff, #ebf1ff);
    min-height: 100vh;
    color: #0b1b36;
    line-height: 1.5;
}

body.chat-page {
    overflow: hidden;
}

body.chat-page main {
    height: calc(100vh - 56px);
    overflow: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.high-contrast {
    background: #0b0b0b;
    color: #f5f7fa;
}

.high-contrast main,
.high-contrast .chat-shell,
.high-contrast .chat-panel,
.high-contrast .chat-sidebar,
.high-contrast .chat-top-bar,
.high-contrast .sidebar-section,
.high-contrast .welcome-card,
.high-contrast .embedded-dashboard-wrapper,
.high-contrast .thread-summary,
.high-contrast .checklist-panel {
    background: #0f1117;
    color: #f5f7fa;
    border-color: #2f3846;
    box-shadow: none;
}

.high-contrast .chat-scroll {
    background: #0f1117;
}

.high-contrast .message .content {
    background: #0f1a2b;
    border-color: #2f3846;
    color: #f5f7fa;
}

.high-contrast .message.user .content {
    background: #0a5db5;
}

.high-contrast .chat-top-bar .btn,
.high-contrast .thread-actions .btn,
.high-contrast .btn {
    border-color: #8fd0ff;
    color: #e8f4ff;
}

.high-contrast .btn-primary {
    background: #0a74da;
    border-color: #0a74da;
}

.high-contrast .btn-outline-primary {
    border-color: #8fd0ff;
    color: #e8f4ff;
}

.high-contrast .chat-input {
    background: #0f1117;
    border-color: #2f3846;
}

.high-contrast .sidebar-list .thread-item,
.high-contrast .sidebar-list .workspace-link {
    background: rgba(255,255,255,0.06);
    color: #f5f7fa;
}

.high-contrast .sidebar-list .thread-item.active,
.high-contrast .sidebar-list .workspace-link.active {
    background: rgba(13, 131, 255, 0.45);
}

.high-contrast .presence-item {
    border-color: #2f3846;
    background: #0f1a2b;
}

main {
    padding: 0;
}

a {
    text-decoration: none;
}

.navbar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(15, 33, 74, 0.08);
}

.navbar-brand {
    font-weight: 600;
    letter-spacing: 0.01em;
}

.btn {
    border-radius: 0.75rem;
    font-weight: 600;
}

.btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 10px 30px rgba(13, 131, 255, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

:focus-visible {
    outline: 3px solid #ffbf47;
    outline-offset: 2px;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    box-shadow: 0 0 0 0.2rem rgba(255, 191, 71, 0.45);
}

.btn-outline-primary {
    border-color: rgba(13, 131, 255, 0.4);
    color: var(--primary-color);
}

.btn-outline-primary:hover {
    background: var(--primary-color);
    color: #fff;
}

.btn-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.btn-icon-text {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding-inline: 1rem;
}

.eyebrow {
    font-size: 0.75rem;
    letter-spacing: 0.18em;
    font-weight: 700;
    text-transform: uppercase;
}

/* Layout */
.chat-shell {
    display: flex;
    min-height: calc(100vh - 56px);
    height: 100%;
    flex: 1;
    position: relative;
    background-image: var(--chat-gradient);
    overflow: visible;
}

.chat-sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    gap: 1.5rem;
    box-shadow: inset -1px 0 0 var(--sidebar-border);
    transition: transform 0.35s ease;
    z-index: 1046;
    height: calc(100vh - 56px);
    max-height: calc(100vh - 56px);
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-brand {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.sidebar-section {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 1.25rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
    min-height: 0;
    flex-shrink: 0;
}

.sidebar-section-header p {
    color: rgba(255, 255, 255, 0.7);
}

.sidebar-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    max-height: 100%;
}

#thread-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.workspace-link,
.thread-item {
    border: none;
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    border-radius: 0.9rem;
    padding: 0.85rem 1rem;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    text-decoration: none;
}

.workspace-link .chevron,
.thread-item .chevron {
    opacity: 0.6;
}

.workspace-link:hover,
.thread-item:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(4px);
}

.workspace-link.active,
.thread-item.active {
    background: rgba(13, 131, 255, 0.35);
    box-shadow: 0 10px 20px rgba(13, 131, 255, 0.2);
}

.sidebar-select {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
}

.sidebar-select:focus {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    box-shadow: 0 0 0 0.1rem rgba(13, 131, 255, 0.35);
    border-color: rgba(13, 131, 255, 0.5);
}

.machine-map {
    height: 180px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
}

.embedded-dashboard-wrapper {
    background: #fff;
    border-radius: 1rem;
    border: 1px solid var(--border-muted);
    box-shadow: var(--shadow-soft);
    padding: 1.25rem;
    margin-top: 1rem;
    height: calc(100vh - 120px);
    max-height: none;
    overflow: auto;
}

.embedded-dashboard-content {
    height: 100%;
    overflow: visible;
}

.embedded-dashboard-inner .card {
    border: 1px solid var(--border-muted);
}

.chat-area {
    flex: 1;
    position: relative;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 0;
    overflow-y: auto;
}

.panel-toggle-fab {
    align-self: flex-end;
    margin-bottom: -0.5rem;
    z-index: 10;
    box-shadow: 0 12px 30px rgba(13, 131, 255, 0.25);
}

.chat-welcome {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-card {
    background: var(--surface);
    border-radius: 1.5rem;
    padding: 3rem;
    box-shadow: var(--shadow-soft);
    max-width: 420px;
}

.chat-panel {
    flex: 1;
    background: var(--surface);
    border-radius: 1.75rem;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.chat-top-bar {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--border-muted);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.6rem;
    align-items: center;
    background: linear-gradient(115deg, rgba(13, 131, 255, 0.12), rgba(11, 92, 214, 0.18));
    border-radius: 1.2rem 1.2rem 0 0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
    position: relative;
    overflow: visible;
    transition: max-height 0.25s ease, padding 0.25s ease, background 0.25s ease;
}

.chat-top-bar .btn,
.chat-top-bar .btn-group .btn {
    padding: 0.45rem 0.75rem;
    font-size: 0.88rem;
    border-radius: 0.6rem;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.4);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.chat-top-bar h5 {
    color: #0b1b36;
}

.thread-actions .btn:hover,
.chat-top-bar .btn-group .btn:hover {
    background: rgba(255, 255, 255, 0.16);
    box-shadow: 0 10px 24px rgba(13, 131, 255, 0.18);
    transform: translateY(-1px);
}

.chat-top-bar.collapsed {
    padding: 0;
    gap: 0;
    max-height: 8px;
    overflow: visible;
    opacity: 0.85;
    box-shadow: none;
    background: linear-gradient(115deg, rgba(13, 131, 255, 0.08), rgba(11, 92, 214, 0.12));
}

.chat-top-bar.collapsed h5 {
    display: none;
}

.chat-top-bar.collapsed .thread-actions {
    width: 100%;
    justify-content: flex-end;
    gap: 0;
    min-height: 0;
    padding-right: 0;
}

.chat-top-bar.collapsed .bar-toggle-handle {
    height: 14px;
    width: 26px;
    font-size: 0.82rem;
    box-shadow: none;
    top: 2px;
    right: 6px;
}

.chat-top-bar.collapsed .thread-actions > :not(.bar-toggle-handle) {
    display: none;
}

.chat-top-bar .btn-outline-primary {
    background: linear-gradient(135deg, rgba(13, 131, 255, 0.18), rgba(13, 131, 255, 0.28));
    border-color: rgba(13, 131, 255, 0.6);
}

.chat-top-bar .btn-outline-secondary {
    background: linear-gradient(135deg, rgba(108, 117, 125, 0.2), rgba(108, 117, 125, 0.3));
    border-color: rgba(108, 117, 125, 0.55);
}

.chat-top-bar .btn-outline-danger {
    background: linear-gradient(135deg, rgba(220, 53, 69, 0.22), rgba(220, 53, 69, 0.32));
    border-color: rgba(220, 53, 69, 0.65);
}

.chat-top-bar .btn-outline-info {
    background: linear-gradient(135deg, rgba(13, 202, 240, 0.22), rgba(13, 202, 240, 0.32));
    border-color: rgba(13, 202, 240, 0.6);
}

.chat-top-bar .btn-outline-light {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.24));
    color: #0b1b36;
    border-color: rgba(255, 255, 255, 0.75);
}

.chat-top-bar .btn-outline-light:hover {
    color: #0b1b36;
}

.high-contrast .chat-top-bar {
    background: #0f1a2b;
    border-color: #2f3846;
}

.thread-summary {
    margin: 0.5rem 1rem 0;
    padding: 0.9rem 1rem;
    background: linear-gradient(120deg, rgba(13, 131, 255, 0.08), rgba(11, 92, 214, 0.12));
    border: 1px solid rgba(13, 131, 255, 0.18);
    border-radius: 1rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 10px 24px rgba(13, 131, 255, 0.12);
}

.summary-header h6 {
    color: #0b1b36;
}

.summary-body {
    margin-top: 0.25rem;
}

.summary-body.loading {
    position: relative;
    overflow: hidden;
    min-height: 60px;
}

.summary-body.loading::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,255,255,0.35), rgba(255,255,255,0));
    animation: shimmer 1.4s infinite;
}

.summary-skeleton {
    height: 12px;
    margin-bottom: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.5);
}

.summary-skeleton:last-child {
    width: 65%;
}

.checklist-panel {
    margin: 0.5rem 1rem 0;
    padding: 0.75rem 1rem;
    background: linear-gradient(120deg, rgba(111, 182, 132, 0.1), rgba(102, 173, 123, 0.16));
    border: 1px solid rgba(111, 182, 132, 0.25);
    border-radius: 1rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 10px 24px rgba(111, 182, 132, 0.12);
}

.checklist-list .form-check {
    margin-bottom: 0.35rem;
}

.checklist-list .form-check-input {
    border-color: rgba(111, 182, 132, 0.65);
}

.checklist-list .form-check-input:checked {
    background-color: #6fb684;
    border-color: #6fb684;
}

.summary-toggle-btn {
    border-color: rgba(111, 182, 132, 0.65) !important;
    color: #0b1b36 !important;
    background: linear-gradient(135deg, #e9f7ee, #c7e9d7) !important;
    box-shadow: 0 8px 18px rgba(111, 182, 132, 0.18);
}

.summary-toggle-btn:hover {
    background: linear-gradient(135deg, #dff3e6, #b6e0c8) !important;
    color: #0b1b36 !important;
}

.summary-toggle-btn.is-on {
    border-color: rgba(88, 168, 120, 0.9) !important;
    background: linear-gradient(135deg, #c7e9d7, #a9d6c3) !important;
    box-shadow: 0 10px 20px rgba(88, 168, 120, 0.22);
}

.pulse-alert {
    animation: pulse-alert 1.2s ease-in-out infinite;
    color: #d39e00;
}

.high-contrast .thread-summary,
.high-contrast .checklist-panel {
    background: #0f1a2b;
    border-color: #2f3846;
}

@keyframes pulse-alert {
    0% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); opacity: 0.9; }
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.thread-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    justify-content: flex-end;
    position: relative;
}

.thread-actions .btn-group .btn {
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
}

.thread-actions .btn-group .btn-check:checked + .btn,
.thread-actions .btn-group .btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.thread-actions.collapsed > :not(.bar-toggle-handle) {
    display: none;
}

.bar-toggle-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 18px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.7);
    color: #0b1b36;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 6px 14px rgba(13, 131, 255, 0.12);
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    position: absolute;
    right: 0;
    top: 10px;
}

.bar-toggle-handle:hover {
    background: #fff;
    box-shadow: 0 8px 18px rgba(13, 131, 255, 0.2);
    transform: translateY(-1px);
}

.chat-scroll {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background: var(--surface-alt);
    min-height: 0;
    scroll-behavior: smooth;
}

.chat-scroll::-webkit-scrollbar,
.sidebar-list::-webkit-scrollbar {
    width: 6px;
}

.chat-scroll::-webkit-scrollbar-thumb,
.sidebar-list::-webkit-scrollbar-thumb {
    background: rgba(13, 131, 255, 0.4);
    border-radius: 999px;
}

.chat-input {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-muted);
    background: #fff;
}

#question {
    border-radius: 1rem;
    border: 1px solid var(--border-muted);
    padding-block: 0.55rem;
    background: #fff;
}

.chat-input .input-group-text {
    padding: 0.35rem 0.65rem;
}

.chat-input .btn {
    padding: 0.55rem 0.9rem;
    font-size: 0.95rem;
    border-radius: 0.8rem;
}

#question:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(13, 131, 255, 0.15);
}

/* Messages */
.message {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.message .content {
    padding: 1.1rem 1.35rem;
    border-radius: 1.25rem;
    max-width: 720px;
    background: #fff;
    border: 1px solid rgba(10, 27, 54, 0.06);
    box-shadow: 0 12px 35px rgba(30, 45, 72, 0.08);
}

.message.user {
    align-items: flex-end;
}

.message.user .content {
    background: var(--primary-color);
    color: #fff;
    border-bottom-right-radius: 0.35rem;
}

.message.assistant {
    align-items: flex-start;
}

.message.assistant .content {
    background: #fff;
    border-bottom-left-radius: 0.35rem;
}

.high-contrast .message .content {
    background: #0f1a2b;
    color: #f5f7fa;
    border-color: #2f3846;
}

.high-contrast .message.user .content {
    background: #0a5db5;
    color: #f5f7fa;
}

.message-footer {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.feedback-controls .btn {
    min-width: 90px;
}

.feedback-complete {
    color: #28a745;
    font-weight: 600;
}

.citations {
    margin-top: 0.25rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Presence panel */
.presence-filters .form-select {
    background: #f8fafc;
}

.presence-item {
    border: 1px solid var(--border-muted);
    border-radius: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-soft);
}

.high-contrast .presence-item {
    box-shadow: none;
}

.presence-avatar {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
}

.presence-name {
    font-weight: 700;
    color: #0b1b36;
}

.presence-chip {
    background: var(--surface-alt);
    border: 1px solid var(--border-muted);
    border-radius: 999px;
    padding: 0.2rem 0.65rem;
    font-size: 0.8rem;
    color: #0b1b36;
}

.presence-chip.subtle {
    background: rgba(13, 131, 255, 0.08);
    border-color: rgba(13, 131, 255, 0.25);
}

.presence-status {
    font-size: 0.78rem;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    border: 1px solid transparent;
}

.presence-status-typing {
    background: rgba(13, 131, 255, 0.15);
    color: #0b1b36;
    border-color: rgba(13, 131, 255, 0.4);
}

.presence-status-active {
    background: rgba(111, 182, 132, 0.18);
    color: #0b1b36;
    border-color: rgba(111, 182, 132, 0.5);
}

.presence-status-idle {
    background: rgba(108, 117, 125, 0.15);
    color: #0b1b36;
    border-color: rgba(108, 117, 125, 0.35);
}

.presence-location {
    margin-top: 0.25rem;
}

.presence-meta {
    min-width: 120px;
}

/* Lottie avatar */
#lottie-avatar {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 200px;
    height: 200px;
    z-index: 1050;
    pointer-events: none;
    opacity: 0.9;
    background: transparent !important;
    border: none;
    display: block;
    border-radius: 50%;
    overflow: hidden;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

@keyframes glow {
    0% { opacity: 0.85; }
    50% { opacity: 1; }
    100% { opacity: 0.85; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    50% { transform: translateX(3px); }
    75% { transform: translateX(-2px); }
}

/* Overlay for mobile sidebar */
#panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 14, 30, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1045;
}

#panel-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Responsive */
@media (max-width: 1199px) {
    .chat-sidebar {
        width: 280px;
    }
}

@media (max-width: 991px) {
    .chat-shell {
        min-height: calc(100vh - 56px);
    }

    .chat-sidebar {
        position: fixed;
        top: 56px;
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
        padding-top: 1.5rem;
        border-radius: 0 1.25rem 1.25rem 0;
    }

    .chat-shell.sidebar-open .chat-sidebar {
        transform: translateX(0);
    }

    .chat-area {
        padding: 1.25rem;
    }

    .chat-panel {
        border-radius: 1.25rem;
    }

    .chat-top-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 0.55rem 0.75rem;
        gap: 0.5rem;
    }

    .thread-actions {
        justify-content: flex-start;
        gap: 0.45rem;
    }

    .chat-top-bar .btn,
    .chat-top-bar .btn-group .btn {
        padding: 0.35rem 0.6rem;
        font-size: 0.84rem;
        min-height: 44px;
    }

    .chat-input {
        padding: 0.65rem 0.85rem;
    }

    #question {
        padding-block: 0.45rem;
    }

    .chat-input .btn {
        padding: 0.45rem 0.75rem;
        font-size: 0.9rem;
        min-height: 44px;
    }

    #lottie-avatar {
        width: 160px;
        height: 160px;
        bottom: 16px;
        right: 16px;
    }
}
