:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e8eaed;
    --text-dim: #9aa0ac;
    --accent: #4f8cff;
    --accent-dim: #274b8e;
    --danger: #e5534b;
    --success: #3fb950;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

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

.topbar {
    display: flex;
    align-items: center;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.brand { font-weight: 700; font-size: 18px; color: var(--text); }

.page { padding: 24px; max-width: 1100px; margin: 0 auto; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 9px 16px;
    font-size: 14px;
    cursor: pointer;
}

.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

input, textarea, select {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
}

label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--text-dim); }

.bot-list, .member-list, .broadcast-list, .command-list, .quickreply-list { list-style: none; padding: 0; margin: 0; }
.bot-list li, .member-list li, .broadcast-list li, .command-list li, .quickreply-list li {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 0; border-bottom: 1px solid var(--border);
}
.bot-list li:last-child, .member-list li:last-child, .broadcast-list li:last-child { border-bottom: none; }

.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-dim); }
.tag.owner { background: var(--accent-dim); color: #cfe0ff; }
.tag.pending { background: #4a3b1f; color: #ffcf7a; }

.nav-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.nav-tabs a { padding: 10px 14px; color: var(--text-dim); border-bottom: 2px solid transparent; }
.nav-tabs a.active { color: var(--text); border-color: var(--accent); }

.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 16px; height: calc(100vh - 160px); }
.conversation-list { overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.conversation-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.conversation-item:hover { background: var(--surface-2); }
.conversation-item.active { background: var(--accent-dim); }
.conversation-item .name { font-weight: 600; font-size: 14px; }
.conversation-item .preview { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-pill { font-size: 10px; padding: 1px 6px; border-radius: 999px; margin-left: 6px; }
.status-OPEN { background: #1f3d24; color: var(--success); }
.status-CLOSED { background: #3a2020; color: var(--danger); }
.status-SNOOZED { background: #3a3420; color: #e0c860; }

.thread { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.thread-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.thread-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 70%; padding: 8px 12px; border-radius: 12px; font-size: 14px; line-height: 1.4; }
.bubble.IN { align-self: flex-start; background: var(--surface-2); }
.bubble.OUT { align-self: flex-end; background: var(--accent-dim); }
.bubble .meta { font-size: 10px; color: var(--text-dim); margin-top: 4px; }
.thread-reply { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; position: relative; }
.thread-reply textarea { resize: none; height: 44px; }
.quick-reply-menu { position: absolute; bottom: 60px; left: 12px; right: 90px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); max-height: 160px; overflow-y: auto; display: none; }
.quick-reply-menu.open { display: block; }
.quick-reply-menu div { padding: 8px 12px; cursor: pointer; font-size: 13px; }
.quick-reply-menu div:hover { background: var(--surface); }

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

.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

.empty-state { color: var(--text-dim); padding: 40px; text-align: center; }

.btn-back { display: none; }

@media (max-width: 768px) {
    .page { padding: 16px; }
    .topbar { padding: 12px 16px; }

    .form-row { flex-direction: column; gap: 0; }

    .nav-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
    .nav-tabs a { white-space: nowrap; }

    /* Inbox becomes a single pane that drill-downs from the conversation list into the thread,
       rather than the two-column desktop layout - there's no room for both side by side. */
    .inbox { grid-template-columns: 1fr; height: calc(100vh - 120px); }
    .inbox .conversation-list { display: block; }
    .inbox .thread { display: none; }
    .inbox.conversation-open .conversation-list { display: none; }
    .inbox.conversation-open .thread { display: flex; }
    .btn-back { display: inline-block; }

    .quick-reply-menu { left: 12px; right: 12px; }

    /* Label + action-buttons rows (bot list, team members, commands, quick replies, broadcasts)
       stack instead of squeezing everything onto one line. */
    .bot-list li, .member-list li, .broadcast-list li, .command-list li, .quickreply-list li {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .bot-list li > div:last-child {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
}
