/* Sentience v2 — Web UI Styles */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-input: #0d1117;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --danger: #f85149;
    --success: #3fb950;
    --user-bg: #1c2a3a;
    --agent-bg: #161b22;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* ── Login Page ─────────────────────────────────────────────────── */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.login-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    width: 100%;
    max-width: 360px;
}

.login-box h1 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--text-primary);
}

.login-box input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.login-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.login-box button {
    width: 100%;
    padding: 0.6rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.4rem;
}

.login-box button:hover { background: var(--accent-hover); }

.login-error {
    color: var(--danger);
    font-size: 0.85rem;
    text-align: center;
    margin-top: 0.8rem;
    min-height: 1.2rem;
}

/* ── Chat Layout ────────────────────────────────────────────────── */

.app {
    display: flex;
    height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────── */

.sidebar {
    width: 220px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 1.1rem;
    font-weight: 600;
}

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

.agent-btn {
    display: block;
    width: 100%;
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.25rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
}

.agent-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.agent-btn.active {
    background: var(--bg-tertiary);
    border-color: var(--border);
    color: var(--accent);
}

.agent-btn .agent-name { font-weight: 600; }
.agent-btn .agent-desc {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.sidebar-footer {
    padding: 0.5rem;
    border-top: 1px solid var(--border);
}

.sidebar-footer button {
    display: block;
    width: 100%;
    padding: 0.5rem 0.8rem;
    margin-bottom: 0.25rem;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
}

.sidebar-footer button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ── Chat Area ──────────────────────────────────────────────────── */

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

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

.message {
    margin-bottom: 1rem;
    max-width: 80%;
    line-height: 1.5;
}

.message.user {
    margin-left: auto;
    background: var(--user-bg);
    padding: 0.6rem 1rem;
    border-radius: 12px 12px 4px 12px;
}

.message.assistant {
    background: var(--agent-bg);
    padding: 0.6rem 1rem;
    border-radius: 12px 12px 12px 4px;
    border: 1px solid var(--border);
}

.message.assistant img {
    max-width: 100%;
    border-radius: 6px;
    margin: 0.5rem 0;
}

.message.error {
    color: var(--danger);
    font-size: 0.85rem;
}

/* Markdown inside messages */
.message.assistant p { margin-bottom: 0.5rem; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant pre {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem;
    overflow-x: auto;
    margin: 0.5rem 0;
    font-size: 0.85rem;
}
.message.assistant code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.85em;
}
.message.assistant :not(pre) > code {
    background: var(--bg-tertiary);
    padding: 0.15em 0.3em;
    border-radius: 4px;
}
.message.assistant ul, .message.assistant ol {
    padding-left: 1.5rem;
    margin: 0.4rem 0;
}
.message.assistant table {
    border-collapse: collapse;
    margin: 0.5rem 0;
    font-size: 0.85rem;
}
.message.assistant th, .message.assistant td {
    border: 1px solid var(--border);
    padding: 0.3rem 0.6rem;
}

.typing-indicator {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.85rem;
    padding: 0.4rem 0;
}

/* ── Input Area ─────────────────────────────────────────────────── */

.input-area {
    padding: 0.8rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.input-area textarea {
    flex: 1;
    padding: 0.6rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
    min-height: 40px;
    max-height: 200px;
}

.input-area textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.input-area #btn-send {
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.input-area #btn-send:hover { background: var(--accent-hover); }
.input-area #btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.attach-btn {
    padding: 0.5rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    min-width: 38px;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

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

/* ── Attachment Preview ────────────────────────────────────────── */

.attachment-preview {
    display: none;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.4rem 0;
}

.attachment-preview.visible {
    display: flex;
}

.attachment-thumb {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    max-width: 180px;
}

.attachment-thumb img {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
}

.attachment-thumb .att-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100px;
}

.attachment-thumb .att-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0 0.2rem;
    line-height: 1;
}

.attachment-thumb .att-remove:hover {
    color: var(--danger);
}

/* ── Drag-and-Drop Overlay ─────────────────────────────────────── */

.messages.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
}

/* ── User Attachments in Chat History ──────────────────────────── */

.user-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.4rem;
}

.user-attachments img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 6px;
    object-fit: contain;
}

.file-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.no-agent-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 1rem;
}

/* ── Cost Modal ─────────────────────────────────────────────────── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible { display: flex; }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    min-width: 300px;
    max-width: 400px;
}

.modal h2 {
    font-size: 1rem;
    margin-bottom: 1rem;
}

.modal .cost-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    font-size: 0.9rem;
}

.modal .cost-row .label { color: var(--text-secondary); }

.modal button {
    margin-top: 1rem;
    padding: 0.4rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85rem;
}

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

/* ── Mobile ─────────────────────────────────────────────────────── */

.sidebar-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0;
    margin-right: 0.5rem;
}

@media (max-width: 700px) {
    .sidebar {
        position: fixed;
        left: -220px;
        top: 0;
        bottom: 0;
        z-index: 50;
        transition: left 0.2s;
    }

    .sidebar.open { left: 0; }

    .sidebar-toggle { display: inline-block; }

    .message { max-width: 95%; }
}
