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

html, body {
    height: 100%;
    background: #0d0d0d;
    color: #e8e8e8;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

.screen {
    display: flex;
    flex-direction: column;
    height: 100dvh;
}

.hidden { display: none !important; }

/* Login */
#login-screen {
    align-items: center;
    justify-content: center;
    padding: 24px;
}
#login-form {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#login-form h1 {
    text-align: center;
    margin-bottom: 24px;
    font-weight: 600;
    letter-spacing: -0.5px;
}
#login-form input,
#login-form button {
    padding: 14px 16px;
    font-size: 16px;
    border-radius: 10px;
    border: 1px solid #2a2a2a;
    background: #1a1a1a;
    color: #fff;
}
#login-form button {
    background: #4a8fee;
    border: none;
    cursor: pointer;
    font-weight: 600;
}
.error { color: #ff6b6b; font-size: 14px; min-height: 18px; }

/* Header */
#chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid #1f1f1f;
    background: #0d0d0d;
    padding-top: max(10px, env(safe-area-inset-top));
}
#chat-header button {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 6px 10px;
}
#chat-title {
    font-weight: 600;
    flex: 1;
    text-align: center;
    font-size: 15px;
    color: #aaa;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Drawer */
#drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
}
#drawer {
    position: fixed;
    top: 0; left: 0;
    bottom: 0;
    width: 80%;
    max-width: 320px;
    background: #141414;
    border-right: 1px solid #2a2a2a;
    z-index: 10;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    padding-top: env(safe-area-inset-top);
}
#drawer.hidden { display: none !important; }
#drawer-overlay.hidden { display: none !important; }

#drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px;
    border-bottom: 1px solid #2a2a2a;
}
#drawer-header h2 { font-size: 16px; }
#drawer-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
}
#chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.chat-item {
    padding: 12px 14px;
    border-radius: 8px;
    cursor: pointer;
    color: #ddd;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.chat-item:hover { background: #1f1f1f; }
.chat-item.active { background: #232a3a; color: #fff; }
.chat-item .delete-btn {
    background: transparent;
    border: none;
    color: #666;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    opacity: 0;
    transition: opacity 0.15s;
}
.chat-item:hover .delete-btn,
.chat-item.active .delete-btn {
    opacity: 1;
}
.chat-item .delete-btn:hover { color: #ff6b6b; }

/* Chat */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 24px;
}
.msg {
    max-width: 85%;
    padding: 12px 14px;
    border-radius: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.msg.user {
    align-self: flex-end;
    background: #4a8fee;
    color: #fff;
}
.msg.assistant {
    align-self: flex-start;
    background: #1f1f1f;
}
.msg.tool {
    align-self: stretch;
    background: #161616;
    border-left: 3px solid #5a5a5a;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 13px;
    padding: 10px 12px;
    border-radius: 6px;
    color: #999;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow-y: auto;
}

.approval {
    align-self: stretch;
    background: #2a1f0a;
    border: 1px solid #5a4a1a;
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.approval .tool-name { font-weight: 600; color: #ffb84a; }
.approval pre {
    background: #0d0d0d;
    padding: 8px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 13px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.approval .actions { display: flex; gap: 8px; }
.approval button {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.approval button.approve { background: #4caf50; color: #fff; }
.approval button.deny { background: #444; color: #fff; }

/* Input */
#input-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid #1f1f1f;
    background: #0d0d0d;
}
#input {
    flex: 1;
    padding: 12px 14px;
    border-radius: 22px;
    border: 1px solid #2a2a2a;
    background: #1a1a1a;
    color: #fff;
    font-size: 16px;
    resize: none;
    max-height: 120px;
    font-family: inherit;
}
#input-form button {
    width: 44px;
    height: 44px;
    border-radius: 22px;
    border: none;
    background: #4a8fee;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
}
