/* ============================================================
   CRM AGS Tráfego Express — estilos globais
   Mobile-first. Sem frameworks externos.
   ============================================================ */

:root {
    --color-primary:       #1a1a1a;
    --color-primary-light: #2e2e2e;
    --color-primary-dark:  #0d0d0d;
    --color-accent:        #cc0000;
    --color-accent-dark:   #a30000;
    --color-bg:            #f4f6f9;
    --color-surface:       #ffffff;
    --color-border:        #e2e6ed;
    --color-text:          #1f2733;
    --color-text-muted:    #6b7686;
    --color-success:       #2ecc71;
    --color-danger:        #e74c3c;

    --radius-sm: 6px;
    --radius-md: 10px;
    --shadow-sm: 0 1px 3px rgba(16, 28, 51, 0.08);
    --shadow-md: 0 8px 24px rgba(16, 28, 51, 0.12);

    --sidebar-width: 260px;
    --topbar-height: 60px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

h1, h2, h3 {
    margin: 0 0 8px;
}

button {
    font-family: inherit;
}

/* ------------------------------------------------------------
   Botões / formulários (compartilhados entre login e app)
   ------------------------------------------------------------ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s ease, transform .05s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn--primary {
    background: var(--color-accent);
    color: #fff;
}

.btn--primary:hover {
    background: var(--color-accent-dark);
}

.btn--block {
    width: 100%;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    background: #fff;
    color: var(--color-text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
}

.alert--error {
    background: #fdecea;
    color: var(--color-danger);
    border: 1px solid #f8c9c4;
}

/* ------------------------------------------------------------
   Página de login
   ------------------------------------------------------------ */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(160deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 36px 28px;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--color-accent);
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: .5px;
    margin-bottom: 14px;
}

.login-logo__img {
    display: block;
    width: 140px;
    height: auto;
    margin: 0 auto 14px;
}

.login-logo h1 {
    font-size: 20px;
    color: var(--color-primary);
}

.login-logo p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--color-text-muted);
}

/* ------------------------------------------------------------
   Layout principal (sidebar + conteúdo) — mobile-first
   ------------------------------------------------------------ */

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: var(--color-primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 40;
}

.sidebar--open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(16, 28, 51, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    z-index: 30;
}

.sidebar-overlay--visible {
    opacity: 1;
    pointer-events: auto;
}

.sidebar__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 22px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__brand-badge {
    background: var(--color-accent);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    border-radius: 8px;
    padding: 6px 9px;
}

.sidebar__brand-fallback {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.sidebar__brand-logo {
    width: 108px;
    height: auto;
    display: block;
    background: #fff;
    border-radius: 10px;
    padding: 8px;
}

.sidebar__brand-text {
    font-weight: 600;
    font-size: 15px;
}

.sidebar__nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.75);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
}

.sidebar__link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.sidebar__link--active {
    background: var(--color-accent);
    color: #fff;
}

.sidebar__icon-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    background: var(--color-primary);
    border-radius: 3px;
}

.sidebar__link--active .sidebar__icon-wrap {
    background: var(--color-accent);
}

.sidebar__link:hover .sidebar__icon-wrap {
    background: rgba(255, 255, 255, 0.06);
}

.sidebar__icon {
    width: 26px;
    height: 26px;
    object-fit: contain;
    background: none;
    filter: brightness(1.1);
}

/* Silhuetas: inverte apenas os pixels da imagem — fundo fica no wrap */
.sidebar__icon[src*="leads.png"],
.sidebar__icon[src*="usuarios.png"] {
    filter: brightness(0) invert(1);
}

.sidebar__badge {
    margin-left: auto;
    background: var(--color-danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
}

.sidebar__footer {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sidebar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.sidebar__avatar {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.sidebar__user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar__user-info strong {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar__user-info span {
    font-size: 11px;
    text-transform: capitalize;
    color: rgba(255, 255, 255, 0.6);
}

.sidebar__logout {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    font-size: 15px;
}

.sidebar__logout:hover {
    background: var(--color-danger);
}

.app-shell__main {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 18px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar__toggle {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
}

.topbar__toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--color-primary);
    border-radius: 2px;
}

.topbar__title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-primary);
}

.content {
    flex: 1;
    padding: 20px 16px 40px;
}

/* ------------------------------------------------------------
   Componentes de conteúdo
   ------------------------------------------------------------ */

.page-intro {
    margin-bottom: 20px;
}

.page-intro p {
    color: var(--color-text-muted);
    margin: 0;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

.card__label {
    display: block;
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.card__value {
    font-size: 26px;
    font-weight: 700;
    color: var(--color-primary);
}

.card--placeholder {
    color: var(--color-text-muted);
    font-size: 14px;
}

.card__sub {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--color-text-muted);
}

.card__sub--danger {
    color: var(--color-danger);
    font-weight: 700;
}

.recent-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.recent-list__item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--color-border);
}

.recent-list__item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.recent-list__item a {
    font-weight: 600;
    color: var(--color-primary);
}

.recent-list__meta {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.recent-list__date {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--color-text-muted);
    white-space: nowrap;
}

/* ------------------------------------------------------------
   Breakpoints — tablet / desktop
   ------------------------------------------------------------ */

@media (min-width: 768px) {
    .cards-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ------------------------------------------------------------
   Botões adicionais / ações
   ------------------------------------------------------------ */

.btn--secondary {
    background: var(--color-primary);
    color: #fff;
}

.btn--secondary:hover {
    background: var(--color-primary-light);
}

.btn--outline {
    background: transparent;
    color: var(--color-primary);
    border: 1px solid var(--color-border);
}

.btn--outline:hover {
    background: var(--color-bg);
}

.btn--danger {
    background: var(--color-danger);
    color: #fff;
}

.btn--danger:hover {
    background: #c0392b;
}

.btn--sm {
    padding: 7px 12px;
    font-size: 13px;
}

.alert--success {
    background: #eafaf1;
    color: #1e8449;
    border: 1px solid #b9ecd0;
}

/* ------------------------------------------------------------
   Cabeçalho de página (título + ação principal)
   ------------------------------------------------------------ */

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.page-header h2 {
    margin: 0;
    color: var(--color-primary);
    font-size: 19px;
}

/* ------------------------------------------------------------
   Badges
   ------------------------------------------------------------ */

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge--blue   { background: #e8f1fc; color: #2471a3; }
.badge--purple { background: #f1e8fb; color: #7d3c98; }
.badge--orange { background: #fdf0e3; color: #b9650f; }
.badge--green  { background: #e7f9ef; color: #1e8449; }
.badge--red    { background: #fdecea; color: #c0392b; }
.badge--gray   { background: #eef0f3; color: #5d6675; }

/* ------------------------------------------------------------
   Barra de filtros
   ------------------------------------------------------------ */

.filter-bar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 18px;
}

.filter-bar__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: end;
}

.filter-bar__grid .form-group {
    margin-bottom: 0;
}

.filter-bar__actions {
    display: flex;
    gap: 10px;
}

@media (min-width: 768px) {
    .filter-bar__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 992px) {
    .filter-bar__grid {
        grid-template-columns: 2fr 1fr 1fr 1fr auto;
    }
}

/* ------------------------------------------------------------
   Tabela
   ------------------------------------------------------------ */

.table-responsive {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}

table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    min-width: 720px;
}

table.table th,
table.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

table.table th {
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
}

table.table tbody tr:hover {
    background: var(--color-bg);
}

table.table td.is-wrap {
    white-space: normal;
}

.table-actions {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

.table-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--color-text-muted);
}

/* Tarefas vencidas: destaque visual em vermelho */
table.table tbody tr.is-overdue {
    background: #fdecea;
}

table.table tbody tr.is-overdue:hover {
    background: #fbdedb;
}

table.table tbody tr.is-overdue td:first-child {
    border-left: 3px solid var(--color-danger);
}

table.table tbody tr.is-overdue td[data-venc-cell] {
    color: var(--color-danger);
    font-weight: 700;
}

/* ------------------------------------------------------------
   Paginação
   ------------------------------------------------------------ */

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 16px;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
}

.pagination a:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.pagination .is-active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
}

.pagination .is-disabled {
    opacity: .4;
    pointer-events: none;
}

/* ------------------------------------------------------------
   Perfil do lead / detalhe
   ------------------------------------------------------------ */

.detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 992px) {
    .detail-grid {
        grid-template-columns: 1.1fr 1.4fr;
    }
}

.detail-list {
    display: grid;
    gap: 12px;
}

.detail-list__item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-list__item span {
    font-size: 12px;
    color: var(--color-text-muted);
}

.detail-list__item strong {
    font-size: 14px;
    color: var(--color-text);
    word-break: break-word;
}

/* ------------------------------------------------------------
   Timeline de interações
   ------------------------------------------------------------ */

.timeline {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.timeline-item {
    border-left: 3px solid var(--color-accent);
    padding: 4px 0 4px 14px;
}

.timeline-item__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 12px;
    color: var(--color-text-muted);
}

.timeline-item p {
    margin: 0;
    font-size: 14px;
    white-space: pre-wrap;
}

/* ------------------------------------------------------------
   Abas (painel de WhatsApp)
   ------------------------------------------------------------ */

.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 18px;
    overflow-x: auto;
}

.tab-btn {
    border: none;
    background: transparent;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--color-primary);
}

.tab-btn.is-active {
    color: var(--color-primary);
    border-bottom-color: var(--color-accent);
}

.tab-panel {
    display: none;
}

.tab-panel.is-active {
    display: block;
}

/* ------------------------------------------------------------
   Preview de mensagem de WhatsApp
   ------------------------------------------------------------ */

.whatsapp-preview {
    background: #e9fbe3;
    border: 1px solid #c8eec0;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--color-text);
    min-height: 48px;
}

/* ------------------------------------------------------------
   Autocomplete (busca de lead no envio manual)
   ------------------------------------------------------------ */

.autocomplete-list {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 10;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 220px;
    overflow-y: auto;
}

.autocomplete-list.is-open {
    display: block;
}

.autocomplete-item {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
}

.autocomplete-item:hover {
    background: var(--color-bg);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

@media (min-width: 768px) {
    .form-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ------------------------------------------------------------
   Kanban (Funil de Vendas)
   ------------------------------------------------------------ */

.kanban-board {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 12px;
    align-items: flex-start;
}

.kanban-column {
    flex: 0 0 270px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 220px);
}

.kanban-column__header {
    padding: 14px 14px 10px;
    border-top: 4px solid var(--color-border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.kanban-column__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14px;
    color: var(--color-primary);
}

.kanban-column__dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.kanban-column__count {
    margin-left: auto;
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 700;
    border-radius: 999px;
    padding: 2px 8px;
}

.kanban-column__total {
    margin-top: 4px;
    font-size: 12px;
    color: var(--color-text-muted);
}

.kanban-column__body {
    flex: 1;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    min-height: 80px;
    transition: background-color .12s ease;
}

.kanban-column__body.is-dragover {
    background: rgba(249, 115, 22, 0.08);
    outline: 2px dashed var(--color-accent);
    outline-offset: -4px;
}

.kanban-empty {
    margin: 12px 0;
    text-align: center;
    font-size: 13px;
    color: var(--color-text-muted);
}

.kanban-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 12px;
    cursor: grab;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .12s ease, opacity .12s ease;
}

.kanban-card:hover {
    box-shadow: var(--shadow-md);
}

.kanban-card.is-dragging {
    opacity: .4;
}

.kanban-card__lead {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: var(--color-primary);
    margin-bottom: 4px;
}

.kanban-card__valor {
    font-weight: 700;
    font-size: 15px;
    color: var(--color-accent-dark);
    margin-bottom: 6px;
}

.kanban-card__meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

.kanban-card__actions {
    display: flex;
    justify-content: flex-end;
}

@media (min-width: 992px) {
    .sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
    }

    .app-shell__main {
        margin-left: var(--sidebar-width);
    }

    .topbar__toggle {
        display: none;
    }

    .content {
        padding: 28px 32px 48px;
    }
}

@media (min-width: 992px) {
    #fin-filter-grid { grid-template-columns: 1fr 1fr 1fr 1fr 1fr auto; }
}
