/* ITC WhatsApp Suite — PWA base styles */
:root {
    --bg: #f8fafc;
    --panel: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --accent: #16a34a;
    --accent-hover: #15803d;
    --danger: #dc2626;
    --bubble-in: #ffffff;
    --bubble-out: #d1fae5;
    --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
    --radius: 12px;
    --space: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.45;
}

body { display: flex; min-height: 100vh; min-height: 100dvh; }

a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; }

/* ── Login ───────────────────────────────────────────────────── */
body.login {
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 18% 12%, rgba(22, 163, 74, 0.18), transparent 34%),
        radial-gradient(circle at 82% 16%, rgba(56, 189, 248, 0.18), transparent 30%),
        linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
}
.login-shell { padding: 24px; width: 100%; max-width: 380px; }
.login-card {
    background: var(--panel);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.login-card input {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 11px 12px;
    font: inherit;
    background: #f1f5f9;
}
.login-card input:focus { outline: none; border-color: var(--accent); background: #fff; }
.login-card button {
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 10px;
    padding: 12px 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.login-card button:hover { background: var(--accent-hover); }
.login-card button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Authed layout ───────────────────────────────────────────── */
body.authed { display: flex; }

.sidebar {
    width: 320px;
    background: var(--panel);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    flex: 0 0 320px;
}
.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}
.sidebar-header form { margin: 4px 0 0; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; text-align: left; }

.filter-bar {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 1px solid var(--line);
}
.filter-bar input,
.filter-bar select {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 10px;
    background: #fff;
    font: inherit;
}

.conversation-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}
.conversation-list .empty {
    padding: 16px;
    color: var(--muted);
    text-align: center;
}
.conversation-list li.item {
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.conversation-list li.item:hover { background: #f1f5f9; }
.conversation-list li.item.active { background: #ecfdf5; }
.conversation-list .row1 { display: flex; justify-content: space-between; }
.conversation-list .row1 strong { font-weight: 600; }
.conversation-list .preview {
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.badge {
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 700;
    margin-left: 6px;
}
.status-chip {
    display: inline-block;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #e2e8f0;
    color: var(--ink);
    margin-left: 4px;
}
.status-chip.aguardando_humano { background: #fef3c7; color: #92400e; }
.status-chip.com_agente_ia { background: #dbeafe; color: #1e40af; }
.status-chip.com_atendente { background: #d1fae5; color: #065f46; }
.status-chip.nova { background: #fee2e2; color: #991b1b; }

/* ── Chat area ───────────────────────────────────────────────── */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}
.chat-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.chat-header {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.chat-header h2 { margin: 0; font-size: 16px; }
.chat-header .muted { margin: 2px 0 0; }
.chat-actions { display: flex; gap: 8px; }
.chat-actions button {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 12px;
    font: inherit;
    cursor: pointer;
}
.chat-actions button:hover { background: #f1f5f9; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f1f5f9;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 14px;
    background: var(--bubble-in);
    box-shadow: var(--shadow);
    word-wrap: break-word;
    white-space: pre-wrap;
}
.bubble.out {
    align-self: flex-end;
    background: var(--bubble-out);
}
.bubble.in {
    align-self: flex-start;
}
.bubble .meta { font-size: 10px; color: var(--muted); margin-top: 4px; }
.bubble.system { background: #fef9c3; align-self: center; font-size: 12px; }

.chat-form {
    border-top: 1px solid var(--line);
    padding: 10px 12px;
    display: flex;
    gap: 8px;
    background: var(--panel);
}
.chat-form textarea {
    flex: 1;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    resize: none;
    min-height: 38px;
    max-height: 140px;
}
.chat-form button {
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 10px;
    padding: 10px 18px;
    font-weight: 600;
    cursor: pointer;
}
.chat-form button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Install banner ─────────────────────────────────────────── */
.install-banner {
    position: fixed;
    bottom: 12px;
    left: 12px;
    right: 12px;
    background: #0f172a;
    color: #fff;
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.4);
    z-index: 1000;
}
.install-banner button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.install-banner button:last-child { background: transparent; color: #fff; font-size: 18px; padding: 0 8px; }

@media (max-width: 720px) {
    body.authed { flex-direction: column; }
    .sidebar { width: 100%; flex: 0 0 auto; max-height: 40vh; }
}