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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 30px;
    color: white;
    gap: 40px;
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}



.project-input {
    padding: 8px 12px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 5px;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 14px;
    width: 100%;
    max-width: 200px;
}

.project-input::placeholder {
    color: rgba(255,255,255,0.7);
}

.header-buttons {
    display: flex;
    gap: 10px;
}

.header-btn {
    padding: 8px 16px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 5px;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.header-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-1px);
}

.logo {
    height: 60px;
    width: auto;
}

.header-text {
    text-align: left;
}

header h1 {
    font-size: 1.8rem;
    margin-bottom: 0;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1rem;
    opacity: 0.9;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    height: 70vh;
}

.editor-section, .output-section {
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.toolbar {
    background: #f8f9fa;
    padding: 10px 15px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    /* allow toolbar to grow to two rows when needed */
    align-items: flex-end;
    min-height: 50px;
    box-sizing: border-box;
    justify-content: space-between;
}

.tabs-group {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.file-tabs {
    display: flex;
    gap: 6px;
    /* allow wrapping into two rows; wrap-reverse places wrapped items on the top row
       so earlier (left) items remain on the bottom row and later items move to the top */
    flex-wrap: wrap-reverse;
    align-content: flex-end;
    /* constrain height so it only ever shows up to two rows visually */
    max-height: 64px;
}

.file-tab {
    background: #e9ecef;
    border: 1px solid #ddd;
    border-radius: 5px 5px 0 0;
    padding: 8px 12px;
    font-size: 14px;
    color: #666;
    font-family: 'Courier New', monospace;
    border-bottom: none;
    position: relative;
    top: 1px;
    cursor: pointer;
    user-select: none;
    /* small margin between wrapped rows */
    margin-top: 4px;
}

.file-tab.active {
    background: #fff;
    color: #333;
    z-index: 1;
}

.file-tab:hover {
    background: #dee2e6;
}

.file-tab.active:hover {
    background: #fff;
}

.add-tab {
    background: #e9ecef;
    border: 1px solid #ddd;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    font-size: 16px;
    color: #666;
    cursor: pointer;
    border-bottom: none;
    position: relative;
    top: 1px;
    user-select: none;
}

.add-tab:hover {
    background: #dee2e6;
}

.save-btn {
    background: #28a745;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 8px 16px;
    font-size: 14px;
    -webkit-user-select: none;
    user-select: none;
    transition: all 0.3s ease;
}

.save-btn:hover {
    background: #218838;
    transform: translateY(-1px);
}

.delete-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.delete-btn:hover {
    background: #c82333;
    transform: translateY(-1px);
}

.file-actions {
    display: flex;
    gap: 5px;
}

.file-name-input {
    background: transparent;
    border: none;
    outline: none;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: #333;
    width: 100%;
}

#languageSelect {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    font-size: 14px;
}

button {
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
}

#compileBtn {
    background: #28a745;
    color: white;
}

#runBtn {
    background: #007bff;
    color: white;
}

#interactiveBtn {
    background: #17a2b8;
    color: white;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.editor-container {
    height: calc(100% - 60px);
    display: flex;
    align-items: stretch;
}

.line-numbers {
    background: #e9ecef;
    color: #6c757d;
    padding: 20px 10px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    text-align: right;
    border-right: 1px solid #ddd;
    -webkit-user-select: none;
    user-select: none;
    min-width: 40px;
    white-space: pre;
    /* Allow the line numbers column to scroll independently so it can be synced
       to the editor's scrollTop via JavaScript. Height set to 100% to match
       the textarea's visible area. */
    overflow-y: auto;
    height: 100%;
    box-sizing: border-box;
    /* Hide scrollbar but keep scrolling functional */
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none; /* Firefox */
}

/* WebKit browsers */
.line-numbers::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

#codeEditor {
    flex: 1;
    height: 100%;
    border: none;
    padding: 20px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    background: #f8f9fa;
    overflow: auto;
    box-sizing: border-box;
}

.output-header {
    background: #343a40;
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px;
    box-sizing: border-box;
    flex-shrink: 0;
}

.output-buttons {
    display: flex;
    gap: 10px;
}

.output-header h3 {
    margin: 0;
}

.output-buttons button {
    padding: 5px 10px;
    font-size: 12px;
}

#clearOutput {
    background: #dc3545;
    color: white;
}

.output-container {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

#output, #console {
    padding: 20px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    background: #f8f9fa;
    min-height: 100%;
    border: none;
    outline: none;
    resize: none;
    width: calc(100% - 40px);
}



.success {
    color: #28a745;
}

.error {
    color: #dc3545;
}

.info {
    color: #17a2b8;
}

footer {
    text-align: center;
    padding: 20px;
    color: white;
    margin-top: 20px;
    font-size: 14px;
    opacity: 0.8;
}

footer a {
    color: #4CAF50;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .editor-section, .output-section {
        height: 400px;
    }
}

/* Chatbot styles */
.chatbot {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2000;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.chat-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: #007bff;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.chat-panel {
    width: 320px;
    height: 420px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
    overflow: hidden;
    display: none;
    flex-direction: column;
}
.chat-header {
    background: #007bff;
    color: white;
    padding: 12px 14px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat-controls { display: flex; gap: 8px; align-items: center; }
.chat-controls button { background: rgba(255,255,255,0.15); color: white; border: none; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.chat-controls button:hover { background: rgba(255,255,255,0.25); }
.chat-messages {
    padding: 12px;
    height: calc(100% - 108px);
    overflow-y: auto;
    background: #f8f9fa;
}
.chat-message { margin-bottom: 12px; }
.chat-message.assistant { color: #222; }
.chat-message.user { text-align: right; color: #0056b3; }
.chat-meta { font-size: 11px; color: #999; margin-top: 4px; }
.chat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #eee; }
.chat-input { flex: 1; padding: 8px 10px; border-radius: 6px; border: 1px solid #ddd; }
.chat-send { background: #17a2b8; color: white; border: none; padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.chat-voice { background: #ffc107; color: #222; border: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 16px; }
.chat-voice.recording { background: #dc3545; color: white; box-shadow: 0 4px 10px rgba(220,53,69,0.2); transform: translateY(-1px); }
.chat-close { cursor: pointer; opacity: 0.9; }

/* Toast notifications */
.toast-container {
    position: fixed;
    right: 20px;
    bottom: 90px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: rgba(0,0,0,0.85);
    color: white;
    padding: 10px 14px;
    border-radius: 8px;
    min-width: 180px;
}
.chat-typing { font-style: italic; color: #666; margin-bottom: 6px; }

/* Modal for upload results */
.modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
}
.modal-content {
    background: white;
    padding: 18px;
    border-radius: 8px;
    width: 90%;
    max-width: 700px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal-close {
    float: right;
    cursor: pointer;
    font-size: 20px;
}
.upload-file-link { word-break: break-all; display: block; margin-bottom: 6px; }

/* Tutorial modal styles */
.tutorial-modal .modal-content {
    width: 90%;
    max-width: 1200px;
    height: 80vh;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.tutorial-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #ddd;
    background: #f8f9fa;
}

.tutorial-modal .modal-header h3 {
    margin: 0;
    color: #333;
}

.tutorial-modal .modal-body {
    flex: 1;
    padding: 0;
    overflow: hidden;
}

.tutorial-modal iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Chat message formatting styles */
.chat-code {
    background: #f4f4f4;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    margin: 8px 0;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
    overflow-x: auto;
    white-space: pre;
}

.chat-inline-code {
    background: #f4f4f4;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 2px 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #d63384;
}

.chat-list-item {
    margin: 4px 0;
    padding-left: 8px;
}

.chat-message.assistant {
    line-height: 1.5;
}

.chat-message.assistant strong {
    font-weight: 600;
    color: #0056b3;
}

.chat-message.assistant em {
    font-style: italic;
    color: #6c757d;
}

.chat-intro-btn {
    background: #28a745;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    margin: 2px 4px;
    transition: background 0.2s;
}

.chat-intro-btn:hover {
    background: #218838;
}

/* File I/O styles */
.file-io-section {
    padding: 10px 15px;
    border-top: 1px solid #e9ecef;
    background: #f8f9fa;
    flex-shrink: 0;
    max-height: 100px;
    overflow-y: auto;
}

.file-io-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.file-io-btn {
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.file-io-btn:hover {
    background: #5a6268;
    transform: translateY(-1px);
}

.input-files-list {
    max-height: 100px;
    overflow-y: auto;
}

.input-file-item {
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 8px 12px;
    margin: 4px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

.input-file-path {
    color: #007bff;
    font-weight: bold;
}

.input-file-remove {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 10px;
    cursor: pointer;
}

.output-file-item {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    margin: 8px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.output-file-download {
    background: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.output-file-download:hover {
    background: #218838;
}