/* ===== Blastness Chat AI — Design System aligned with k01 Governance Tools ===== */

:root {
    /* Blastness Brand Colors (same as k01) */
    --blastness-magenta: #e6007e;
    --blastness-magenta-dark: #c4006a;
    --blastness-magenta-light: #ff1493;
    --blastness-dark: #1a1a1a;
    --blastness-dark-secondary: #2d2d2d;
    --blastness-gray: #6c757d;
    --blastness-light: #f8f9fa;
    --blastness-white: #ffffff;

    /* Gradients (same as k01) */
    --primary-gradient: linear-gradient(135deg, #e6007e 0%, #ff1493 100%);
    --sidebar-bg: linear-gradient(180deg, #1a1a1a 0%, #242424 100%);

    /* Chat-specific */
    --chat-sidebar-width: 280px;
    --chat-sidebar-collapsed-width: 56px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--blastness-light);
}

/* ===== APP LAYOUT ===== */
.chat-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== SIDEBAR (matches k01 sidebar) ===== */
.chat-sidebar {
    width: var(--chat-sidebar-width);
    background: var(--sidebar-bg);
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.2);
    z-index: 1050;
}

.chat-sidebar.collapsed { width: var(--chat-sidebar-collapsed-width); }

/* Sidebar header — brand style like k01 */
.sidebar-header {
    display: flex;
    align-items: center;
    padding: 16px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    gap: 10px;
    flex-shrink: 0;
}

.sidebar-header .sidebar-toggle {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-header .sidebar-toggle:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-brand-logo img {
    height: 36px;
    width: auto;
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.sidebar-brand-name {
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.sidebar-brand-sub {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.sidebar-brand-sub strong {
    color: var(--blastness-magenta);
    font-weight: 600;
}

/* New thread button — magenta gradient like k01 primary actions */
.btn-new-thread {
    background: var(--primary-gradient);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: auto;
    flex-shrink: 0;
}
.btn-new-thread:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(230, 0, 126, 0.4);
}

/* Search box — same as k01 */
.sidebar-search {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}
.sidebar-search input {
    width: 100%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.75rem;
    color: #fff;
    transition: all 0.2s;
}
.sidebar-search input::placeholder { color: rgba(255, 255, 255, 0.35); }
.sidebar-search input:focus {
    outline: none;
    border-color: var(--blastness-magenta);
    background: rgba(255, 255, 255, 0.12);
}

/* Thread list */
.sidebar-threads { flex: 1; overflow-y: auto; padding: 4px 0; }

.thread-group-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255, 255, 255, 0.35);
    padding: 10px 14px 4px;
    font-weight: 600;
}

.thread-item {
    padding: 8px 14px;
    cursor: pointer;
    border-radius: 8px;
    margin: 1px 8px;
    transition: all 0.2s;
}
.thread-item:hover {
    background: rgba(255, 255, 255, 0.06);
}
.thread-item.active {
    background: rgba(230, 0, 126, 0.15);
    border-left: 3px solid var(--blastness-magenta);
}

.thread-title {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: rgba(255, 255, 255, 0.85);
}
.thread-item.active .thread-title { color: #fff; font-weight: 500; }

.thread-meta {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.35);
    margin-top: 2px;
}

/* Sidebar footer — user info */
.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px 14px;
    flex-shrink: 0;
}
.user-info {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.user-info > i { color: var(--blastness-magenta); font-size: 1.1rem; margin-top: 2px; flex-shrink: 0; }

.user-footer-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.user-footer-name {
    font-size: 0.78rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-footer-roles {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.role-tag {
    font-size: 0.58rem;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(230, 0, 126, 0.2);
    color: var(--blastness-magenta-light);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.user-footer-kb {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 2px;
}

.kb-tag {
    font-size: 0.55rem;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.55);
    font-weight: 400;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.kb-tag i { font-size: 0.5rem; }
.kb-tag.tool-tag {
    background: rgba(100, 200, 255, 0.1);
    color: rgba(100, 200, 255, 0.6);
}

/* ===== MAIN AREA ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--blastness-light);
    min-width: 0;
    position: relative;
}

/* ===== WELCOME SCREEN ===== */
.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
}
.welcome-logo {
    width: 80px;
    height: 80px;
    background: var(--primary-gradient);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    box-shadow: 0 8px 32px rgba(230, 0, 126, 0.25);
}
.welcome-logo i { font-size: 2.2rem; color: #fff; }

.chat-welcome h2 {
    font-weight: 700;
    color: var(--blastness-dark);
    margin-bottom: 8px;
}
.chat-welcome .text-muted { font-size: 0.95rem; }

.welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: 700px;
    margin-top: 16px;
}
.welcome-suggestions .btn {
    font-size: 0.82rem;
    border-radius: 10px;
    padding: 10px 16px;
    border-color: #dee2e6;
    color: var(--blastness-dark);
    transition: all 0.2s;
}
.welcome-suggestions .btn:hover {
    border-color: var(--blastness-magenta);
    color: var(--blastness-magenta);
    background: rgba(230, 0, 126, 0.04);
}

/* ===== MESSAGES ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
}

.chat-message {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    max-width: 820px;
    margin: 0 auto;
    width: 100%;
}

.message-avatar {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-size: 1rem;
}
.chat-message.user .message-avatar {
    background: var(--primary-gradient);
    color: #fff;
}
.chat-message.assistant .message-avatar {
    background: linear-gradient(135deg, #2d2d2d 0%, #3d3d3d 100%);
    color: #fff;
}

.message-content {
    flex: 1;
    min-width: 0;
    line-height: 1.65;
    font-size: 0.92rem;
    color: var(--blastness-dark);
}
.message-content p { margin-bottom: 0.5rem; }
.message-content p:last-child { margin-bottom: 0; }

/* Code blocks — dark theme */
.message-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 14px 16px;
    border-radius: 10px;
    overflow-x: auto;
    font-size: 0.82rem;
    margin: 8px 0;
    border: 1px solid #333;
}
.message-content code {
    background: rgba(230, 0, 126, 0.08);
    color: var(--blastness-magenta-dark);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
}
.message-content pre code {
    background: none;
    color: inherit;
    padding: 0;
}

/* Tables in markdown */
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.85rem;
}
.message-content th, .message-content td {
    padding: 6px 10px;
    border: 1px solid #dee2e6;
    text-align: left;
}
.message-content th {
    background: var(--blastness-light);
    font-weight: 600;
}

.message-time {
    font-size: 0.65rem;
    color: var(--blastness-gray);
    margin-top: 6px;
}

.message-sources {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.message-sources .badge {
    font-size: 0.65rem;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 6px;
}

/* ===== TYPING INDICATOR ===== */
.typing-indicator { display: flex; gap: 5px; padding: 8px 0; }
.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--blastness-magenta);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
    0%, 80%, 100% { transform: scale(0.5); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* ===== INPUT BAR ===== */
.chat-input-bar {
    padding: 16px 24px 20px;
    background: var(--blastness-white);
    border-top: 1px solid #e9ecef;
}
.chat-input-wrapper {
    display: flex;
    gap: 10px;
    max-width: 820px;
    margin: 0 auto;
    align-items: flex-end;
    background: var(--blastness-light);
    border: 1px solid #dee2e6;
    border-radius: 14px;
    padding: 8px 8px 8px 16px;
    transition: border-color 0.2s;
}
.chat-input-wrapper:focus-within {
    border-color: var(--blastness-magenta);
    box-shadow: 0 0 0 3px rgba(230, 0, 126, 0.1);
}
.chat-input-wrapper textarea {
    flex: 1;
    resize: none;
    border: none;
    background: transparent;
    padding: 6px 0;
    font-size: 0.92rem;
    color: var(--blastness-dark);
    max-height: 120px;
    outline: none;
    font-family: inherit;
}
.chat-input-wrapper textarea::placeholder { color: var(--blastness-gray); }

.btn-send {
    background: var(--primary-gradient);
    border: none;
    color: #fff;
    border-radius: 10px;
    width: 38px;
    height: 38px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(230, 0, 126, 0.4);
}
.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Attach button ── */
.btn-attach {
    background: none;
    border: none;
    color: var(--blastness-gray);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.15rem;
    transition: all 0.2s;
}
.btn-attach:hover:not(:disabled) {
    color: var(--blastness-magenta);
    background: rgba(230, 0, 126, 0.08);
}
.btn-attach:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Image preview strip ── */
.image-preview {
    max-width: 820px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--blastness-light);
    border: 1px solid #dee2e6;
    border-radius: 10px;
}
.image-preview img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #dee2e6;
}
.image-preview-name {
    font-size: 0.8rem;
    color: var(--blastness-gray);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
.btn-remove-image {
    background: none;
    border: none;
    color: var(--blastness-gray);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: all 0.2s;
}
.btn-remove-image:hover {
    color: #dc3545;
    background: rgba(220, 53, 69, 0.1);
}

/* ── Inline message images ── */
.message-image {
    margin-bottom: 8px;
}
.message-image img {
    max-width: 320px;
    max-height: 240px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    cursor: pointer;
    transition: transform 0.2s;
}
.message-image img:hover {
    transform: scale(1.02);
}

.chat-input-footer {
    text-align: center;
    padding-top: 8px;
    max-width: 820px;
    margin: 0 auto;
}
.chat-input-footer small { font-size: 0.7rem; }

.chat-error {
    max-width: 820px;
    margin: 8px auto 0;
    padding: 8px 12px;
    background: rgba(220, 53, 69, 0.08);
    border: 1px solid rgba(220, 53, 69, 0.2);
    border-radius: 8px;
    color: #dc3545;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
}
.chat-error .btn-close-sm {
    font-size: 0.5rem;
    padding: 4px;
}

/* ===== LOADING ===== */
.chat-loading {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}
.chat-loading .spinner-border { color: var(--blastness-magenta) !important; }

/* ===== BLAZOR ERROR UI ===== */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    width: 100%;
    background: #ffe0e0;
    padding: 8px;
    text-align: center;
    z-index: 1000;
    font-size: 0.85rem;
}

/* ===== SCROLLBAR (matches k01) ===== */
.chat-messages::-webkit-scrollbar,
.sidebar-threads::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track,
.sidebar-threads::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}
.sidebar-threads::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1050;
        width: var(--chat-sidebar-collapsed-width);
    }
    .chat-sidebar .sidebar-search,
    .chat-sidebar .sidebar-threads,
    .chat-sidebar .sidebar-brand-text,
    .chat-sidebar .sidebar-footer span,
    .chat-sidebar .btn-new-thread { display: none; }
    .chat-main { margin-left: var(--chat-sidebar-collapsed-width); }
    .chat-message { padding: 12px 16px; }
    .chat-input-bar { padding: 12px 16px; }
}
