:root {
    /* Paleta da logo Atendia: teal #0D9488, escuro #0F766E, claro #5EEAD4 */
    --brand: #0d9488;
    --brand-dark: #0f766e;
    --brand-light: #5eead4;
    --brand-subtle: #ccfbf1;
    --brand-grad: linear-gradient(135deg, #14b8a6 0%, #0f766e 100%);
    --sidebar-bg: #ffffff;
    --sidebar-bg2: #ffffff;
    --sidebar-text: #4b5563;
    --sidebar-active: #0d9488;
    --content-bg: #f4f6fb;
    --card-shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
    --radius: 12px;
}

/* ---------- Tema escuro ----------
   Ardósia, não preto: o fundo mais escuro é #1c222c, e as superfícies (cards, sidebar,
   topbar) ficam um degrau acima para continuarem legíveis. O Bootstrap 5.3 recolore os
   próprios componentes sozinho a partir do data-bs-theme; aqui só ajustamos os tokens
   do app e as classes utilitárias que assumem fundo claro. */
[data-bs-theme="dark"] {
    --brand-subtle: #134e4a;
    --sidebar-bg: #232b38;
    --sidebar-bg2: #232b38;
    --sidebar-text: #cbd5e1;
    --content-bg: #1c222c;
    --surface: #272f3d;
    --border-soft: #38414f;
    --card-shadow: 0 1px 3px rgba(0,0,0,.35), 0 1px 2px rgba(0,0,0,.25);

    /* Tokens do próprio Bootstrap, para o cinza dele não puxar para o preto. */
    --bs-body-bg: #1c222c;
    --bs-body-color: #e2e8f0;
    --bs-emphasis-color: #f1f5f9;
    --bs-secondary-bg: #272f3d;
    --bs-tertiary-bg: #2f3847;
    --bs-border-color: #38414f;
}

html, body {
    font-family: 'Inter', 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background: var(--content-bg);
    color: #1f2937;
}
[data-bs-theme="dark"] body { color: #e2e8f0; }

/* Utilitários do Bootstrap que fixam fundo claro e apareceriam como manchas brancas. */
[data-bs-theme="dark"] .bg-white { background-color: var(--surface) !important; }
[data-bs-theme="dark"] .bg-light { background-color: var(--bs-tertiary-bg) !important; }
[data-bs-theme="dark"] .text-dark { color: #e2e8f0 !important; }
[data-bs-theme="dark"] .text-muted { color: #9aa7b8 !important; }
[data-bs-theme="dark"] .border,
[data-bs-theme="dark"] .border-top,
[data-bs-theme="dark"] .border-bottom,
[data-bs-theme="dark"] .border-start,
[data-bs-theme="dark"] .border-end { border-color: var(--border-soft) !important; }

a, .btn-link { color: var(--brand-dark); text-decoration: none; }
a:hover { color: var(--brand); }

h1:focus { outline: none; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: 248px;
    background: var(--sidebar-bg);
    border-right: 1px solid #e6e9f0;
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    position: fixed; top: 0; bottom: 0; left: 0;
    overflow-y: auto;
    transition: transform .2s ease;
    z-index: 100;
}
body.sidebar-collapsed .app-sidebar { transform: translateX(-248px); }
body.sidebar-collapsed .app-main { margin-left: 0; }

.app-main { flex: 1; margin-left: 248px; display: flex; flex-direction: column; transition: margin .2s ease; }

.app-topbar {
    height: 60px; background: #fff; border-bottom: 1px solid #e6e9f0;
    display: flex; align-items: center; gap: 16px; padding: 0 24px;
    position: sticky; top: 0; z-index: 50;
}
.sidebar-toggle { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: #6b7280; }
.topbar-title { font-weight: 600; font-size: 1.1rem; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%; background: var(--brand-grad);
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.user-info { line-height: 1.15; }
.user-name { font-weight: 600; font-size: .9rem; }
.user-role { font-size: .72rem; color: #9ca3af; }
.btn-logout { background: none; border: 1px solid #e6e9f0; border-radius: 6px; font-size: .85rem; padding: 4px 10px; color: #9ca3af; cursor: pointer; margin-left: 12px; white-space: nowrap; }
.btn-logout:hover { color: #ef4444; border-color: #ef4444; }

.app-content { padding: 24px; flex: 1; }

/* Superfícies do shell com cor fixa no tema claro. */
[data-bs-theme="dark"] .app-sidebar { border-right-color: var(--border-soft); }
[data-bs-theme="dark"] .app-topbar { background: var(--surface); border-bottom-color: var(--border-soft); }
[data-bs-theme="dark"] .nav-brand { border-bottom-color: var(--border-soft); }
[data-bs-theme="dark"] .nav-item:hover { background: #2f3847; color: #f1f5f9; }
[data-bs-theme="dark"] .nav-item.active { background: #14343a; color: var(--brand-light); }
[data-bs-theme="dark"] .nav-item.active .nav-icon { color: var(--brand-light); }
[data-bs-theme="dark"] .btn-logout { border-color: var(--border-soft); }
[data-bs-theme="dark"] .spinner { border-color: var(--border-soft); border-top-color: var(--brand); }
[data-bs-theme="dark"] a, [data-bs-theme="dark"] .btn-link { color: var(--brand-light); }
[data-bs-theme="dark"] a:hover { color: #99f6e4; }

/* Botão de tema na topbar (mesmo peso visual do sino). */
.theme-toggle {
    background: none; border: none; cursor: pointer; color: #6b7280;
    font-size: 1.15rem; line-height: 1; padding: 6px 8px; border-radius: 8px;
}
.theme-toggle:hover { background: var(--bs-tertiary-bg, #f1f5f9); color: var(--brand-dark); }
[data-bs-theme="dark"] .theme-toggle { color: #cbd5e1; }
[data-bs-theme="dark"] .theme-toggle:hover { color: var(--brand-light); }

.impersonation-bar {
    background: #b45309; color: #fff; padding: 8px 16px; font-size: .9rem;
    display: flex; align-items: center; gap: 6px;
}

.app-loading { display: flex; align-items: center; justify-content: center; height: 100vh; }
.spinner {
    width: 42px; height: 42px; border: 4px solid #e6e9f0; border-top-color: var(--brand);
    border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Sidebar nav ---------- */
.nav-brand {
    display: flex; align-items: center; gap: 10px; padding: 20px 22px; color: var(--brand-dark);
    font-size: 1.25rem; font-weight: 700; border-bottom: 1px solid #eef1f6;
}
.brand-logo { font-size: 1.4rem; display: flex; align-items: center; }
/* Logo Atendia: o SVG tem respiro interno, margens negativas compensam. */
.brand-img { height: 64px; margin: -12px 0 -12px -16px; }
.login-brand { height: 96px; margin: -18px 0 -14px; }
.nav-sections { padding: 16px 14px; }
.nav-group { margin-bottom: 24px; }
.nav-group:last-child { margin-bottom: 8px; }
.nav-group-title {
    font-size: .66rem; text-transform: uppercase; letter-spacing: .1em;
    color: #9ca3af; padding: 0 12px 8px; font-weight: 600;
}
/* Seções recolhíveis: o título vira botão. Reaproveita a aparência do .nav-group-title. */
button.nav-group-title {
    display: flex; align-items: center; gap: 6px; width: 100%;
    background: none; border: 0; text-align: left; cursor: pointer;
}
button.nav-group-title:hover { color: #6b7280; }
.nav-group-caret {
    margin-left: auto; font-size: .7rem; transition: transform .15s;
}
.nav-group.collapsed .nav-group-caret { transform: rotate(-90deg); }
/* Recolhida ocupa menos espaço vertical que uma seção aberta. */
.nav-group.collapsed { margin-bottom: 6px; }
.nav-group.collapsed button.nav-group-title { padding-bottom: 0; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin: 1px 0;
    border-radius: 8px; color: var(--sidebar-text); font-size: .9rem; cursor: pointer;
    line-height: 1.2;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: #f2faf8; color: #111827; }
.nav-item.active { background: #e3f5f2; color: var(--brand-dark); font-weight: 600; }
.nav-icon { width: 22px; text-align: center; font-size: 1.05rem; display: flex; align-items: center; justify-content: center; }
.nav-item.active .nav-icon { color: var(--brand-dark); }
.nav-label { flex: 1; }
.nav-count-badge {
    background: #dc3545; color: #fff; font-size: .68rem; font-weight: 700;
    min-width: 19px; height: 19px; line-height: 19px; text-align: center;
    border-radius: 10px; padding: 0 5px;
}

/* ---------- Buttons ---------- */
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn { border-radius: 8px; }
.btn:focus, .form-control:focus, .form-select:focus, .form-check-input:focus {
    box-shadow: 0 0 0 .2rem rgba(13,148,136,.2);
    border-color: var(--brand);
}
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }

/* Reaponta as utilitárias "primary" do Bootstrap para o teal da marca. */
.text-primary { color: var(--brand) !important; }
.bg-primary { background-color: var(--brand) !important; }
.bg-primary-subtle { background-color: var(--brand-subtle) !important; }
.text-primary-emphasis { color: #115e59 !important; }
.border-primary { border-color: var(--brand) !important; }
.text-bg-primary { background-color: var(--brand) !important; color: #fff !important; }
.btn-outline-primary { color: var(--brand); border-color: var(--brand); }
.btn-outline-primary:hover, .btn-outline-primary:active, .btn-outline-primary.active {
    background-color: var(--brand); border-color: var(--brand); color: #fff;
}
.progress-bar { background-color: var(--brand); }
.spinner-border.text-primary { color: var(--brand) !important; }

/* ---------- Cards / tables ---------- */
.card { border: 1px solid #e9edf5; border-radius: var(--radius); box-shadow: var(--card-shadow); }
.table { --bs-table-hover-bg: #f0faf8; }
.table > thead th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; border-bottom: 2px solid #eef1f6; }
.modal-content { border: none; border-radius: 14px; box-shadow: 0 20px 50px rgba(16,24,40,.2); }
.form-control, .form-select { border-radius: 8px; border-color: #d8dee9; }
.badge { font-weight: 600; }

h4 { font-weight: 700; }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--brand-grad); padding: 20px;
}
.login-card {
    background: #fff; border-radius: 18px; box-shadow: 0 24px 60px rgba(0,0,0,.25);
    width: 100%; max-width: 400px; padding: 40px 36px;
}
[data-bs-theme="dark"] .login-card { background: var(--surface); }
/* A logo tem o texto "atend" em ardósia escura, que some no fundo escuro:
   troca pela variante de texto claro (o ícone teal é o mesmo nas duas). */
[data-bs-theme="dark"] .brand-img,
[data-bs-theme="dark"] .login-brand { content: url("atendia-dark.svg"); }
.login-logo { text-align: center; font-size: 2.6rem; margin-bottom: 6px; }
.login-title { text-align: center; font-weight: 700; font-size: 1.5rem; margin-bottom: 2px; }
.login-sub { text-align: center; color: #9ca3af; font-size: .9rem; margin-bottom: 26px; }

/* Cartões, tabelas e a lista do inbox no escuro. */
[data-bs-theme="dark"] .card { border-color: var(--border-soft); }
[data-bs-theme="dark"] .table { --bs-table-hover-bg: #2f3847; }
[data-bs-theme="dark"] .table > thead th { color: #9aa7b8; border-bottom-color: var(--border-soft); }
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select { border-color: var(--border-soft); }

/* ---------- Inbox: lista de conversas ----------
   Tokens próprios para os dois temas; o resto da folha usa só estes nomes. */
:root {
    --inbox-canvas: #eef1f5;
    --inbox-surface: #ffffff;
    --inbox-raised: #eef2f7;
    --inbox-line: #e6e9f0;
    --inbox-muted: #6b7280;
    --inbox-faint: #9aa3b0;
    --st-wait: #d99a2b;
    --st-open: #0d9488;
    --st-done: #35a37a;
    --st-late: #dc3545;
}
[data-bs-theme="dark"] {
    --inbox-canvas: #171d26;
    --inbox-surface: #1f2733;
    --inbox-raised: #273140;
    --inbox-line: #333e4d;
    --inbox-muted: #93a1b4;
    --inbox-faint: #6b7a8d;
    --st-late: #e05561;
}

/* Chips de filtro: tracejados quando vazios, teal quando ativos. */
.filter-chip {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
    border: 1px dashed var(--inbox-line); border-radius: 8px; padding: 3px 8px;
    color: var(--inbox-muted); font-size: .78rem;
}
.filter-chip select {
    flex: 1; min-width: 0; border: 0; background: none; color: inherit;
    font: inherit; padding: 2px 0; cursor: pointer; outline: none;
}
.filter-chip.set {
    border-style: solid; border-color: var(--brand);
    background: color-mix(in srgb, var(--brand) 12%, transparent);
    color: var(--brand-dark);
}
[data-bs-theme="dark"] .filter-chip.set { color: var(--brand-light); }
/* As opções herdam o fundo do sistema; força o tema para não sair branco no escuro. */
[data-bs-theme="dark"] .filter-chip select option { background: var(--inbox-surface); color: #e2e8f0; }
.filter-clear {
    border: 1px solid var(--inbox-line); background: none; color: var(--inbox-muted);
    border-radius: 8px; padding: 0 8px; cursor: pointer; font-size: .72rem;
}
.filter-clear:hover { color: var(--st-late); border-color: var(--st-late); }

/* Contadores como seletor segmentado. */
.conv-tabs { display: flex; gap: 2px; background: var(--inbox-raised); border-radius: 9px; padding: 3px; }
.conv-tabs button {
    flex: 1; border: 0; background: none; color: var(--inbox-muted);
    font-size: .72rem; line-height: 1.25; padding: 4px 2px; border-radius: 7px; cursor: pointer;
}
.conv-tabs button b { display: block; font-size: .92rem; color: var(--bs-body-color); font-variant-numeric: tabular-nums; }
.conv-tabs button.on { background: var(--inbox-surface); font-weight: 600; box-shadow: 0 1px 3px rgba(16,24,40,.12); }
[data-bs-theme="dark"] .conv-tabs button.on { box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.conv-tabs button.on b { color: var(--brand-dark); }
[data-bs-theme="dark"] .conv-tabs button.on b { color: var(--brand-light); }

/* Linha da conversa: faixa de estado + corpo + contador. */
.conv-item {
    display: grid; grid-template-columns: 3px 1fr auto; gap: 9px;
    padding: 8px 10px 8px 0; border-bottom: 1px solid var(--inbox-line);
    cursor: pointer; align-items: start;
}
.conv-item:hover { background: var(--inbox-raised); }
.conv-item.on { background: color-mix(in srgb, var(--brand) 14%, transparent); }
.conv-stripe { align-self: stretch; border-radius: 0 3px 3px 0; }
.conv-stripe.s-wait { background: var(--st-wait); }
.conv-stripe.s-open { background: var(--st-open); }
.conv-stripe.s-done { background: var(--st-done); }
.conv-stripe.s-late { background: var(--st-late); }
.conv-body { min-width: 0; }
.conv-head { display: flex; align-items: baseline; gap: 6px; }
.conv-name { font-size: .82rem; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: .67rem; color: var(--inbox-faint); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.conv-prev { font-size: .75rem; color: var(--inbox-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { display: flex; align-items: center; gap: 5px; margin-top: 2px; font-size: .67rem; color: var(--inbox-faint); flex-wrap: wrap; }
.conv-meta .conv-late { color: var(--st-late); font-weight: 600; }
.conv-sep { opacity: .5; }
.conv-unread {
    align-self: center; background: var(--brand); color: #fff; border-radius: 20px;
    font-size: .65rem; font-weight: 700; min-width: 18px; text-align: center; padding: 1px 5px;
}

/* O inbox precisa caber na tela sem rolagem da página, senão o compositor cai abaixo
   da dobra. Em vez de descontar a altura da topbar na mão (frágil: muda com a barra de
   impersonação, com zoom, com quebra de linha no título), fixa a altura no shell e deixa
   o flex distribuir o que sobra — a topbar toma o que precisa, o inbox fica com o resto. */
.app-shell:has(.inbox-fill) { height: 100dvh; overflow: hidden; }
.app-shell:has(.inbox-fill) .app-main { min-height: 0; overflow: hidden; }
.app-content:has(.inbox-fill) { padding: 0; min-height: 0; overflow: hidden; }
.inbox-fill { height: 100%; min-height: 0; }

/* ---------- Inbox: chat ---------- */
.chat-canvas { background: var(--inbox-canvas); }
.chat-daysep { text-align: center; margin: 6px 0 10px; }
.chat-daysep span {
    background: var(--inbox-raised); color: var(--inbox-muted);
    font-size: .68rem; padding: 3px 11px; border-radius: 20px;
}
.msg-in { background: var(--inbox-surface); }
.msg-out { background: var(--brand); color: #fff; }
[data-bs-theme="dark"] .msg-out { background: color-mix(in srgb, var(--brand) 82%, #000); }
.msg-note {
    background: color-mix(in srgb, var(--st-wait) 16%, transparent);
    border: 1px solid color-mix(in srgb, var(--st-wait) 45%, transparent);
}
.msg-note-tag { font-size: .68rem; font-weight: 600; color: var(--st-wait); margin-bottom: 2px; }
.msg-time { font-size: .64rem; opacity: .7; margin-top: 2px; font-variant-numeric: tabular-nums; }
/* Ctrl+Enter quebra linha: sem isto o HTML colapsa a quebra e o balão sai numa linha só. */
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Compositor: cresce com o texto (o teto de altura é aplicado pelo composer.js). */
.composer-input { resize: none; overflow-y: auto; line-height: 1.35; }

/* ---------- Inbox: painel do contato ---------- */
.contact-panel { background: var(--inbox-surface); }
.contact-name { font-size: .84rem; }
.contact-phone { font-size: .72rem; color: var(--inbox-faint); font-variant-numeric: tabular-nums; }
.contact-h {
    font-size: .63rem; text-transform: uppercase; letter-spacing: .09em;
    color: var(--inbox-faint); font-weight: 700;
}
.contact-kv { display: grid; grid-template-columns: 60px 1fr; gap: 4px 8px; margin: 0; font-size: .74rem; }
.contact-kv dt { color: var(--inbox-faint); font-weight: 400; }
.contact-kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.contact-kv dd.empty { color: var(--inbox-faint); }
.contact-kv dd.protocol { font-variant-numeric: tabular-nums; font-size: .72rem; }
.contact-empty { font-size: .73rem; color: var(--inbox-faint); }
.contact-empty button { font-size: .74rem; margin-top: 5px; }

/* ---------- Misc ---------- */
.quick-item:hover { background: #f0faf8; }
[data-bs-theme="dark"] .quick-item:hover { background: #2f3847; }

#blazor-error-ui {
    background: #fff3cd; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; }
.validation-message { color: #e50000; }

@media (max-width: 768px) {
    .app-sidebar { transform: translateX(-248px); }
    .app-main { margin-left: 0; }
    body:not(.sidebar-collapsed) .app-sidebar { transform: translateX(0); }
}
