:root {
    --wa-primary: #25d366;
    --wa-primary-dark: #128c7e;
    --wa-bg: #efeae2;
    --wa-in: #ffffff;
    --wa-out: #d9fdd3;
    --wa-sidebar: #f7f8fa;
    --wa-border: #e6e8ec;
    --wa-text: #1f2a30;
    --wa-muted: #667781;
}

html, body { height: 100%; }
body { background: #f0f2f5; }

/* ===== App shell (sidebar à esquerda) ===== */
.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}
.app-sidebar {
    background: #fff;
    border-right: 1px solid var(--wa-border);
    position: sticky; top: 0;
    height: 100vh;
    display: flex; flex-direction: column;
}
.app-sidebar .brand {
    font-size: 18px; font-weight: 600;
    padding: 16px 18px;
    border-bottom: 1px solid #f0f2f5;
}
.app-sidebar .menu { flex: 1; padding: 8px; overflow-y: auto; }
.app-sidebar .menu a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px;
    color: var(--wa-text); text-decoration: none; font-size: 14px;
}
.app-sidebar .menu a:hover { background: #f3f4f6; }
.app-sidebar .menu a.active { background: #e7f7ee; color: var(--wa-primary-dark); font-weight: 600; }
.app-sidebar .menu hr { border: 0; border-top: 1px solid var(--wa-border); margin: 8px 4px; }
.app-sidebar .user-block {
    padding: 14px;
    border-top: 1px solid var(--wa-border);
    background: #fafbfc;
    display: flex; align-items: center; gap: 10px;
}
.app-sidebar .user-block .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--wa-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; flex-shrink: 0;
}
.app-main { padding: 24px; min-width: 0; }

/* ===== Status pills ===== */
.status-pill {
    display: inline-block;
    padding: 2px 10px; border-radius: 999px;
    font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600;
}
.status-connected, .status-open    { background: #d1f7da; color: #1d7a3a; }
.status-qr_pending, .status-pending{ background: #fff4d6; color: #9a6b00; }
.status-disconnected, .status-closed { background: #e9ecef; color: #67737a; }

/* ===================================================================
   INBOX (split-view tipo WhatsApp Web)
   =================================================================== */
.page-inbox .app-main {
    padding: 0;
    height: 100vh;
    overflow: hidden;
}

.wa-inbox {
    display: grid;
    grid-template-columns: 360px 1fr;
    height: 100vh;
    background: #fff;
}

/* Painel esquerdo — lista de tickets */
.wa-tickets-pane {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid var(--wa-border);
    min-width: 0;
}
.wa-tickets-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--wa-border);
    background: #f7f8fa;
}
.wa-status-tabs .nav-link {
    padding: 6px 8px;
    font-size: 13px;
    color: var(--wa-muted);
    border-radius: 8px;
}
.wa-status-tabs .nav-link.active {
    background: var(--wa-primary);
    color: #fff;
}

.wa-ticket-list {
    list-style: none; padding: 0; margin: 0;
    flex: 1; overflow-y: auto;
}
.wa-ticket-item {
    display: flex; align-items: stretch;
    border-bottom: 1px solid #f0f2f5;
    transition: background .15s;
    position: relative;
}
.wa-ticket-item:hover { background: #fafbfc; }
.wa-ticket-item.is-active { background: #e7f7ee; }
.wa-ticket-item.is-active::before {
    content: '';
    position: absolute; left: 0; top: 0; bottom: 0;
    width: 3px; background: var(--wa-primary);
}
.wa-ticket-link {
    flex: 1; min-width: 0;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    color: inherit; text-decoration: none;
}
.wa-ticket-action {
    padding: 12px 14px 12px 0;
    display: flex; align-items: center;
}
.wa-ticket-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--wa-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px;
    flex-shrink: 0; text-transform: uppercase;
}
.wa-ticket-body { flex: 1; min-width: 0; }
.wa-ticket-row {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.wa-ticket-name {
    font-weight: 600; color: var(--wa-text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wa-ticket-time { color: var(--wa-muted); font-size: 12px; flex-shrink: 0; }
.wa-ticket-meta { margin-top: 2px; }
.wa-ticket-meta small {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 100%;
}
.wa-ticket-preview {
    color: var(--wa-muted); font-size: 13px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 2px;
}
.badge-unread {
    background: var(--wa-primary); color: #fff;
    border-radius: 999px; padding: 0 8px;
    font-size: 11px; line-height: 18px;
    min-width: 20px; text-align: center;
    flex-shrink: 0;
}
.wa-ticket-empty {
    padding: 64px 24px;
    text-align: center;
    color: var(--wa-muted);
}

/* Painel direito — chat ou empty state */
.wa-chat-pane {
    display: flex; flex-direction: column;
    background: var(--wa-bg);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'><circle cx='2' cy='2' r='1' fill='%23dcd6cb'/></svg>");
    min-width: 0;
}
.wa-chat-empty {
    flex: 1;
    display: flex; align-items: center; justify-content: center;
    background: #f7f8fa;
}

/* Chat dentro do split-view */
.chat-screen {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
}
.chat-header {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px;
    background: #fff;
    border-bottom: 1px solid var(--wa-border);
}
.chat-header .info { flex: 1; line-height: 1.2; min-width: 0; }
.chat-header .info strong { display: block; }
.chat-header .info small { color: var(--wa-muted); }
.chat-header .actions {
    display: flex; gap: 6px; align-items: center;
    flex-shrink: 0;
}

.chat-body {
    padding: 18px;
    overflow-y: auto;
    display: flex; flex-direction: column;
    gap: 4px;
}
.chat-empty { margin: auto; color: var(--wa-muted); }

.msg {
    max-width: 70%;
    padding: 6px 10px 6px 12px;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0,0,0,.06);
    font-size: 14px;
    word-wrap: break-word;
}
.msg-in { background: var(--wa-in); align-self: flex-start; border-top-left-radius: 0; }
.msg-out { background: var(--wa-out); align-self: flex-end; border-top-right-radius: 0; }
.msg-text { white-space: pre-wrap; }
.msg-img { max-width: 280px; max-height: 280px; border-radius: 6px; display: block; }
.msg-video { max-width: 320px; border-radius: 6px; display: block; }
.msg-doc {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 10px; background: rgba(0,0,0,.05); border-radius: 6px;
    color: inherit; text-decoration: none;
}
.msg-meta {
    display: flex; justify-content: flex-end; gap: 4px;
    color: var(--wa-muted); font-size: 11px; margin-top: 2px;
}

.chat-composer {
    display: flex; gap: 8px; align-items: flex-end;
    padding: 10px 16px;
    background: #fff;
    border-top: 1px solid var(--wa-border);
}
.chat-composer textarea {
    flex: 1; resize: none;
    padding: 10px 14px;
    border: 1px solid var(--wa-border); border-radius: 20px;
    font-size: 14px; background: #f8f9fa;
    max-height: 140px; min-height: 40px;
}
.chat-composer .attach-btn {
    cursor: pointer; padding: 8px 10px; font-size: 18px;
    color: var(--wa-muted); user-select: none;
}
.chat-composer-disabled {
    padding: 18px;
    background: #fff;
    border-top: 1px solid var(--wa-border);
    text-align: center;
    color: var(--wa-muted);
}

/* ===== Login ===== */
.page-login {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    padding: 24px;
}
.page-login .login-card {
    width: 100%; max-width: 420px;
    background: #fff; border-radius: 14px;
    padding: 32px; box-shadow: 0 24px 60px rgba(0,0,0,.18);
}

/* ===== QR pair ===== */
.pair-qr img { max-width: 320px; width: 100%; height: auto; display: block; margin: 0 auto; }
.pair-qr pre { font-size: 11px; max-height: 360px; overflow: auto; }

/* ===== Avatar genérico (usado fora do inbox também) ===== */
.ticket-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--wa-primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px;
    flex-shrink: 0; text-transform: uppercase;
}

/* ===== Responsivo: sidebar colapsada em telas médias ===== */
@media (max-width: 1100px) {
    .app-shell { grid-template-columns: 64px 1fr; }
    .app-sidebar .brand { font-size: 0; padding: 16px; text-align: center; }
    .app-sidebar .brand::before { content: '💬'; font-size: 22px; }
    .app-sidebar .menu a { justify-content: center; padding: 12px 8px; gap: 0; font-size: 0; }
    .app-sidebar .menu a i { font-size: 18px; }
    .app-sidebar .user-block { flex-direction: column; gap: 6px; padding: 8px; }
    .app-sidebar .user-block > div:nth-child(2) { display: none; }
}

@media (max-width: 800px) {
    .app-shell { grid-template-columns: 1fr; }
    .app-sidebar {
        position: fixed; bottom: 0; left: 0; right: 0; top: auto;
        height: 56px; flex-direction: row; z-index: 100;
        border-right: none; border-top: 1px solid var(--wa-border);
    }
    .app-sidebar .brand, .app-sidebar .user-block { display: none; }
    .app-sidebar .menu { flex-direction: row; padding: 4px; overflow-x: auto; }
    .app-main { padding: 16px; padding-bottom: 72px; }
    .page-inbox .app-main { padding: 0; }

    .wa-inbox { grid-template-columns: 1fr; height: calc(100vh - 56px); }
    .chat-screen { height: calc(100vh - 56px); }
    .page-inbox:not(.has-ticket) .wa-chat-pane { display: none; }
    .page-inbox.has-ticket .wa-tickets-pane { display: none; }
}
