:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --ai-message-bg: #f7f9ff;
    --user-message-bg: #667eea;
    --user-message-text: white;
    --sidebar-width: 280px;
    --sidebar-collapsed: 0px;
    --chat-max-width: 800px;
}

.chat-app {
    display: flex;
    height: calc(100vh - 180px);
    gap: 0;
    position: relative;
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

/* Sidebar with toggle */
.chat-sessions {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1a1f36 0%, #2d3748 100%);
    padding: 24px 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    position: relative;
    z-index: 10;
}

.chat-sessions.collapsed {
    transform: translateX(calc(-100% + 48px));
    opacity: 0.3;
}

.sidebar-toggle {
    position: absolute;
    right: -16px;
    top: 24px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-gradient);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    transform: scale(1.1);
}

.sessions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sessions-header h4 {
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0;
}

#new-chat-btn {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

#new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.sessions-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sessions-list li {
    padding: 12px 16px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sessions-list li:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

.sessions-list li.active {
    background: rgba(102, 126, 234, 0.2);
    color: white;
    border-left: 4px solid #667eea;
}

/* Main Chat Panel */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    position: relative;
}

.chat-header {
    padding: 20px 32px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

#chat-title {
    font-size: 1.4rem;
    font-weight: 600;
    color: #1a1f36;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-controls {
    display: flex;
    gap: 12px;
}

.chat-controls button {
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 2px solid transparent;
}

#delete-chat-btn {
    background: white;
    color: #ef4444;
    border-color: #fecaca;
}

#delete-chat-btn:hover {
    background: #fef2f2;
    transform: translateY(-2px);
}

#summarize-chat-btn {
    background: var(--primary-gradient);
    color: white;
    border: none;
}

#summarize-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

/* Messages Area */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: var(--chat-max-width);
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    gap: 16px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    justify-content: flex-end;
}

.message-content {
    max-width: 85%;
    padding: 20px 24px;
    border-radius: 20px;
    position: relative;
    word-wrap: break-word;
}

.message.user .message-content {
    background: var(--primary-gradient);
    color: var(--user-message-text);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--ai-message-bg);
    color: #1a1f36;
    border-bottom-left-radius: 4px;
    border: 1px solid #e5e7eb;
}

.message-time {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 8px;
    text-align: right;
}

/* Message Form */
.message-form {
    padding: 24px 32px;
    background: white;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 12px;
    align-items: center;
}

#message-input {
    flex: 1;
    padding: 18px 24px;
    border: 2px solid #e5e7eb;
    border-radius: 16px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: #f8fafc;
}

#message-input:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.file-upload-wrapper {
    position: relative;
}

.file-upload-btn {
    padding: 18px 24px;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #4b5563;
    font-weight: 500;
}

.file-upload-btn:hover {
    background: #f8fafc;
    border-color: #667eea;
    color: #667eea;
}

#file-input {
    display: none;
}

.message-form button[type="submit"] {
    padding: 18px 32px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-form button[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

/* SVG Icons */
.icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 20px 24px;
    background: var(--ai-message-bg);
    border-radius: 20px;
    width: fit-content;
    border: 1px solid #e5e7eb;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #667eea;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.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(-10px);
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chat-app {
        flex-direction: column;
        height: calc(100vh - 140px);
    }

    .chat-sessions {
        width: 100%;
        height: 200px;
        flex-shrink: 0;
    }

    .chat-sessions.collapsed {
        height: 60px;
        transform: translateY(-140px);
    }

    .sidebar-toggle {
        top: auto;
        bottom: -16px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
    }

    .messages {
        padding: 16px;
    }

    .message-content {
        max-width: 90%;
    }

    .message-form {
        padding: 16px;
        flex-wrap: wrap;
    }

    #message-input {
        min-width: 200px;
    }
}

/* Inline code styling */
.message-content code.inline-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", "Segoe UI Mono", monospace;
  background: rgba(27,31,35,0.05);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.92em;
  color: #c7254e;
}

/* Block code - command/terminal look */
.message-content pre.code-block {
  background: #0b1220;         /* dark terminal background */
  color: #c9d1d9;             /* pale text */
  padding: 12px 16px;
  border-radius: 12px;
  overflow: auto;
  margin: 12px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", monospace;
  font-size: 0.9rem;
  line-height: 1.45;
  border: 1px solid rgba(0,0,0,0.25);
  box-shadow: inset 0 -1px 0 rgba(255,255,255,0.02);
}

/* Optional: show a small language badge in top-right of block */
.message-content pre.code-block::before {
  content: attr(data-lang);
  position: absolute;
  right: 18px;
  top: 8px;
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

/* Improve block spacing inside assistant messages */
.message.assistant .message-content pre.code-block {
  margin-left: 0;
  margin-right: 0;
}
