:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-2: #f3f4f7;
    --surface-3: #e8eaef;
    --text: #1d2433;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --primary: #4a154b;
    --primary-contrast: #ffffff;
    --accent: #36c5f0;
    --success: #2eb67d;
    --warning: #ecb22e;
    --danger: #e01e5a;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 12px rgba(16, 24, 40, .06);
    --radius: 10px;
}

[data-theme="dark"] {
    --bg: #0f1419;
    --surface: #181d25;
    --surface-2: #222831;
    --surface-3: #2c333d;
    --text: #e7e9ee;
    --text-muted: #9aa0a6;
    --border: #2c333d;
    --primary: #b388eb;
    --primary-contrast: #1a1024;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 16px rgba(0,0,0,.45);
}

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

/* ============ Layout principal ============ */
/* Container com largura controlada para não esticar em monitor wide */
.app-container {
    max-width: 1480px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem;
}

/* ============ Header ============ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
}
.app-header-left { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.app-header-left h3 { margin: 0; font-size: 1.35rem; font-weight: 600; }
.app-header-actions { display: flex; align-items: center; gap: .5rem; }

.workspace-pill {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .3rem .65rem; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text-muted); font-size: .8rem;
}
.workspace-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.workspace-pill strong { color: var(--text); font-weight: 600; }

.user-chip {
    display: inline-flex; align-items: center; gap: .35rem;
    color: var(--text-muted); font-size: .85rem;
    padding: .25rem .5rem; border-radius: 6px;
}

/* ============ Cards ============ */
.app-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.app-card .card-header {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
    padding: .65rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}
.app-card .card-header .header-title {
    display: inline-flex; align-items: center; gap: .5rem;
}

.btn-primary {
    background: var(--primary); border-color: var(--primary); color: var(--primary-contrast);
}
.btn-primary:hover, .btn-primary:focus {
    filter: brightness(1.1); background: var(--primary); border-color: var(--primary); color: var(--primary-contrast);
}

/* ============ Listas (destinatários / excluídos) ============ */
.scroll-box {
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}
.scroll-box-tall   { max-height: calc(100vh - 380px); min-height: 280px; }
.scroll-box-short  { max-height: 220px; min-height: 120px; }

.user-row {
    display: flex; align-items: center; gap: .75rem;
    padding: .5rem .75rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    transition: background-color .15s;
    margin: 0;
}
.user-row:last-child { border-bottom: none; }
.user-row:hover { background: var(--surface-2); }
.user-row .avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--surface-3);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--text);
    font-size: .85rem;
}
.user-row .meta { flex: 1; min-width: 0; }
.user-row .meta .name { font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-row .meta .sub  { font-size: .78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-row .badge-tag {
    font-size: .68rem; padding: .15rem .4rem; border-radius: 999px;
    background: var(--surface-2); color: var(--text-muted);
    flex-shrink: 0;
}

.empty-state { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 2rem; opacity: .35; margin-bottom: .5rem; display: block; }

/* ============ Editor ============ */
.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .15rem;
    padding: .35rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-bottom: none;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    align-items: center;
}
.editor-toolbar button {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text);
    padding: .25rem .5rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: .85rem;
    line-height: 1;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.editor-toolbar button.var-btn {
    font-size: .72rem; padding: .15rem .4rem; height: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-family: monospace;
}
.editor-toolbar button:hover { background: var(--surface); border-color: var(--border); }
.editor-toolbar .toolbar-sep { width: 1px; height: 18px; background: var(--border); margin: 0 .25rem; }

.editor-area {
    width: 100%;
    min-height: 280px;
    resize: vertical;
    padding: .75rem;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: .92rem;
    line-height: 1.5;
}
.editor-area:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* Quando preview está ao lado, ambos têm mesma altura */
.editor-pane,
.preview-pane {
    min-height: 320px;
    display: flex;
    flex-direction: column;
}
.editor-pane .editor-area { flex: 1; }

.preview-pane {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    font-family: "Slack-Lato", -apple-system, "Segoe UI", sans-serif;
    font-size: .95rem;
    overflow-y: auto;
}
.preview-pane .slack-msg-header {
    display: flex; align-items: center; gap: .5rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: .75rem;
}
.preview-pane .slack-msg-header .av {
    width: 32px; height: 32px; border-radius: 6px;
    background: var(--primary); color: var(--primary-contrast);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.preview-pane code { background: var(--surface-2); padding: .1rem .3rem; border-radius: 4px; font-size: .85em; }
.preview-pane blockquote { border-left: 3px solid var(--border); padding-left: .75rem; color: var(--text-muted); margin: .5rem 0; }
.preview-pane .slack-block-button {
    display: inline-block; padding: .35rem .9rem; margin: .25rem .25rem 0 0;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
    font-size: .85rem; color: var(--text);
}
.preview-pane .slack-divider { border: none; border-top: 1px solid var(--border); margin: .75rem 0; }
.preview-pane h1, .preview-pane h2 { font-size: 1.05rem; font-weight: 700; margin: .5rem 0 .25rem; }

.preview-empty {
    color: var(--text-muted);
    font-style: italic;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
}

.char-counter { font-size: .75rem; color: var(--text-muted); }
.char-counter.warn { color: var(--warning); }
.char-counter.over { color: var(--danger); font-weight: 600; }

/* ============ Tabs ============ */
.tab-pill {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .3rem .75rem; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text-muted); cursor: pointer; font-size: .8rem;
    transition: all .15s;
}
.tab-pill:hover { color: var(--text); }
.tab-pill.active {
    background: var(--primary); border-color: var(--primary); color: var(--primary-contrast);
}

/* ============ Bloco de envio ============ */
.send-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    margin-top: 1rem;
}

.live-log {
    max-height: 180px; overflow-y: auto;
    background: var(--surface-2);
    border-radius: 6px;
    padding: .5rem .75rem;
    margin-top: .5rem;
}
.live-log > div {
    font-size: .8rem;
    padding: .15rem 0;
    border-bottom: 1px solid var(--border);
}
.live-log > div:last-child { border-bottom: none; }

/* ============ Tema toggle ============ */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 34px; height: 34px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text);
    padding: 0;
}
.theme-toggle:hover { background: var(--surface-2); }

/* ============ Tela de login ============ */
.login-screen {
    position: fixed; inset: 0;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    z-index: 2000;
}
.login-card {
    width: 100%; max-width: 400px;
    padding: 2rem;
}
.login-card h4 { color: var(--text); }
.login-card code {
    background: var(--surface-2); padding: .1rem .35rem;
    border-radius: 4px; font-size: .85em; color: var(--text);
}

/* ============ Status alert ============ */
#statusAlert { margin-bottom: 1rem; }

/* ============ Compactações específicas ============ */
.search-input { font-size: .85rem; }

/* Responsivo: em telas menores que 1200px, encolhe um pouco */
@media (max-width: 1199.98px) {
    .app-container { padding: 1rem; }
    .editor-pane, .preview-pane { min-height: 280px; }
}

/* Mobile: editor e preview empilham; ajustes de header */
@media (max-width: 991.98px) {
    .app-container { padding: .75rem; }
    .scroll-box-tall { max-height: 320px; }
    .app-header { flex-direction: column; align-items: stretch; }
    .app-header-left, .app-header-actions { justify-content: space-between; }
}
