html,
body {
    height: 100%;
    overflow: hidden;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.5;
}

.demo-banner {
    background: #fff3cd;
    border-bottom: 1px solid #ffc107;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    font-size: 14px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.demo-banner a {
    color: #0c5460;
    text-decoration: none;
    font-weight: 600;
    border: 1px solid #0c5460;
    padding: 6px 12px;
    border-radius: 4px;
    transition: all 0.2s;
    white-space: nowrap;
}

.demo-banner a:hover {
    background: #0c5460;
    color: white;
}

.container {
    display: grid;
    grid-template-rows: auto auto 1fr;
    height: 100vh;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

/* Header */
header {
    background: white;
    border-bottom: 2px solid #f0f0f0;
    padding: 18px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

header h1 {
    font-size: 26px;
    font-weight: 700;
    color: #1a1a1a;
}

.model-select {
    padding: 10px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    background: white;
    transition: all 0.2s ease;
}

.model-select:hover {
    border-color: #007aff;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

.model-select:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

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

.modal-content {
    background: white;
    border-radius: 8px;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

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

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    overflow-y: auto;
    padding: 20px;
    font-size: 14px;
    line-height: 1.6;
}

.modal-body h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: #0052cc;
    font-size: 16px;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.modal-body ul {
    margin: 8px 0;
    padding-left: 20px;
}

.modal-body li {
    margin: 6px 0;
}

/* Main Layout */
.main {
    display: grid;
    grid-template-columns: 260px 1fr;
    flex: 1;
    overflow: hidden;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 0;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: #fafafa;
    border-right: 1px solid #e0e0e0;
    padding: 24px;
    overflow-y: auto;
    min-height: 0;
}

.sidebar h2 {
    font-size: 18px;
    margin-bottom: 16px;
    font-weight: 600;
}

.sidebar h3 {
    font-size: 14px;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.section {
    margin-bottom: 24px;
}

.demo-notice {
    background: #e7f3ff;
    border: 1px solid #b3d9ff;
    border-radius: 4px;
    padding: 12px;
    font-size: 12px;
    color: #0052cc;
    margin-bottom: 16px;
    line-height: 1.6;
}

.demo-notice-link {
    color: #0052cc;
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px solid #0052cc;
    transition: color 0.2s;
}

.demo-notice-link:hover {
    color: #0041a8;
    border-bottom-color: #0041a8;
}

.help-btn-notice {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #0052cc 0%, #0041a8 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 82, 204, 0.2);
}

.help-btn-notice:hover {
    background: linear-gradient(135deg, #0041a8 0%, #002d7d 100%);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
    transform: translateY(-1px);
}

.demo-disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.demo-disabled label {
    cursor: not-allowed;
}

.upload-disabled-msg {
    font-size: 11px;
    color: #999;
    margin-top: 8px;
    font-style: italic;
}

.section label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    cursor: pointer;
    font-weight: 500;
}

.section label input[type="radio"] {
    cursor: pointer;
    margin: 0;
}

.section input[type="radio"] {
    cursor: pointer;
}

.path-input,
.upload-area {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 8px;
    font-size: 13px;
}

.upload-area {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
}

.btn {
    width: 100%;
    padding: 11px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    color: #333;
}

.btn:hover:not(:disabled) {
    background: #f0f7ff;
    border-color: #007aff;
    color: #0052cc;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.status {
    padding: 10px;
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 8px;
    font-weight: 500;
}

.status-detail {
    font-size: 12px;
    color: #666;
}

.codebase-path {
    padding: 10px;
    background: #f0f7ff;
    border: 1px solid #b3d9ff;
    border-radius: 4px;
    font-size: 12px;
    color: #0052cc;
    word-break: break-all;
    margin-bottom: 12px;
}

.folder-name {
    padding: 8px;
    background: #f0f7ff;
    border: 1px solid #b3d9ff;
    border-radius: 4px;
    font-size: 11px;
    color: #0052cc;
    word-break: break-all;
    margin-top: 8px;
}

.upload-hint {
    margin-top: 8px;
    font-size: 11px;
    line-height: 1.4;
    color: #666;
}

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

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 12px;
    animation: slideIn 0.3s ease-out;
}

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

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

.message.agent {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
}

.user .message-bubble {
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.2);
}

.agent .message-bubble {
    background: #f5f5f5;
    color: #333;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Markdown rendering in messages */
.agent .message-bubble h1 {
    font-size: 18px;
    margin: 16px 0 10px 0;
    font-weight: 700;
    border-bottom: 2px solid #007aff;
    padding-bottom: 6px;
}

.agent .message-bubble h2 {
    font-size: 15px;
    margin: 14px 0 8px 0;
    font-weight: 700;
    color: #0052cc;
}

.agent .message-bubble h3 {
    font-size: 14px;
    margin: 10px 0 6px 0;
    font-weight: 600;
    color: #333;
}

.agent .message-bubble p {
    margin: 8px 0;
}

.agent .message-bubble code {
    background: #e8e8e8;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.agent .message-bubble pre {
    background: #f5f5f5;
    color: #333;
    padding: 12px;
    border-radius: 4px;
    border-left: 3px solid #007aff;
    overflow-x: auto;
    margin: 10px 0;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
}

.agent .message-bubble code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    color: #d63384;
}

.agent .message-bubble pre code {
    background: none;
    padding: 0;
    color: #333;
}

.agent .message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    font-size: 13px;
    background: white;
}

.agent .message-bubble th {
    background: #f0f7ff;
    font-weight: 600;
    border: 1px solid #b3d9ff;
    padding: 10px;
}

.agent .message-bubble td {
    border: 1px solid #e0e0e0;
    padding: 10px;
}

.agent .message-bubble tr:nth-child(even) {
    background: #fafafa;
}

/* Steps/Thinking Area */
.steps-area {
    background: #fafafa;
    border-top: 1px solid #eee;
    padding: 12px 20px;
    max-height: 120px;
    overflow-y: auto;
    animation: fadeIn 0.2s ease-out;
}

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

.steps-area.fade-out {
    animation: fadeOut 0.5s ease-out forwards;
}

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

.steps-label {
    font-size: 12px;
    color: #999;
    font-weight: 600;
    margin-bottom: 8px;
}

.steps-content {
    font-size: 12px;
    color: #777;
    font-family: 'Monaco', 'Courier New', monospace;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.step-line {
    padding: 2px 0;
    animation: stepSlideIn 0.3s ease-out;
}

@keyframes stepSlideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #e0e0e0;
    border-top-color: #666;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* Input Section */
.input-section {
    display: flex;
    gap: 12px;
    padding: 24px 28px;
    border-top: 2px solid #f0f0f0;
    background: white;
}

#queryInput {
    flex: 1;
    padding: 14px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    transition: all 0.3s ease;
    background: white;
}

#queryInput:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
    background: white;
}

#queryInput:disabled {
    background: #f5f5f5;
    color: #b0b0b0;
    border-color: #d0d0d0;
    cursor: not-allowed;
}

.btn-send {
    width: 48px;
    height: 48px;
    padding: 0;
    flex-shrink: 0;
    font-size: 20px;
    border: none;
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
    font-weight: 600;
}

.btn-send:hover:not(:disabled) {
    background: linear-gradient(135deg, #0066ff 0%, #0041a8 100%);
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.4);
    transform: translateY(-2px);
}

.btn-send:active:not(:disabled) {
    transform: translateY(0);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

/* Responsive */
@media (max-width: 768px) {
    .main {
        grid-template-columns: 1fr;
        max-width: 100%;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #ddd;
        max-height: 200px;
    }

    .message-bubble {
        max-width: 88%;
    }

    .input-section {
        padding: 16px 20px;
        gap: 10px;
    }

    #queryInput {
        padding: 12px 14px;
        font-size: 14px;
    }

    .btn-send {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }

    .messages {
        padding: 20px 16px;
    }

    header {
        padding: 14px 16px;
        max-width: 100%;
    }

    header h1 {
        font-size: 22px;
    }

    .demo-banner {
        max-width: 100%;
    }
}
