:root {
    --bg: #1a1a2e;
    --bg2: #16213e;
    --bg-user: #0f3460;
    --bg-agent: #252540;
    --text: #e0e0e0;
    --text2: #8888aa;
    --accent: #4e9af1;
    --green: #00c853;
    --border: #333355;
}

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

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

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

/* Tabs */
#tabs {
    display: flex;
    overflow-x: auto;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 8px 4px;
    gap: 4px;
    flex-shrink: 0;
    scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }

.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 12px;
    border-radius: 12px;
    cursor: pointer;
    white-space: nowrap;
    min-width: 64px;
    transition: background 0.2s;
    font-size: 11px;
    color: var(--text2);
    position: relative;
}
.tab:hover { background: rgba(255,255,255,0.05); }
.tab.active { background: var(--bg-user); color: var(--text); }
.tab .emoji { font-size: 20px; margin-bottom: 2px; }
.tab .badge {
    position: absolute;
    top: 2px;
    right: 6px;
    width: 8px;
    height: 8px;
    background: var(--green);
    border-radius: 50%;
    display: none;
}

/* Chat area */
#chat {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
    height: 100%;
}

#messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.msg.user {
    align-self: flex-end;
    background: var(--bg-user);
    border-bottom-right-radius: 4px;
}
.msg.agent {
    align-self: flex-start;
    background: var(--bg-agent);
    border-bottom-left-radius: 4px;
}
.msg .agent-badge {
    font-size: 11px;
    color: var(--accent);
    margin-bottom: 4px;
    display: block;
}
.msg .time {
    font-size: 10px;
    color: var(--text2);
    margin-top: 4px;
    text-align: right;
}

.msg img {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 6px;
}

.msg a {
    color: var(--accent);
    text-decoration: none;
}

/* Typing indicator */
.typing {
    align-self: flex-start;
    padding: 10px 14px;
    background: var(--bg-agent);
    border-radius: 16px;
    font-size: 14px;
    color: var(--text2);
}
.typing .dots span {
    animation: blink 1.4s infinite;
    font-size: 18px;
}
.typing .dots span:nth-child(2) { animation-delay: 0.2s; }
.typing .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,60%,100% { opacity: 0.2; } 30% { opacity: 1; } }

/* Input */
#input-bar {
    display: flex;
    align-items: flex-end;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: var(--bg2);
    border-top: 1px solid var(--border);
    gap: 8px;
}

#msg-input {
    flex-grow: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    color: var(--text);
    font-size: 15px;
    resize: none;
    max-height: 120px;
    outline: none;
    font-family: inherit;
}
#msg-input:focus { border-color: var(--accent); }
#msg-input::placeholder { color: var(--text2); }

#attach-btn, #send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
#attach-btn { background: transparent; }
#send-btn { background: var(--accent); color: white; }
#send-btn:disabled { opacity: 0.4; }

/* Welcome screen */
#welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px 20px;
    text-align: center;
}
#welcome h2 { color: var(--text); font-size: 18px; }
#welcome p { color: var(--text2); font-size: 14px; }

/* Keyboard dismiss button */
#dismiss-kb {
    display: none;
    text-align: center;
    padding: 8px;
    background: var(--bg2);
    color: var(--text2);
    font-size: 13px;
    cursor: pointer;
    border-top: 1px solid var(--border);
}

/* Image actions */
.img-wrap {
    margin-top: 6px;
}
.img-wrap img {
    border-radius: 8px;
    max-width: 100%;
    display: block;
}
.img-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}
.img-btn {
    padding: 6px 12px;
    background: var(--bg-user);
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
    font-size: 12px;
}

/* Context menu */
#context-menu {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    background: #2a2a45;
    border-radius: 12px;
    padding: 4px 0;
    z-index: 9999;
    min-width: 180px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.ctx-item {
    padding: 12px 20px;
    font-size: 15px;
    color: #e0e0e0;
    cursor: pointer;
}
.ctx-item:active {
    background: rgba(255,255,255,0.1);
}

/* Prevent text selection on long press */
.msg {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
