/* ==========================================================
   CRM MedPlus - estilos (versao premium)
   Paleta e tokens seguem o metodo de visualizacao de dados
   (ver skill "dataviz"): cores categoricas em ordem fixa,
   tons reservados para status (verde = ganho, vermelho = perdido).
   ========================================================== */

:root {
    color-scheme: light;
    --page: #f6f6f3;
    --surface-1: #ffffff;
    --surface-2: #fbfbf9;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --baseline: #c3c2b7;
    --border: rgba(11, 11, 11, 0.08);
    --shadow: 0 1px 2px rgba(20, 20, 15, 0.04), 0 8px 24px -12px rgba(20, 20, 15, 0.10);
    --shadow-hover: 0 4px 10px rgba(20, 20, 15, 0.06), 0 16px 32px -14px rgba(20, 20, 15, 0.16);

    --series-whatsapp: #2a78d6;
    --series-instagram: #eb6834;
    --series-google: #1baf7a;

    /* Origem dos visitantes (grafico "Origem dos visitantes" na pagina Visitantes) */
    --src-meta-ads: #2a78d6;
    --src-ig-pessoal: #eb6834;
    --src-google-ads: #1baf7a;
    --src-google-organico: #eda100;
    --src-ig-empresa: #e87ba4;
    --src-ig-generico: #008300;
    --src-facebook: #4a3aa7;
    --src-whatsapp: #e34948;

    --ordinal-1: #86b6ef; /* novo */
    --ordinal-2: #3987e5; /* em atendimento */
    --ordinal-3: #1c5cab; /* aguardando resposta */
    --status-good: #0ca30c;     /* convertido */
    --status-critical: #d03b3b; /* perdido */

    /* Marca (estilo "app escuro"): azul de destaque, igual a paleta da LP */
    --brand: #2a78d6;
    --brand-dark: #1c5cab;
    --sidebar-bg: #0a1628;
    --sidebar-bg-2: #122542;
    --sidebar-text: #aeb9d4;
    --sidebar-active: #1c3a63;
    --accent-gradient: linear-gradient(135deg, #2a78d6, #1c5cab);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page: #0a0a0a;
        --surface-1: #181818;
        --surface-2: #141414;
        --text-primary: #f5f5f4;
        --text-secondary: #c3c2b7;
        --muted: #8f8e88;
        --grid: #2c2c2a;
        --baseline: #3a3a37;
        --border: rgba(255, 255, 255, 0.09);
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
        --shadow-hover: 0 4px 10px rgba(0, 0, 0, 0.4), 0 18px 36px -14px rgba(42, 120, 214, 0.22);

        --series-whatsapp: #4a95f0;
        --series-instagram: #e46f34;
        --series-google: #22b57e;

        --src-meta-ads: #3987e5;
        --src-ig-pessoal: #d95926;
        --src-google-ads: #199e70;
        --src-google-organico: #c98500;
        --src-ig-empresa: #d55181;
        --src-ig-generico: #008300;
        --src-facebook: #9085e9;
        --src-whatsapp: #e66767;

        --ordinal-1: #6da7ec;
        --ordinal-2: #2a78d6;
        --ordinal-3: #184f95;
        --status-good: #17b317;
        --status-critical: #e66767;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0a0a0a;
    --surface-1: #181818;
    --surface-2: #141414;
    --text-primary: #f5f5f4;
    --text-secondary: #c3c2b7;
    --muted: #8f8e88;
    --grid: #2c2c2a;
    --baseline: #3a3a37;
    --border: rgba(255, 255, 255, 0.09);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    --shadow-hover: 0 4px 10px rgba(0, 0, 0, 0.4), 0 18px 36px -14px rgba(42, 120, 214, 0.22);

    --series-whatsapp: #4a95f0;
    --series-instagram: #e46f34;
    --series-google: #22b57e;

    --src-meta-ads: #3987e5;
    --src-ig-pessoal: #d95926;
    --src-google-ads: #199e70;
    --src-google-organico: #c98500;
    --src-ig-empresa: #d55181;
    --src-ig-generico: #008300;
    --src-facebook: #9085e9;
    --src-whatsapp: #e66767;

    --ordinal-1: #6da7ec;
    --ordinal-2: #2a78d6;
    --ordinal-3: #184f95;
    --status-good: #17b317;
    --status-critical: #e66767;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--page);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.2s ease, color 0.2s ease;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Login ---------- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse 900px 500px at 50% -10%, rgba(42, 120, 214, 0.28), transparent 60%),
        radial-gradient(circle at 20% 20%, var(--sidebar-bg-2), var(--sidebar-bg) 65%);
}
.login-card {
    background: rgba(24, 24, 24, 0.92);
    padding: 40px;
    border-radius: 16px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.09);
}
.login-card h1 {
    margin: 0 0 4px;
    font-size: 22px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-weight: 800;
}
.login-subtitle { color: #b3b3b3; margin: 0 0 24px; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 6px; }
.login-card label { font-size: 13px; color: #b3b3b3; margin-top: 10px; }
.login-card input {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(255,255,255,0.06);
    color: #f5f5f4;
    font-size: 14px;
    font-family: inherit;
}
.login-card input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(42, 120, 214, 0.2);
}
.login-card button {
    margin-top: 20px;
    padding: 11px;
    border: none;
    border-radius: 8px;
    background: var(--accent-gradient);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
}
.login-card button:hover { transform: translateY(-1px); box-shadow: 0 8px 20px -8px rgba(42, 120, 214, 0.6); }

/* ---------- Shell / sidebar ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 224px;
    background: linear-gradient(180deg, var(--sidebar-bg-2), var(--sidebar-bg));
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 22px 0;
    flex-shrink: 0;
}
.sidebar .brand {
    font-weight: 800;
    font-size: 16.5px;
    padding: 0 22px 22px;
    color: #fff;
    letter-spacing: -0.01em;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; padding: 0 10px; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--sidebar-text);
    font-size: 13.5px;
    font-weight: 500;
    border-radius: 9px;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.sidebar nav a svg { opacity: 0.85; flex-shrink: 0; }
.sidebar nav a:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 700; box-shadow: inset 3px 0 0 var(--brand); }
.sidebar-footer { padding: 16px 22px 0; border-top: 1px solid rgba(255,255,255,0.08); margin-top: 12px; }
.sidebar-footer .user-name { color: #fff; font-size: 14px; font-weight: 700; margin-top: 10px; }
.sidebar-footer .user-role { font-size: 12px; color: var(--sidebar-text); margin-bottom: 8px; }
.sidebar-links { display: flex; gap: 12px; }
.logout-link, .sidebar-links a { font-size: 12.5px; color: var(--sidebar-text); }
.logout-link:hover, .sidebar-links a:hover { color: #fff; }

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    color: var(--sidebar-text);
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    margin-bottom: 4px;
}
.theme-toggle:hover { background: rgba(255,255,255,0.1); color: #fff; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
    :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}

.content { flex: 1; padding: 28px 34px 48px; max-width: 1280px; }
.content-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.content-header h1 { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -0.01em; }

/* ---------- Notificacoes ---------- */
.notif-wrap { position: relative; flex-shrink: 0; }
.notif-bell {
    position: relative;
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    box-shadow: var(--shadow);
}
.notif-bell:hover { color: var(--text-primary); }
.notif-badge {
    position: absolute;
    top: -5px; right: -5px;
    min-width: 17px; height: 17px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--status-critical);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
}
.notif-dropdown {
    position: absolute;
    top: 46px; right: 0;
    width: 300px;
    max-height: 360px;
    overflow-y: auto;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-hover);
    padding: 8px;
    z-index: 20;
}
.notif-dropdown-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); padding: 6px 8px 8px; }
.notif-item { display: block; padding: 9px 8px; border-radius: 8px; font-size: 13px; color: var(--text-primary); line-height: 1.4; }
.notif-item:hover { background: var(--surface-2); text-decoration: none; }
.notif-empty { padding: 14px 8px; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- Dashboard header (estilo "hero" Netflix) ---------- */
.dash-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 22px;
    gap: 16px;
    flex-wrap: wrap;
    background:
        linear-gradient(120deg, rgba(42, 120, 214, 0.14), transparent 65%),
        var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px 26px;
    box-shadow: var(--shadow);
}
.dash-greeting { margin: 0; font-size: 27px; font-weight: 800; letter-spacing: -0.02em; }
.dash-date { margin: 5px 0 0; color: var(--muted); font-size: 13.5px; text-transform: capitalize; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters-dash { margin-bottom: 22px; }
.filters input, .filters select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--baseline);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
}
.filters button {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--baseline);
    background: var(--surface-1);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
}

.segmented {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 3px;
    gap: 2px;
}
.segmented a {
    padding: 6px 13px;
    border-radius: 7px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
}
.segmented a:hover { text-decoration: none; color: var(--text-primary); }
.segmented a.active { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }

.btn-primary, .btn-secondary {
    display: inline-block;
    padding: 9px 16px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 700;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn-primary { background: var(--accent-gradient); color: #fff; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 20px -10px rgba(42, 120, 214, 0.55); text-decoration: none; }
.btn-secondary { background: var(--surface-1); color: var(--text-primary); border-color: var(--baseline); }
.btn-secondary:hover { text-decoration: none; border-color: var(--muted); }
.btn-lg { padding: 11px 20px; font-size: 13.5px; }

/* ---------- Table ---------- */
.table-wrapper { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
    text-align: left;
    padding: 12px 16px;
    color: var(--muted);
    font-weight: 700;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--grid);
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--grid); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(42, 120, 214, 0.04); }
.data-table-compact th, .data-table-compact td { padding: 9px 12px; font-size: 13px; }
.empty-state { text-align: center; color: var(--muted); padding: 28px !important; font-size: 13px; }

/* ---------- Tags (canal / status) ---------- */
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; color: #fff; letter-spacing: 0.01em; }
.tag-channel-whatsapp { background: var(--series-whatsapp); }
.tag-channel-instagram { background: var(--series-instagram); }
.tag-channel-google { background: var(--series-google); }
.tag-status-novo { background: var(--ordinal-1); color: #0b0b0b; }
.tag-status-em_atendimento { background: var(--ordinal-2); }
.tag-status-aguardando_resposta { background: var(--ordinal-3); }
.tag-status-convertido { background: var(--status-good); }
.tag-status-perdido { background: var(--status-critical); }

.campaign-pill {
    display: inline-block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
}
.empty-cell { color: var(--muted); }

/* ---------- Forms ---------- */
.form-card, .detail-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    max-width: 720px;
    box-shadow: var(--shadow);
    min-width: 0;
}
.detail-card h2 { margin-top: 0; font-size: 15.5px; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-row label { font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.form-row input, .form-row select, .form-row textarea {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--baseline);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
    outline: none;
    border-color: var(--series-whatsapp);
    box-shadow: 0 0 0 3px rgba(42, 120, 214, 0.15);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

.utm-fieldset {
    border: 1px dashed var(--baseline);
    border-radius: 10px;
    padding: 4px 14px 14px;
    margin-bottom: 18px;
    background: var(--surface-2);
}
.utm-fieldset summary { padding: 10px 0; font-size: 13.5px; font-weight: 700; cursor: pointer; color: var(--text-secondary); }
.utm-fieldset[open] summary { color: var(--text-primary); }
.utm-fieldset .form-hint { font-size: 12px; color: var(--muted); margin: 0 0 14px; }
.utm-fieldset .form-grid:last-child { margin-bottom: 0; }

/* ---------- Bloco de permissoes (tela de Equipe) ---------- */
.perm-fieldset {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 16px 14px;
    margin: 4px 0 18px;
    background: var(--surface-2);
}
.perm-fieldset legend { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); padding: 0 4px; }
.perm-hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.perm-check {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13.5px;
    padding: 8px 2px;
    cursor: pointer;
    border-top: 1px solid var(--grid);
}
.perm-check:first-of-type { border-top: none; }
.perm-check input { width: 17px; height: 17px; accent-color: var(--brand); cursor: pointer; flex-shrink: 0; }
.perm-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 9px 2px;
    border-top: 1px solid var(--grid);
}
.perm-row label { font-size: 13.5px; font-weight: 700; min-width: 42px; }
.perm-row select {
    padding: 7px 10px;
    border-radius: 7px;
    border: 1px solid var(--baseline);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 12.5px;
    font-family: inherit;
    flex: 1 1 150px;
}

.alert { padding: 10px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: rgba(208, 59, 59, 0.12); color: var(--status-critical); border: 1px solid rgba(208, 59, 59, 0.3); }
.alert-success { background: rgba(12, 163, 12, 0.12); color: var(--status-good); border: 1px solid rgba(12, 163, 12, 0.3); }

/* ---------- Lead detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.detail-list { display: grid; grid-template-columns: 140px 1fr; gap: 10px 12px; font-size: 14px; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; }
.notes-box { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--grid); font-size: 14px; }
.notes-box p { margin: 6px 0 0; white-space: pre-wrap; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.timeline li { border-left: 2px solid var(--grid); padding-left: 14px; }
.timeline-desc { font-size: 14px; }
.timeline-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Dashboard: KPIs ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px;
    box-shadow: var(--shadow);
    transition: transform 0.22s cubic-bezier(.2,.8,.2,1), box-shadow 0.22s ease, border-color 0.22s ease;
    min-width: 0;
}
.kpi-card:hover {
    transform: translateY(-4px) scale(1.025);
    box-shadow: var(--shadow-hover);
    border-color: rgba(42, 120, 214, 0.35);
    z-index: 2;
    position: relative;
}
.kpi-top { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.kpi-icon {
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 9px;
    flex-shrink: 0;
}
.kpi-icon-blue { background: rgba(42, 120, 214, 0.12); color: var(--series-whatsapp); }
.kpi-icon-green { background: rgba(12, 163, 12, 0.12); color: var(--status-good); }
.kpi-icon-amber { background: rgba(235, 104, 52, 0.12); color: var(--series-instagram); }
.kpi-icon-red { background: rgba(208, 59, 59, 0.12); color: var(--status-critical); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: 28px; font-weight: 800; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi-value-text { font-size: 22px; }
.kpi-delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; margin-top: 8px; }
.kpi-delta svg { flex-shrink: 0; }
.kpi-delta-good { color: var(--status-good); }
.kpi-delta-bad { color: var(--status-critical); }
.kpi-delta-neutral { color: var(--muted); font-weight: 500; }

/* ---------- Ao vivo ---------- */
.live-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 18px;
    margin-bottom: 20px;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    transition: box-shadow 0.18s ease, transform 0.18s ease;
}
.live-banner:hover { box-shadow: var(--shadow-hover); text-decoration: none; transform: translateY(-1px); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--status-good); flex-shrink: 0; animation: livePulse 1.8s ease-in-out infinite; }
.live-banner-empty .live-dot { background: var(--muted); animation: none; }
.live-count { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.live-label { font-size: 13px; color: var(--text-secondary); }
.live-more { margin-left: auto; font-size: 12.5px; color: var(--muted); font-weight: 600; }
@keyframes livePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.45); }
    70% { box-shadow: 0 0 0 7px rgba(12, 163, 12, 0); }
}

.live-panel {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.live-panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.live-panel-head h3 { margin: 0; font-size: 14.5px; font-weight: 700; }
.live-panel .live-count { font-size: 26px; }
.live-visitor-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.live-visitor-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; font-size: 13px; border-top: 1px solid var(--grid); }
.live-visitor-list li:first-child { border-top: none; }
.live-visitor-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--status-good); flex-shrink: 0; }
.live-visitor-loc { font-weight: 600; }
.live-visitor-page { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-visitor-time { color: var(--muted); font-size: 11.5px; flex-shrink: 0; }

/* ---------- Tendencia em barras CSS (sem dependencia externa) ---------- */
.bar-trend { display: flex; align-items: flex-end; gap: 2px; height: 90px; margin-top: 6px; }
.bar-trend-col { flex: 1; display: flex; align-items: flex-end; height: 100%; min-width: 2px; }
.bar-trend-fill { width: 100%; background: var(--series-whatsapp); border-radius: 3px 3px 0 0; min-height: 2px; transition: height 700ms cubic-bezier(.2,.8,.2,1); }
.bar-trend-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ---------- Charts ---------- */
.chart-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; margin-bottom: 20px; }
.chart-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    box-shadow: var(--shadow);
    transition: transform 0.22s cubic-bezier(.2,.8,.2,1), box-shadow 0.22s ease, border-color 0.22s ease;
    /* Evita que uma tabela larga dentro de um card "estique" o grid inteiro
       (inclusive os cards vizinhos, sem tabela) para alem da largura da tela. */
    min-width: 0;
}
.chart-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: rgba(42, 120, 214, 0.25); }
.chart-grid-full { grid-template-columns: 1fr; }
.chart-card h3 {
    position: relative;
    margin: 0 0 4px;
    padding-left: 13px;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.01em;
}
.chart-card h3::before {
    content: '';
    position: absolute;
    left: 0; top: 2px; bottom: 2px;
    width: 4px;
    border-radius: 2px;
    background: var(--accent-gradient);
}
.chart-card .chart-subtitle { font-size: 12.5px; color: var(--muted); margin: 0 0 16px; padding-left: 13px; }

/* ---------- Aneis SVG animados ("caracois"), sem dependencia externa ---------- */
.donut-wrap { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; padding-top: 4px; }
.ring-chart { position: relative; width: 160px; height: 160px; flex-shrink: 0; }
.ring-svg {
    width: 100%; height: 100%;
    transform: rotate(-90deg) scale(0.7);
    opacity: 0;
    animation: ringPop 950ms cubic-bezier(.2,.8,.2,1) forwards;
    animation-delay: 80ms;
}
.ring-track { fill: none; stroke: var(--grid); stroke-width: 12; }
.ring-seg { fill: none; stroke-width: 12; stroke-linecap: round; transition: stroke-dasharray 900ms cubic-bezier(.2,.8,.2,1); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.ring-total { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.ring-total-label { font-size: 11px; color: var(--muted); }
.donut-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 11px; flex: 1; min-width: 140px; }
.donut-legend li {
    display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--text-secondary);
    opacity: 0; animation: legendFadeIn 500ms ease forwards;
}
.donut-legend li:nth-child(1) { animation-delay: 260ms; }
.donut-legend li:nth-child(2) { animation-delay: 360ms; }
.donut-legend li:nth-child(3) { animation-delay: 460ms; }
.donut-legend li:nth-child(4) { animation-delay: 560ms; }
.donut-legend li:nth-child(5) { animation-delay: 660ms; }
.donut-legend li:nth-child(6) { animation-delay: 760ms; }
.donut-legend li:nth-child(7) { animation-delay: 860ms; }
.donut-legend li:nth-child(8) { animation-delay: 960ms; }
.donut-legend li:nth-child(n+9) { animation-delay: 1000ms; }
.donut-legend .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.donut-legend strong { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-primary); }

@keyframes ringPop {
    from { opacity: 0; transform: rotate(-90deg) scale(0.7); }
    to { opacity: 1; transform: rotate(-90deg) scale(1); }
}
@keyframes legendFadeIn {
    from { opacity: 0; transform: translateX(-4px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---------- Aneis pequenos: conversao por canal ---------- */
.mini-rings { display: flex; justify-content: space-around; align-items: flex-start; gap: 14px; padding-top: 10px; flex-wrap: wrap; }
.mini-ring {
    position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    opacity: 0; animation: ringItemIn 600ms cubic-bezier(.2,.8,.2,1) forwards;
}
.mini-ring .ring-svg-sm { width: 104px; height: 104px; }
.mini-ring .ring-track-sm, .mini-ring .ring-seg-sm { stroke-width: 9; }
.mini-ring .ring-center { position: absolute; top: 0; left: 0; width: 104px; height: 104px; }
.mini-ring .ring-pct { font-size: 16.5px; font-weight: 800; font-variant-numeric: tabular-nums; }
.mini-ring-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); }
@keyframes ringItemIn {
    from { opacity: 0; transform: translateY(8px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Funil (barras animadas) ---------- */
.funnel { display: flex; flex-direction: column; gap: 14px; }
.funnel-row { display: grid; grid-template-columns: 128px 1fr 92px; align-items: center; gap: 10px; }
.funnel-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.funnel-track { background: var(--grid); border-radius: 999px; height: 10px; overflow: hidden; }
.funnel-bar { height: 100%; border-radius: 999px; transition: width 900ms cubic-bezier(.2,.8,.2,1); }
.funnel-value { font-size: 12.5px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.funnel-value span { color: var(--muted); font-weight: 500; }

/* ---------- Precisa de atencao ---------- */
.attention-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.attention-list li a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 8px;
    border-radius: 9px;
    color: var(--text-primary);
}
.attention-list li a:hover { background: var(--surface-2); text-decoration: none; }
.attention-name { flex: 1; font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-wait { font-size: 12px; color: var(--muted); flex-shrink: 0; }

/* ---------- Atividade recente ---------- */
.activity-feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.activity-feed li {
    display: flex; gap: 12px; align-items: flex-start;
    opacity: 0;
    animation: fadeInUp 0.5s ease forwards;
}
.activity-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; background: var(--series-whatsapp); }
.activity-dot-criado { background: var(--ordinal-1); }
.activity-dot-status_alterado { background: var(--ordinal-3); }
.activity-dot-atualizado { background: var(--muted); }
.activity-desc { font-size: 13.5px; }
.activity-desc a { color: var(--text-primary); font-weight: 700; }
.activity-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Kanban ---------- */
.kanban-board { display: grid; grid-template-columns: repeat(4, minmax(230px, 1fr)); gap: 14px; align-items: start; overflow-x: auto; }
.kanban-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 200px; }
.kanban-col-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text-secondary); padding: 2px 2px 0; }
.kanban-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.kanban-count { margin-left: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; font-size: 11px; color: var(--muted); font-weight: 700; }
.kanban-drop { display: flex; flex-direction: column; gap: 10px; min-height: 80px; border-radius: 10px; transition: background-color 0.15s ease; padding: 2px; }
.kanban-drop.drag-over { background: rgba(42, 120, 214, 0.08); outline: 2px dashed var(--series-whatsapp); outline-offset: -2px; }
.kanban-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 12px;
    cursor: grab;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.kanban-card:hover { box-shadow: var(--shadow-hover); }
.kanban-card.dragging { opacity: 0.4; }
.kanban-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.kanban-time { font-size: 11px; color: var(--muted); }
.kanban-card-name { display: block; font-size: 13.5px; font-weight: 700; color: var(--text-primary); margin-bottom: 3px; }
.kanban-card-name:hover { text-decoration: none; color: var(--series-whatsapp); }
.kanban-card-meta { font-size: 11.5px; color: var(--muted); }
.kanban-empty { text-align: center; color: var(--muted); font-size: 12px; padding: 18px 6px; border: 1px dashed var(--baseline); border-radius: 10px; }

@media (max-width: 980px) {
    .kanban-board { grid-template-columns: 1fr; }
    .chart-grid { grid-template-columns: 1fr; }
}

/* ---------- Mobile (celular / tablet estreito): app de tela cheia ---------- */
.menu-toggle, .bottom-nav, .drawer-overlay { display: none; }

@media (max-width: 900px) {
    html, body { overflow-x: hidden; }
    .app-shell { flex-direction: column; }

    /* Sidebar vira uma gaveta (drawer) que desliza por cima do conteudo */
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 258px;
        flex-direction: column;
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(.2,.8,.2,1);
        z-index: 60;
        box-shadow: 0 0 40px rgba(0,0,0,0.35);
    }
    .sidebar.sidebar-open { transform: translateX(0); }
    .sidebar nav { overflow-y: auto; }

    .drawer-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 55;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }
    .drawer-overlay.visible { opacity: 1; pointer-events: auto; }

    /* Cabecalho: botao de menu + titulo + sino, colado nas bordas */
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 38px; height: 38px;
        flex-shrink: 0;
        background: var(--surface-1);
        border: 1px solid var(--border);
        border-radius: 10px;
        color: var(--text-secondary);
        box-shadow: var(--shadow);
    }
    .content-header { flex-wrap: nowrap; gap: 10px; }
    .content-header h1 { font-size: 16.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    /* Barra inferior fixa, estilo app nativo */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        z-index: 40;
        background: linear-gradient(180deg, var(--sidebar-bg-2), var(--sidebar-bg));
        border-top: 1px solid rgba(255,255,255,0.08);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -4px 18px rgba(0,0,0,0.25);
    }
    .bottom-nav a, .bottom-nav-more {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        padding: 6px 2px;
        color: var(--sidebar-text);
        font-size: 10.5px;
        font-weight: 600;
        border: none;
        background: none;
        font-family: inherit;
        cursor: pointer;
        border-radius: 10px;
    }
    .bottom-nav a:hover, .bottom-nav-more:hover { text-decoration: none; }
    .bottom-nav a.active { color: #fff; background: var(--sidebar-active); }

    /* Conteudo ocupa a tela inteira: sem margens laterais grandes, espaco pra barra inferior */
    .content { padding: 14px 12px calc(78px + env(safe-area-inset-bottom, 0px)); max-width: 100%; }
    .content-header { margin-bottom: 16px; }

    .kpi-row { grid-template-columns: 1fr; gap: 12px; }
    .kpi-card {
        padding: 16px 18px;
        border-radius: 14px;
        border-bottom: 2.5px solid var(--brand);
        box-shadow: var(--shadow);
    }
    .dash-header { padding: 18px 18px; border-radius: 14px; }
    .dash-greeting { font-size: 21px; }
    .kpi-value { font-size: 24px; }
    .detail-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-card, .detail-card { padding: 16px; border-radius: 14px; }
    .funnel-row { grid-template-columns: 90px 1fr 68px; gap: 8px; }
    .chart-card { padding: 16px; border-radius: 14px; }

    /* Barra de ferramentas / filtros: empilha e vira toque-friendly */
    .toolbar { flex-direction: column; align-items: stretch; gap: 12px; }
    .filters { width: 100%; }
    .filters input, .filters select { flex: 1 1 140px; }
    .filters button, .filters a.btn-secondary, .filters a.btn-primary { flex: 1 1 auto; text-align: center; }
    .segmented { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
    .segmented::-webkit-scrollbar { display: none; }

    /* Tabelas: rolagem horizontal (dentro do proprio card) em vez de espremer ou vazar pra fora */
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
    .data-table { min-width: 560px; }

    /* Notificacoes: dropdown nunca vaza da tela */
    .notif-dropdown { width: min(300px, 88vw); right: -4px; }

    /* Evita zoom automatico do iOS ao tocar em campos com fonte < 16px */
    .filters input, .filters select,
    .form-row input, .form-row select, .form-row textarea,
    .login-card input {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .login-card { padding: 28px 22px; }
    .ring-chart { width: 130px; height: 130px; }
    .mini-ring .ring-svg-sm { width: 88px; height: 88px; }
    .mini-ring .ring-center { width: 88px; height: 88px; }
    .detail-list { grid-template-columns: 108px 1fr; font-size: 13px; }
    .bottom-nav a span, .bottom-nav-more span { font-size: 10px; }
}
