/* CSS Variables for Theming */
:root {
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --sidebar-bg: rgba(255, 255, 255, 0.95);
    --sidebar-text: #333;
    --chat-bg: rgba(255, 255, 255, 0.95);
    --chat-messages-bg: #f8f9fa;
    --message-user-bg: linear-gradient(135deg, #667eea, #764ba2);
    --message-assistant-bg: white;
    --message-assistant-border: #e9ecef;
    --input-border: #e9ecef;
    --input-focus-border: #667eea;
    --text-primary: #333;
    --text-secondary: #666;
    --accent-color: #667eea;
}

/* Dark Theme */
body.dark-theme {
    --bg-gradient-start: #1a1a2e;
    --bg-gradient-end: #16213e;
    --sidebar-bg: rgba(30, 30, 46, 0.95);
    --sidebar-text: #e0e0e0;
    --chat-bg: rgba(30, 30, 46, 0.95);
    --chat-messages-bg: #1e1e2e;
    --message-user-bg: linear-gradient(135deg, #667eea, #764ba2);
    --message-assistant-bg: #2a2a3e;
    --message-assistant-border: #3a3a4e;
    --input-border: #3a3a4e;
    --input-focus-border: #667eea;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-color: #667eea;
}

/* Main Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s ease;
}

.container {
    display: flex;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
}

.sidebar {
    width: 350px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(10px);
    padding: 20px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    overflow-y: auto;
    transition: background 0.3s ease;
}

.logo {
    text-align: center;
    margin-bottom: 25px;
    padding: 20px 0;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 15px;
    color: white;
}

.logo h1 {
    font-size: 22px;
    margin-bottom: 5px;
}

.logo p {
    font-size: 11px;
    opacity: 0.9;
}

.workspace-selector {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 20px;
    color: #333;
}

.workspace-selector h3 {
    color: #333;
    margin-bottom: 10px;
}

.workspace-select {
    width: 100%;
    min-height: 36px;
    padding: 8px;
    margin-bottom: 8px;
    border: 1px solid #cfe3ea;
    border-radius: 8px;
    background: #fff;
    color: #17202a;
    font: inherit;
}

.workspace-select option {
    background: #fff;
    color: #17202a;
}

.workspace-selector .control-btn {
    width: 100%;
}

.workspace-status {
    color: #536273;
    font-size: 10px;
    margin-top: 7px;
}

.conversation-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid #dfe7ec;
    color: #536273;
    font-size: 11px;
    font-weight: 600;
}

.conversation-toolbar button {
    border: 0;
    background: transparent;
    color: #536273;
    cursor: pointer;
    padding: 4px 6px;
}

.conversation-list {
    display: grid;
    gap: 5px;
    margin-top: 7px;
    max-height: 150px;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

.conversation-open {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    border: 1px solid #dfe7ec;
    border-radius: 7px;
    padding: 6px 8px;
    background: #fff;
    color: #17202a;
    cursor: pointer;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-open.active {
    border-color: #667eea;
    background: #edf1ff;
}

.conversation-action {
    border: 0;
    background: transparent;
    color: #536273;
    cursor: pointer;
    padding: 4px;
}

.conversation-empty,
.conversation-error {
    color: #536273;
    font-size: 10px;
    padding: 4px 0;
}

.document-toolbar {
    margin-top: 10px;
}

.document-toolbar-actions {
    display: inline-flex;
    align-items: center;
}

.document-list {
    display: grid;
    gap: 5px;
    margin-top: 7px;
    max-height: 130px;
    overflow-y: auto;
}

.document-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
    min-width: 0;
    border: 1px solid #dfe7ec;
    border-radius: 7px;
    padding: 6px 8px;
    background: #fff;
    color: #17202a;
    font-size: 10px;
}

.document-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.document-indexed {
    color: #16803c;
    font-size: 9px;
}

.document-metadata {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 5px;
}

.document-actions {
    display: inline-flex;
    align-items: center;
}

.document-actions button {
    padding: 3px 5px;
}

.document-source {
    border-radius: 999px;
    padding: 2px 5px;
    background: #eef2f6;
    color: #465463;
    font-size: 8px;
}

.document-source.teyra_documentation {
    background: #e0f7fb;
    color: #0e7490;
}

.document-source.url {
    background: #e8f0fe;
    color: #1d4ed8;
}

.document-visibility {
    border-radius: 999px;
    padding: 2px 5px;
    background: #e8f5e9;
    color: #166534;
    font-size: 8px;
}

.document-visibility.restricted {
    background: #fff3cd;
    color: #92400e;
}

.document-delete {
    border: 0;
    background: transparent;
    color: #536273;
    cursor: pointer;
    padding: 2px;
}

.document-analysis,
.document-acl {
    border: 0;
    background: transparent;
    color: #536273;
    cursor: pointer;
    padding: 2px;
}

.document-acl-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(4, 12, 18, .72);
}

.document-acl-panel {
    width: min(620px, 100%);
    max-height: 85vh;
    overflow: auto;
    display: grid;
    gap: 14px;
    padding: 22px;
    border: 1px solid #315063;
    border-radius: 14px;
    background: #0d1b25;
    color: #e5f3fa;
}

.document-acl-panel h3,
.document-acl-panel p {
    margin: 0;
}

.document-acl-panel p {
    color: #9bb4c2;
    font-size: 12px;
}

.document-acl-panel label {
    display: flex;
    align-items: center;
    gap: 7px;
}

.document-acl-panel > label {
    display: grid;
}

.document-acl-panel select {
    padding: 9px;
    border: 1px solid #315063;
    border-radius: 8px;
    background: #07131c;
    color: #e5f3fa;
}

.document-acl-panel fieldset {
    display: flex;
    flex-wrap: wrap;
    gap: 9px 14px;
    border: 1px solid #294252;
    border-radius: 9px;
}

.document-acl-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.document-acl-actions button {
    padding: 9px 12px;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.document-acl-actions button[type="submit"] {
    background: linear-gradient(135deg, #22d3ee, #8b5cf6);
    color: #071018;
    font-weight: 700;
}

.document-empty,
.document-error {
    color: #536273;
    font-size: 10px;
    padding: 4px 0;
}

.document-empty {
    display: grid;
    gap: 7px;
}

.knowledge-empty-action {
    border: 1px solid #22b8cf;
    border-radius: 7px;
    padding: 6px 8px;
    background: #e6f9fc;
    color: #0e6473;
    cursor: pointer;
    font-size: 10px;
    font-weight: 700;
}

.mode-selector {
    margin-bottom: 20px;
    background: var(--chat-messages-bg);
    border-radius: 15px;
    padding: 15px;
    transition: background 0.3s ease;
}

.mode-selector h3 {
    margin-bottom: 10px;
    color: var(--sidebar-text);
    font-size: 14px;
}

.mode-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.mode-btn {
    padding: 8px 12px;
    border: 2px solid var(--input-border);
    background: var(--message-assistant-bg);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 11px;
    text-align: center;
    color: var(--text-primary);
}

.mode-btn.active {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.mode-btn:hover:not(.active) {
    border-color: #667eea;
    transform: translateY(-1px);
}

.upload-section {
    background: var(--chat-messages-bg);
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 15px;
    border: 2px dashed var(--input-border);
    transition: all 0.3s ease;
}

.upload-section:hover {
    border-color: #667eea;
    transform: translateY(-2px);
}

.upload-section h3 {
    margin-bottom: 10px;
    color: var(--sidebar-text);
    font-size: 14px;
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 100%;
}

.file-input {
    position: absolute;
    left: -9999px;
}

.file-input-label {
    display: block;
    padding: 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 12px;
}

.file-input-label:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.file-preview {
    margin-top: 10px;
    max-height: 120px;
    overflow-y: auto;
}

.file-item {
    background: var(--message-assistant-bg);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 5px;
    font-size: 11px;
    border: 1px solid var(--input-border);
    transition: all 0.3s ease;
}

.file-item .file-name {
    font-weight: bold;
    color: var(--text-primary);
    margin-bottom: 3px;
}

.file-item .file-content {
    color: var(--text-secondary);
    font-family: monospace;
    max-height: 60px;
    overflow: hidden;
}

.templates-section {
    background: var(--chat-messages-bg);
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 15px;
    transition: background 0.3s ease;
}

.templates-section h3 {
    margin-bottom: 10px;
    color: var(--sidebar-text);
    font-size: 14px;
}

.template-btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 5px;
    background: var(--message-assistant-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 11px;
    text-align: left;
    color: var(--text-primary);
}

.template-btn:hover {
    border-color: #667eea;
    transform: translateX(5px);
}

.controls {
    margin-top: auto;
}

.panel-navigation {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 16px;
}

.panel-navigation .control-btn {
    min-width: 0;
    margin: 0;
    padding: 9px 6px;
    text-decoration: none;
}

.panel-navigation .control-btn[aria-current="page"] {
    background: linear-gradient(135deg, #0ea5b7, #7c3aed);
    box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.28);
}

.panel-navigation .control-btn:first-child {
    grid-column: 1 / -1;
}

.control-btn {
    width: 100%;
    padding: 10px;
    margin-bottom: 8px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.control-btn.primary {
    background: #28a745;
    color: white;
}

.control-btn.secondary {
    background: #17a2b8;
    color: white;
}

.control-btn.danger {
    background: #dc3545;
    color: white;
}

.control-btn.warning {
    background: #ffc107;
    color: #212529;
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    backdrop-filter: blur(10px);
    transition: background 0.3s ease;
}

.chat-header {
    padding: 15px 20px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h2 {
    font-size: 18px;
}

.chat-header p {
    font-size: 12px;
    opacity: 0.9;
}

.chat-runtime-controls {
    margin-left: auto;
    min-width: 250px;
}

.web-grounding-control {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 7px;
    color: rgba(255, 255, 255, 0.92);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}

.web-grounding-control input {
    accent-color: #22d3ee;
}

.citation-item a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.model-selector-label {
    display: grid;
    gap: 4px;
    font-size: 11px;
    font-weight: 700;
}

.model-selector {
    width: 100%;
    min-height: 36px;
    padding: 7px 34px 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 9px;
    background: rgba(7, 17, 27, 0.72);
    color: #f4fbff;
    font: inherit;
}

.model-selector:focus {
    outline: 2px solid rgba(34, 211, 238, 0.65);
    outline-offset: 1px;
}

.model-selector option,
.model-selector optgroup {
    background: #0d1b25;
    color: #e5f3fa;
}

.model-status {
    min-height: 14px;
    color: rgba(255, 255, 255, 0.76);
    font-weight: 500;
}

.model-status.error {
    color: #fecdd3;
}

.current-mode {
    text-align: right;
}

.current-mode .mode-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
}

@media (max-width: 900px) {
    .chat-header {
        align-items: stretch;
        flex-wrap: wrap;
        gap: 10px;
    }

    .chat-runtime-controls {
        order: 3;
        width: 100%;
        min-width: 0;
    }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--chat-messages-bg);
    transition: background 0.3s ease;
}

.message {
    margin-bottom: 20px;
    animation: slideUp 0.4s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    text-align: right;
}

.message.assistant {
    text-align: left;
}

.message-content {
    display: inline-block;
    max-width: 85%;
    padding: 15px 20px;
    border-radius: 20px;
    margin: 5px 0;
    word-wrap: break-word;
    position: relative;
    transition: all 0.3s ease;
}

.message.user .message-content {
    background: var(--message-user-bg);
    color: white;
    border-bottom-right-radius: 5px;
}

.message.assistant .message-content {
    background: var(--message-assistant-bg);
    border: 1px solid var(--message-assistant-border);
    color: var(--text-primary);
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.message-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.message.assistant .message-actions {
    justify-content: flex-start;
}

.file-analysis {
    margin-top: 6px;
    color: var(--text-secondary, #667085);
    font-size: 11px;
}

.message-citations {
    max-width: 85%;
    margin: 6px 0 0;
    padding: 8px 12px;
    border-left: 3px solid #17a2b8;
    background: rgba(23, 162, 184, 0.08);
    color: var(--text-secondary, #667085);
    font-size: 11px;
    text-align: left;
}

.citations-title {
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-primary, #344054);
}

.citation-item {
    overflow-wrap: anywhere;
    line-height: 1.45;
}

.message-feedback {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    color: var(--text-secondary, #667085);
    font-size: 11px;
}

.feedback-btn {
    border: 1px solid rgba(102, 112, 133, 0.35);
    border-radius: 999px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    padding: 3px 7px;
}

.feedback-btn:hover,
.feedback-btn.selected {
    color: #17a2b8;
    border-color: #17a2b8;
}

.action-btn {
    padding: 4px 8px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.3s ease;
    opacity: 0.7;
}

.action-btn:hover {
    opacity: 1;
    transform: scale(1.05);
}

.action-btn.regenerate {
    background: #17a2b8;
    color: white;
}

.action-btn.copy {
    background: #6c757d;
    color: white;
}

.message-content pre {
    background: var(--chat-messages-bg);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 13px;
}

.message-content code:not(pre code) {
    background: rgba(102, 126, 234, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #e83e8c;
}

.message-content .mermaid {
    background: var(--message-assistant-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 15px;
    margin: 10px 0;
}

.input-container {
    padding: 20px;
    background: var(--message-assistant-bg);
    border-top: 1px solid var(--input-border);
    transition: background 0.3s ease;
}

.workflow-draft-btn {
    align-self: flex-end;
    margin-top: 8px;
    padding: 8px 12px;
    border: 1px solid rgba(34, 211, 238, 0.45);
    border-radius: 9px;
    background: rgba(34, 211, 238, 0.1);
    color: var(--primary-color, #0891b2);
    cursor: pointer;
    font-weight: 700;
}

.workflow-draft-btn:hover {
    background: rgba(34, 211, 238, 0.18);
}

.workflow-draft-btn:disabled {
    cursor: wait;
    opacity: 0.65;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    min-height: 50px;
    max-height: 150px;
    padding: 15px;
    border: 2px solid var(--input-border);
    border-radius: 25px;
    resize: vertical;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.3s ease;
    background: var(--message-assistant-bg);
    color: var(--text-primary);
}

.message-input:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.send-btn {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.streaming-indicator {
    display: inline-block;
    color: #667eea;
    margin-left: 10px;
}

.typing-dots {
    display: inline-flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #667eea;
    animation: typing 1.4s infinite ease-in-out;
}

.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);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.error {
    background: #f8d7da;
    color: #721c24;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0;
    border: 1px solid #f5c6cb;
}

.success {
    background: #d4edda;
    color: #155724;
    padding: 15px;
    border-radius: 10px;
    margin: 10px 0;
    border: 1px solid #c3e6cb;
}

/* Theme Toggle Button */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    z-index: 1000;
}

.ripple::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.ripple:active::before {
    width: 300px;
    height: 300px;
    transition: width 0s, height 0s;
}

body.dark-theme .ripple::before {
    background: rgba(255, 255, 255, 0.3);
}

/* Enhanced Button States */
.control-btn,
.mode-btn,
.template-btn,
.action-btn,
.send-btn {
    position: relative;
    overflow: hidden;
    transform-origin: center;
    will-change: transform;
}

.control-btn:active,
.mode-btn:active,
.template-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

/* Glow effect for primary buttons */
.control-btn.primary,
.send-btn:not(:disabled) {
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4);
    animation: pulse-glow 2s infinite;
}

.send-btn:not(:disabled) {
    box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4);
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(102, 126, 234, 0);
    }
}

/* Enhanced Message Animations */
@keyframes slideUpBounce {
    0% {
        opacity: 0;
        transform: translateY(30px);
    }

    60% {
        opacity: 1;
        transform: translateY(-5px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.message {
    animation: slideUpBounce 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Message hover effect */
.message-content {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message:hover .message-content {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

body.dark-theme .message:hover .message-content {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Staggered animation for multiple messages */
.message:nth-child(1) {
    animation-delay: 0s;
}

.message:nth-child(2) {
    animation-delay: 0.1s;
}

.message:nth-child(3) {
    animation-delay: 0.2s;
}

.message:nth-child(4) {
    animation-delay: 0.3s;
}

.message:nth-child(5) {
    animation-delay: 0.4s;
}

/* New message pulse */
@keyframes newMessagePulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(102, 126, 234, 0);
    }
}

.message.new-message .message-content {
    animation: newMessagePulse 1s ease-out;
}

/* Enhanced Loading States */
.typing-dots span {
    animation: typingBounce 1.4s infinite ease-in-out;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: translateY(0) scale(0.8);
        opacity: 0.5;
    }

    40% {
        transform: translateY(-8px) scale(1);
        opacity: 1;
    }
}

/* Skeleton loader for streaming messages */
.skeleton-loader {
    background: linear-gradient(90deg,
            var(--chat-messages-bg) 25%,
            var(--message-assistant-border) 50%,
            var(--chat-messages-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
    height: 20px;
    margin: 5px 0;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Send button loading state */
.send-btn:disabled {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 0.7;
    }
}

/* Enhanced Input Focus Effects */
.message-input {
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message-input:focus {
    transform: translateY(-2px);
}

/* Animated border glow */
@keyframes borderGlow {

    0%,
    100% {
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    }

    50% {
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
    }
}

.message-input:focus {
    animation: borderGlow 2s infinite;
}

/* File Upload Animations */
.upload-section {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.upload-section.drag-over {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    transform: scale(1.02);
}

.file-item {
    animation: slideInLeft 0.4s ease-out;
}

@keyframes slideInLeft {
    0% {
        opacity: 0;
        transform: translateX(-20px);
    }

    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* File upload progress bar */
.upload-progress {
    height: 3px;
    background: var(--input-border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 5px;
}

.upload-progress-bar {
    height: 100%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    width: 0%;
    transition: width 0.3s ease;
    animation: progressShine 1.5s infinite;
}

@keyframes progressShine {
    0% {
        background-position: -100% 0;
    }

    100% {
        background-position: 100% 0;
    }
}

/* Smooth Scroll Behavior */
.chat-messages {
    scroll-behavior: smooth;
}

/* Scroll to top button */
.scroll-to-top {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.scroll-to-top:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

/* Enhanced Notification System */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 12px;
    color: white;
    z-index: 1001;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    animation: slideInRight 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 350px;
}

@keyframes slideInRight {
    0% {
        opacity: 0;
        transform: translateX(100px);
    }

    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

.notification.success {
    background: linear-gradient(135deg, #28a745, #20c997);
}

.notification.error {
    background: linear-gradient(135deg, #dc3545, #c82333);
}

.notification.info {
    background: linear-gradient(135deg, #17a2b8, #138496);
}

.notification.warning {
    background: linear-gradient(135deg, #ffc107, #e0a800);
    color: #212529;
}

/* Notification progress bar */
.notification-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    width: 100%;
    border-radius: 0 0 12px 12px;
}

.notification-progress-bar {
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    width: 100%;
    animation: notificationProgress 3s linear;
}

@keyframes notificationProgress {
    0% {
        width: 100%;
    }

    100% {
        width: 0%;
    }
}

/* Mode switching animations */
.mode-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mode-btn.active {
    animation: modeActivate 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes modeActivate {
    0% {
        transform: scale(0.9);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

/* Mode badge slide animation */
.mode-badge {
    animation: badgeSlide 0.4s ease-out;
}

@keyframes badgeSlide {
    0% {
        opacity: 0;
        transform: translateY(-10px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Theme toggle icon transition */
.theme-toggle i {
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    display: inline-block;
}

.theme-toggle:hover i {
    transform: rotate(180deg) scale(1.2);
}

/* Action button reveal animation */
.message-actions {
    opacity: 0;
    transform: translateY(5px);
    transition: all 0.3s ease;
}

.message:hover .message-actions {
    opacity: 1;
    transform: translateY(0);
}

/* Copy success feedback */
@keyframes copySuccess {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }
}

.action-btn.copy.copied {
    animation: copySuccess 0.4s ease;
}

/* Performance optimizations */
.message,
.control-btn,
.mode-btn,
.template-btn,
.action-btn,
.send-btn,
.theme-toggle {
    will-change: transform;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Fix for layout issues */
.sidebar {
    flex-shrink: 0 !important;
}

.chat-container {
    min-width: 0 !important;
    overflow-x: hidden !important;
}

/* Mobile Responsiveness */

/* Sidebar Toggle Button (Hidden on Desktop) */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1001;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 15px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    transform: scale(1.05);
}

/* Tablet Styles (768px - 1024px) */
@media (max-width: 1024px) {
    .sidebar {
        width: 250px;
    }

    .chat-container {
        width: calc(100% - 250px);
    }
}

/* Mobile Styles (< 768px) */
@media (max-width: 768px) {

    /* Show Toggle Button */
    .sidebar-toggle {
        display: block;
    }

    /* Hide Sidebar by Default */
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        transition: left 0.3s ease-in-out;
        box-shadow: 2px 0 15px rgba(0, 0, 0, 0.2);
    }

    /* Show Sidebar when Active */
    .sidebar.active {
        left: 0;
    }

    /* Full Width Chat */
    .chat-container {
        width: 100%;
        margin-left: 0;
        padding-top: 60px;
        /* Space for toggle button */
    }

    /* Adjust Input Area */
    .input-area {
        padding: 15px;
    }

    .input-container {
        padding: 5px;
    }

    /* Larger Touch Targets */
    .mode-btn,
    .action-btn,
    .send-btn {
        padding: 12px;
    }

    /* Typography */
    .message-content {
        font-size: 16px;
        /* Larger text for readability */
    }

    /* Overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }
}

/* Force Mobile Layout if detected by Backend */
body.device-mobile .sidebar-toggle {
    display: block !important;
}

body.device-mobile .sidebar {
    position: fixed !important;
    left: -280px !important;
    top: 0;
    bottom: 0;
    width: 280px !important;
    z-index: 1000;
    transition: left 0.3s ease-in-out;
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.2);
}

body.device-mobile .sidebar.active {
    left: 0 !important;
}

body.device-mobile .chat-container {
    width: 100% !important;
    margin-left: 0 !important;
    padding-top: 60px !important;
}

body.device-mobile .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

body.device-mobile .sidebar-overlay.active {
    display: block !important;
    opacity: 1 !important;
}

/* Device-Specific Overrides (Backend Detected) */
body.device-mobile .message-content {
    font-size: 1.1rem;
}

body.device-mobile .input-container textarea {
    font-size: 16px;
    /* Prevent zoom on iOS */
}

/* Fix for Modal Visibility */
.modal,
.admin-login-panel {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}

.modal[style*="display: block"],
.modal[style*="display: flex"] {
    display: flex !important;
}

.modal-content {
    background: var(--chat-bg);
    margin: auto;
    width: 90%;
    max-width: 500px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    animation: slideUpBounce 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.modal-header {
    padding: 15px 20px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-radius: 15px 15px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-header .close {
    color: white;
    opacity: 0.8;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-header .close:hover {
    opacity: 1;
    transform: scale(1.1);
}

.modal-body {
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
}

/* Fix for Mobile Chat Layout */
@media (max-width: 768px) {
    .chat-container {
        height: 100dvh !important;
        /* Use dynamic viewport height */
        display: flex !important;
        flex-direction: column !important;
    }

    .chat-messages {
        flex: 1 !important;
        overflow-y: auto !important;
        padding-bottom: 20px !important;
    }

    .input-container {
        position: sticky !important;
        bottom: 0 !important;
        background: var(--chat-bg) !important;
        z-index: 100 !important;
        padding-bottom: env(safe-area-inset-bottom, 20px) !important;
        /* iOS Safe Area */
    }

    /* Ensure modals are on top of everything on mobile */
    .modal,
    .admin-login-panel {
        z-index: 9999 !important;
    }
}

/* Admin Panel Styling */
.admin-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.admin-content {
    width: 90%;
    max-width: 1000px;
    height: 80vh;
    background: var(--chat-bg);
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-header {
    padding: 20px;
    border-bottom: 1px solid var(--input-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-radius: 15px 15px 0 0;
}

.admin-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px;
}

.admin-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--input-border);
    padding-bottom: 10px;
}

.tab-btn {
    padding: 10px 20px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    border-radius: 8px;
    transition: all 0.3s;
}

.tab-btn.active {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
    font-weight: bold;
}

.tab-btn:hover:not(.active) {
    background: rgba(0, 0, 0, 0.05);
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
}

.tab-content.active {
    display: block;
}

/* Admin Tables */
.table-container {
    background: var(--chat-messages-bg);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--input-border);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--input-border);
    color: var(--text-primary);
}

.admin-table th {
    background: rgba(102, 126, 234, 0.1);
    font-weight: 600;
    color: #667eea;
}

.admin-table tr:hover {
    background: rgba(0, 0, 0, 0.02);
}

body.dark-theme .admin-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: 13px;
}

.form-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--message-assistant-bg);
    color: var(--text-primary);
    font-family: inherit;
}

.form-input:focus {
    border-color: #667eea;
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.control-btn.small {
    padding: 6px 12px;
    font-size: 11px;
    width: auto;
}

.icon-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.8;
}

.icon-btn:hover {
    opacity: 1;
}
body.authentication-required > :not(.modal) {
    filter: blur(3px);
    pointer-events: none;
    user-select: none;
}

body.authentication-required .authentication-gate {
    display: flex !important;
    z-index: 10000;
}

.authentication-gate .close {
    display: none;
}
