/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --sidebar-w: 260px;
    --fileviewer-w: 340px;
    --bg-primary: #faf9f7;
    --bg-sidebar: #1e1e2e;
    --bg-sidebar-hover: #2a2a3c;
    --bg-message-user: #e8e5ff;
    --bg-message-bot: #ffffff;
    --bg-input: #ffffff;
    --border: #e5e5e5;
    --text-primary: #1a1a1a;
    --text-secondary: #666;
    --text-sidebar: #ccc;
    --accent: #6b5ce7;
    --accent-hover: #5a4bd6;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    color: var(--text-primary);
    background: var(--bg-primary);
}

body {
    display: flex;
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    gap: 16px;
    overflow-y: auto;
}

.sidebar-logo-link {
    display: inline-block;
    cursor: pointer;
}
.sidebar-logo {
    height: 32px;
    width: auto;
    margin-bottom: 8px;
}
.sidebar-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.5px;
}
.sidebar-header .subtitle {
    font-size: 12px;
    color: #888;
    display: block;
    margin-top: 2px;
}

.harness-select label,
.model-select label,
.session-list label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    margin-bottom: 6px;
}

.harness-select select,
.model-select select {
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #444;
    background: #2a2a3c;
    color: #eee;
    font-size: 14px;
    cursor: pointer;
}

.btn-primary {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.session-list { flex: 1; overflow-y: auto; }
.session-list ul { list-style: none; }
.session-list li {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #bbb;
    transition: background 0.15s;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.session-list li .session-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.session-list li:hover { background: var(--bg-sidebar-hover); }
.session-list li.active {
    background: var(--bg-sidebar-hover);
    color: #fff;
    font-weight: 600;
}
.session-delete-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
    flex-shrink: 0;
}
.session-list li:hover .session-delete-btn { opacity: 1; }
.session-delete-btn:hover { color: #ff4444; background: rgba(255,68,68,0.15); }

/* ── Chat Area ───────────────────────────────────── */
#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Welcome */
#welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-secondary);
}
#welcome-screen h2 {
    font-size: 28px;
    color: var(--text-primary);
}

.harness-cards {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 700px;
}
.harness-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    width: 200px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
}
.harness-card:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(107,92,231,0.12);
    transform: translateY(-1px);
}
.harness-card h4 {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.harness-card p {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Chat container */
#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: #fff;
    font-weight: 600;
    font-size: 14px;
}
#chat-header button {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 16px;
}

/* Messages */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    max-width: 85%;
    line-height: 1.65;
    font-size: 14px;
}
.message.user {
    align-self: flex-end;
    background: var(--bg-message-user);
    padding: 12px 16px;
    border-radius: var(--radius) var(--radius) 4px var(--radius);
    position: relative;
}
.msg-actions {
    margin-top: 6px;
    text-align: right;
}
.msg-undo-btn {
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    color: #888;
    cursor: pointer;
    transition: all 0.15s;
}
.msg-undo-btn:hover {
    background: #fff;
    color: #d32f2f;
    border-color: #d32f2f;
}
.message.assistant {
    align-self: flex-start;
    background: var(--bg-message-bot);
    padding: 16px 20px;
    border-radius: var(--radius) var(--radius) var(--radius) 4px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 100%;
}

.message.assistant img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s;
}
.message.assistant img:hover {
    transform: scale(1.02);
}

.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
    margin-top: 16px;
    margin-bottom: 8px;
}
.message.assistant h1 { font-size: 20px; }
.message.assistant h2 { font-size: 17px; }
.message.assistant h3 { font-size: 15px; }

.message.assistant p { margin-bottom: 8px; }
.message.assistant ul, .message.assistant ol { margin: 8px 0 8px 20px; }
.message.assistant li { margin-bottom: 4px; }

.message.assistant pre {
    background: #f5f5f5;
    border-radius: 8px;
    padding: 12px 16px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}
.message.assistant code {
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px;
}
.message.assistant :not(pre) > code {
    background: #f0f0f0;
    padding: 2px 5px;
    border-radius: 4px;
}
.message.assistant table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}
.message.assistant th, .message.assistant td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    font-size: 13px;
    text-align: left;
}
.message.assistant th { background: #f9f9f9; font-weight: 600; }

.message.tool-use {
    align-self: flex-start;
    background: #f5f0ff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 12px;
    color: #6b5ce7;
    font-family: monospace;
}

.message.status {
    align-self: center;
    color: var(--text-secondary);
    font-size: 13px;
    font-style: italic;
}

.activity-log {
    margin: 8px 16px;
    font-size: 12px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.activity-log-summary {
    padding: 6px 12px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    list-style: none;
}

.activity-log-summary::before {
    content: "▶ ";
    font-size: 10px;
}

.activity-log[open] > .activity-log-summary::before {
    content: "▼ ";
}

.activity-log-summary::-webkit-details-marker { display: none; }

.activity-log-items {
    padding: 4px 12px 8px;
    border-top: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
}

.activity-log-item {
    padding: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Input */
#input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: #fff;
}

#status-bar {
    font-size: 12px;
    color: var(--accent);
    margin-bottom: 8px;
    padding: 4px 0;
}

#chat-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    max-height: 150px;
    transition: border-color 0.15s;
}
#chat-input:focus {
    outline: none;
    border-color: var(--accent);
}

#send-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, transform 0.05s;
    min-width: 80px;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:active { transform: scale(0.97); }
#send-btn.cancel {
    background: #d32f2f;
}
#send-btn.cancel:hover {
    background: #b71c1c;
}

/* ── Usage footer (sidebar) ─────────────────────── */
.usage-footer {
    margin-top: auto;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
}
.usage-line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
}
.usage-line span:last-child {
    color: var(--text-primary);
    font-weight: 600;
}
.usage-bar-wrap {
    height: 6px;
    background: #e8e8e8;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}
.usage-bar {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    width: 100%;
    transition: width 0.3s;
}
.usage-bar.warn { background: linear-gradient(90deg, #ff9800, #ffc107); }
.usage-bar.danger { background: linear-gradient(90deg, #f44336, #e57373); }
.usage-line-sub {
    font-size: 11px;
    text-align: right;
}

/* ── Powered by ────────────────────────────────── */
.powered-by {
    text-align: center;
    font-size: 11px;
    color: #555;
    padding: 8px 0 4px;
    margin-top: auto;
}
.powered-by-login {
    text-align: center;
    font-size: 11px;
    color: #aaa;
    margin-top: 20px;
}
.powered-by-welcome {
    text-align: center;
    font-size: 12px;
    color: #bbb;
    margin-top: 32px;
}

/* ── Attach button ──────────────────────────────── */
#attach-btn {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}
#attach-btn:hover { background: #f5f5f5; }

/* ── Upload preview ─────────────────────────────── */
#upload-preview {
    padding: 8px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.upload-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f0f0f0;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    color: #333;
}
.upload-chip button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: #999;
    padding: 0 2px;
    line-height: 1;
}
.upload-chip button:hover { color: #d32f2f; }

/* ── File Viewer Resize Handle ──────────────────── */
#file-viewer-resize {
    width: 5px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    flex-shrink: 0;
    z-index: 10;
}
#file-viewer-resize::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 2px;
    width: 1px;
    background: var(--border);
}
#file-viewer-resize:hover,
#file-viewer-resize.dragging {
    background: var(--accent);
}
#file-viewer-resize:hover::after,
#file-viewer-resize.dragging::after {
    background: var(--accent);
}
#file-viewer-resize.hidden { display: none; }

/* ── File Viewer ─────────────────────────────────── */
#file-viewer {
    width: var(--fileviewer-w);
    min-width: 200px;
    max-width: 60vw;
    border-left: none;
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#file-viewer.hidden { display: none; }

.file-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.file-viewer-header h3 { font-size: 14px; }
#download-all-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
}
#download-all-btn:hover { background: #f5f5f5; }

#file-tree {
    padding: 12px;
    overflow-y: auto;
    max-height: 250px;
    border-bottom: 1px solid var(--border);
}

.folder-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    user-select: none;
}
.folder-item:hover { background: #f0f0f0; }
.folder-toggle {
    display: inline-block;
    width: 14px;
    font-size: 10px;
    color: #999;
    transition: transform 0.15s;
}
.file-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background 0.1s;
}
.file-item:hover { background: #f5f5f5; }
.file-item.active { background: #ebe8ff; }
.file-icon { font-size: 14px; }
.file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-size {
    margin-left: auto;
    font-size: 11px;
    color: #999;
    white-space: nowrap;
}

#file-preview {
    flex: 1;
    overflow: auto;
    padding: 16px;
    font-size: 13px;
    line-height: 1.6;
}
#file-preview img {
    max-width: 100%;
    border-radius: 8px;
}
#file-preview pre {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
}

/* ── Scrollbar ───────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 900px) {
    #sidebar { width: 200px; min-width: 200px; }
    #file-viewer { width: 260px; min-width: 260px; }
}
@media (max-width: 700px) {
    #sidebar { display: none; }
    #file-viewer { display: none; }
}

/* ── Login screen ────────────────────────────────── */
.login-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1e1e2e 0%, #2a2a4a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.login-box {
    background: #fff;
    padding: 48px 40px;
    border-radius: 20px;
    width: 90%;
    max-width: 440px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    animation: modalIn 0.3s ease-out;
}
.login-box h1 {
    font-size: 28px;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.login-sub {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 28px;
}
.login-desc {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}
.login-box input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    margin-bottom: 14px;
    text-align: center;
    font-family: inherit;
    transition: border-color 0.15s;
}
.login-box input:focus {
    outline: none;
    border-color: var(--accent);
}
.login-box .btn-primary {
    width: 100%;
    padding: 14px;
    font-size: 15px;
    margin-bottom: 12px;
}
.login-hint {
    color: #999;
    font-size: 12px;
    line-height: 1.5;
    margin-top: 4px;
}
.login-icon {
    font-size: 56px;
    margin-bottom: 16px;
}
#login-step-sent h3 {
    font-size: 20px;
    margin-bottom: 12px;
    color: var(--text-primary);
}
#login-step-sent p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.7;
    margin-bottom: 16px;
}
.btn-secondary {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-secondary:hover { background: #f5f5f5; }
.login-error {
    background: #fee;
    color: #c33;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-top: 12px;
}

/* ── User badge in sidebar ───────────────────────── */
#user-badge {
    margin-top: 12px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.08);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: #ddd;
}
#user-badge button {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
}
#user-badge button:hover { color: #fff; background: rgba(255,255,255,0.1); }

/* ── Username modal ──────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal {
    background: #fff;
    padding: 36px 40px;
    border-radius: 16px;
    width: 90%;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    animation: modalIn 0.25s ease-out;
    position: relative;
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}
.modal-close:hover {
    color: #333;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(-10px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text-primary);
}
.modal p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 14px;
    line-height: 1.6;
}
.modal input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    margin-bottom: 16px;
    text-align: center;
    font-family: inherit;
    transition: border-color 0.15s;
}
.modal input:focus {
    outline: none;
    border-color: var(--accent);
}
.modal .btn-primary {
    width: 100%;
    padding: 12px;
    font-size: 15px;
}

/* ── Typing indicator ────────────────────────────── */
.typing-dots span {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin: 0 2px;
    animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}
