/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --danger-color: #dc2626;
    --success-color: #16a34a;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

.container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Authentication Styles */
#auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-box {
    background: var(--surface);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.auth-box h1 {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--primary-color);
}

.auth-form h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.auth-form input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.auth-form button {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.auth-form button:hover {
    background: var(--primary-hover);
}

.auth-form p {
    text-align: center;
    margin-top: 1rem;
    color: var(--text-secondary);
}

.auth-form a {
    color: var(--primary-color);
    text-decoration: none;
}

.auth-form a:hover {
    text-decoration: underline;
}

/* Header */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    color: var(--primary-color);
    font-size: 1.5rem;
}

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

#user-info {
    color: var(--text-secondary);
    font-weight: 500;
}

/* Main Content Layout */
.main-content {
    display: flex;
    flex: 1;
    height: calc(100vh - 70px);
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.agent-selection {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.agent-selection label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

#agent-select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    font-size: 0.95rem;
    cursor: pointer;
}

.session-controls {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.sessions-list h3 {
    margin-bottom: 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
    font-weight: 600;
}

.session-item {
    margin-bottom: 0.5rem;
    background: var(--background);
    border-radius: 6px;
    transition: background-color 0.2s;
    position: relative;
    display: flex;
    align-items: center;
}

.session-item:hover {
    background: #f1f5f9;
}

.session-item.active {
    background: #dbeafe;
    border-left: 3px solid var(--primary-color);
}

.session-item-content {
    flex: 1;
    padding: 0.75rem;
    cursor: pointer;
}

.session-item-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.session-item-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.session-delete-btn {
    padding: 0.5rem;
    margin-right: 0.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0;
    visibility: hidden;
}

.session-item:hover .session-delete-btn {
    opacity: 1;
    visibility: visible;
}

.session-delete-btn:hover {
    background: #fee2e2;
    color: #dc2626;
}

.session-delete-btn svg {
    display: block;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background);
}

.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

.welcome h2 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.welcome p {
    color: var(--text-secondary);
}

#chat-interface {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.session-info {
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.session-stats {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#token-count {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.message {
    margin-bottom: 1rem;
    display: flex;
    gap: 0.75rem;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    font-size: 0.875rem;
}

.message-user .message-avatar {
    background: var(--primary-color);
    order: 2;
}

.message-assistant .message-avatar {
    background: var(--secondary-color);
}

.message-content {
    max-width: 70%;
    background: var(--surface);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.message-user .message-content {
    background: var(--primary-color);
    color: white;
}

.message-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-content code {
    background: #f1f5f9;
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
}

.message-user .message-content code {
    background: rgba(255, 255, 255, 0.2);
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem 1rem;
    margin-left: 48px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    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);
    }
}

/* Input Area */
.input-area {
    padding: 1rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 1rem;
}

#message-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
}

#message-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-primary:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
}

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

.btn-secondary:hover {
    background: #475569;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    font-size: 0.875rem;
}

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

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    background: var(--surface);
    padding: 1rem 1.5rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    min-width: 250px;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--danger-color);
}

.toast.info {
    border-left: 4px solid var(--primary-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

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

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

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

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.close-button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.close-button:hover {
    background: var(--background);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

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

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input[type="text"],
.form-group input[type="file"],
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 1rem;
}

.form-group input[type="file"] {
    background: var(--surface);
    cursor: pointer;
}

.form-group input[type="file"]:hover {
    background: var(--background);
}

.form-group textarea {
    resize: vertical;
    font-family: 'Courier New', monospace;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.radio-group label {
    display: flex;
    align-items: center;
    font-weight: normal;
    cursor: pointer;
}

.radio-group input[type="radio"] {
    margin-right: 0.5rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--surface);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-primary);
}

.mobile-menu-toggle svg {
    width: 24px;
    height: 24px;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Show mobile menu toggle */
    .mobile-menu-toggle {
        display: block;
    }
    
    /* Header adjustments */
    header {
        padding: 0.75rem 1rem;
    }
    
    .header-content h1 {
        font-size: 1.1rem;
    }
    
    #user-info {
        display: none;
    }
    
    /* Main layout */
    .main-content {
        position: relative;
        height: calc(100vh - 60px);
    }
    
    /* Sidebar as overlay */
    .sidebar {
        position: fixed;
        top: 60px;
        left: -100%;
        width: 85%;
        max-width: 320px;
        height: calc(100vh - 60px);
        z-index: 100;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }
    
    .sidebar.mobile-open {
        left: 0;
    }
    
    /* Overlay backdrop */
    .mobile-backdrop {
        display: none;
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 99;
    }
    
    .mobile-backdrop.active {
        display: block;
    }
    
    /* Chat area takes full width */
    .chat-area {
        width: 100%;
    }
    
    /* Session item adjustments */
    .session-delete-btn {
        opacity: 1;
        visibility: visible;
    }
    
    .session-item-info {
        font-size: 0.7rem;
    }
    
    /* Message adjustments */
    .messages-container {
        padding: 0.75rem;
    }
    
    .message {
        margin-bottom: 0.75rem;
    }
    
    .message-content {
        max-width: 85%;
        font-size: 0.95rem;
    }
    
    .message-avatar {
        width: 30px;
        height: 30px;
        font-size: 0.75rem;
    }
    
    /* Input area adjustments */
    .input-area {
        padding: 0.75rem;
        gap: 0.75rem;
    }
    
    #message-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.625rem;
    }
    
    /* Session info adjustments */
    .session-info {
        padding: 0.75rem;
        flex-wrap: wrap;
    }
    
    #session-title {
        font-size: 0.9rem;
        word-break: break-all;
    }
    
    #token-count {
        font-size: 0.75rem;
    }
    
    /* Button adjustments */
    .btn-primary, .btn-secondary, .btn-danger {
        padding: 0.625rem 0.875rem;
        font-size: 0.9rem;
    }
    
    /* Welcome screen */
    .welcome {
        padding: 1rem;
    }
    
    .welcome h2 {
        font-size: 1.25rem;
    }
    
    /* Auth box adjustments */
    .auth-box {
        padding: 1.5rem;
        margin: 1rem;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .header-content h1 {
        font-size: 1rem;
    }
    
    .sidebar {
        width: 90%;
    }
    
    .message-content {
        max-width: 90%;
        padding: 0.625rem 0.875rem;
    }
    
    .session-info {
        padding: 0.5rem;
    }
    
    /* Ensure delete button is touch-friendly */
    .session-delete-btn {
        padding: 0.625rem;
        min-width: 44px;
        min-height: 44px;
    }
}

/* Approval Dialog */
.approval-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

.approval-dialog-content {
    background: var(--surface);
    border-radius: 12px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

.approval-dialog h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.approval-dialog .tool-info {
    background: var(--background);
    padding: 1rem;
    border-radius: 6px;
    margin: 1rem 0;
    font-family: monospace;
}

.approval-dialog .tool-info ul {
    margin-top: 0.5rem;
    padding-left: 1.5rem;
}

.approval-dialog .tool-info li {
    margin: 0.25rem 0;
    word-break: break-all;
}

.approval-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.approval-buttons button {
    min-width: 120px;
}

/* Auto-approve toggle */
.auto-approve-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--background);
    border-radius: 6px;
}

.auto-approve-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.auto-approve-toggle label {
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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