/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3B82F6;
    --primary-hover: #2563EB;
    --danger-color: #EF4444;
    --success-color: #10B981;
    --warning-color: #F59E0B;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
}

/* App Container */
.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.app-header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
}

.header-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.env-badge {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-indicator {
    font-size: 0.875rem;
    color: var(--gray-600);
}

.status-indicator.online {
    color: var(--success-color);
}

/* Main Content Layout */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: white;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.user-selector {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.user-selector label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.user-selector select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.user-selector select optgroup {
    font-weight: 600;
    color: var(--gray-700);
    background: var(--gray-50);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.25rem;
}

.user-selector select option {
    padding: 0.5rem;
    font-size: 0.875rem;
}

.user-info {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--gray-50);
    border-radius: 0.375rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-badge {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
}

.search-box {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.search-box input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
    cursor: pointer;
    transition: background 0.15s;
}

.conversation-item:hover {
    background: var(--gray-50);
}

.conversation-item.active {
    background: var(--primary-color);
    color: white;
}

.conversation-item.active .conversation-meta {
    color: rgba(255, 255, 255, 0.8);
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.25rem;
}

.conversation-title {
    font-weight: 600;
    font-size: 0.9375rem;
}

.conversation-time {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.conversation-item.active .conversation-time {
    color: rgba(255, 255, 255, 0.8);
}

.conversation-meta {
    font-size: 0.8125rem;
    color: var(--gray-600);
}

.conversation-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    background: var(--gray-100);
    color: var(--gray-700);
    margin-top: 0.25rem;
}

.empty-state {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--gray-500);
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

.empty-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--gray-500);
    text-align: center;
    padding: 2rem;
}

.empty-chat h3 {
    margin-top: 1rem;
    color: var(--gray-700);
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
}

.chat-info h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.chat-info p {
    font-size: 0.875rem;
    color: var(--gray-600);
}

.chat-actions {
    display: flex;
    gap: 0.5rem;
}

.messages-area {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    background: var(--gray-50);
}

.message {
    display: flex;
    margin-bottom: 1rem;
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    position: relative;
}

.message.received .message-bubble {
    background: white;
    border: 1px solid var(--gray-200);
    border-bottom-left-radius: 0.25rem;
}

.message.sent .message-bubble {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message-author {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--gray-600);
}

.message.sent .message-author {
    color: rgba(255, 255, 255, 0.9);
}

.message-text {
    font-size: 0.9375rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.message-time {
    font-size: 0.6875rem;
    margin-top: 0.25rem;
    opacity: 0.7;
}

.message-input-area {
    padding: 1rem 1.5rem;
    background: white;
    border-top: 1px solid var(--gray-200);
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.input-wrapper input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--gray-300);
    border-radius: 1.5rem;
    font-size: 0.9375rem;
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.message-options {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: 0.5rem;
}

/* Debug Panel */
.debug-panel {
    width: 400px;
    background: var(--gray-900);
    color: var(--gray-100);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--gray-700);
    overflow: hidden;
}

.debug-panel.collapsed {
    width: 0;
    border: none;
}

.debug-header {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-700);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.debug-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
}

.debug-actions {
    display: flex;
    gap: 0.5rem;
}

.debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.8125rem;
}

.debug-welcome {
    color: var(--gray-500);
    text-align: center;
    padding: 2rem 1rem;
}

.debug-entry {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--gray-800);
    border-radius: 0.375rem;
    border-left: 3px solid var(--gray-700);
}

.debug-entry.success {
    border-left-color: var(--success-color);
}

.debug-entry.error {
    border-left-color: var(--danger-color);
}

.debug-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.debug-method {
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
}

.debug-method.GET {
    background: var(--success-color);
    color: white;
}

.debug-method.POST {
    background: var(--primary-color);
    color: white;
}

.debug-method.PATCH {
    background: var(--warning-color);
    color: white;
}

.debug-method.DELETE {
    background: var(--danger-color);
    color: white;
}

.debug-status {
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
}

.debug-status.success {
    background: var(--success-color);
    color: white;
}

.debug-status.error {
    background: var(--danger-color);
    color: white;
}

.debug-url {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-bottom: 0.5rem;
    word-break: break-all;
}

.debug-timestamp {
    font-size: 0.6875rem;
    color: var(--gray-500);
}

.debug-body {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--gray-900);
    border-radius: 0.25rem;
    font-size: 0.75rem;
    overflow-x: auto;
}

.debug-body pre {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

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

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #DC2626;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-icon {
    padding: 0.5rem;
    border: none;
    background: transparent;
    color: var(--gray-600);
    cursor: pointer;
    border-radius: 0.375rem;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.btn-icon.btn-sm {
    padding: 0.375rem;
}

.btn-icon.btn-danger {
    color: var(--danger-color);
}

.btn-icon.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 0.5rem;
    width: 90%;
    max-width: 550px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.3s ease;
}

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

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-header .btn-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0.5rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.input-group {
    display: flex;
    gap: 0.5rem;
}

.input-group input {
    flex: 1;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.checkbox-label input {
    width: auto;
}

/* Participants Selector */
.participants-selector {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    padding: 0.5rem;
    background: var(--gray-50);
}

.participant-group {
    margin-bottom: 0.75rem;
}

.participant-group:last-child {
    margin-bottom: 0;
}

.group-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: var(--gray-100);
    border-radius: 0.25rem;
}

.participant-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 0.25rem;
    transition: background 0.15s;
    font-size: 0.875rem;
}

.participant-checkbox:hover {
    background: white;
}

.participant-checkbox input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

.participant-checkbox input[type="checkbox"]:checked + span {
    font-weight: 600;
    color: var(--primary-color);
}

.selected-count {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--gray-50);
    border-radius: 0.25rem;
    text-align: center;
}

.selected-count .count-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    background: var(--primary-color);
    color: white;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-right: 0.25rem;
}

/* Participants List */
.participants-list {
    margin-bottom: 1rem;
}

.participant-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
}

.participant-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.participant-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.participant-role {
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    background: var(--gray-100);
    color: var(--gray-700);
}

/* Utility Classes */
.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

.text-gray {
    color: var(--gray-600);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--gray-100);
}

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

.debug-content::-webkit-scrollbar-track {
    background: var(--gray-800);
}

.debug-content::-webkit-scrollbar-thumb {
    background: var(--gray-600);
}

/* Responsive */
@media (max-width: 1024px) {
    .debug-panel {
        width: 0;
        border: none;
    }
    
    .sidebar {
        width: 280px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s;
    }
    
    .sidebar.show {
        transform: translateX(0);
    }
}

