/* ─── Base ─────────────────────────────────────────────────── */
html {
    font-size: 14px;
    position: relative;
    min-height: 100%;
}

@media (min-width: 768px) {
    html { font-size: 16px; }
}

body {
    margin: 0;
    background: #f4f6f9;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ─── Focus ────────────────────────────────────────────────── */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #667eea;
}

/* ─── Sidebar ──────────────────────────────────────────────── */
:root {
    --sidebar-width: 260px;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    color: #c4c4d4;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    text-decoration: none;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
}

.sidebar-section {
    padding: 0.75rem 1.5rem 0.35rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #6c6c8a;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.6rem 1.5rem;
    color: #a8a8c0;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.sidebar-link:hover {
    color: #fff;
    background: rgba(255,255,255,0.06);
}

.sidebar-link.active {
    color: #fff;
    background: rgba(102, 126, 234, 0.2);
    border-right: 3px solid #667eea;
}

.sidebar-link i {
    width: 20px;
    margin-right: 0.75rem;
    font-size: 1rem;
    text-align: center;
}

.sidebar-arrow {
    margin-left: auto;
    font-size: 0.65rem;
    transition: transform 0.25s;
}

.sidebar-link[aria-expanded="true"] .sidebar-arrow {
    transform: rotate(180deg);
}

.sidebar-submenu .sidebar-sublink {
    display: flex;
    align-items: center;
    padding: 0.45rem 1.5rem 0.45rem 3.25rem;
    color: #8888a8;
    text-decoration: none;
    font-size: 0.825rem;
    transition: all 0.2s;
}

.sidebar-submenu .sidebar-sublink:hover,
.sidebar-submenu .sidebar-sublink.active {
    color: #fff;
}

.sidebar-submenu .sidebar-sublink.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.sidebar-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
    margin-bottom: 0.75rem;
}

.sidebar-user strong {
    display: block;
    color: #fff;
    font-size: 0.875rem;
}

.sidebar-user small {
    color: #8888a8;
    font-size: 0.75rem;
}

/* ─── Main area ────────────────────────────────────────────── */
.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.main-header {
    display: none;
    background: #fff;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    align-items: center;
    gap: 0.75rem;
}

.main-header .btn-toggle {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #333;
    padding: 0.25rem;
}

.main-content {
    padding: 1.5rem;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
}

@media (max-width: 767.98px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .sidebar.show ~ .sidebar-overlay {
        display: block;
    }
    .main-wrapper {
        margin-left: 0;
    }
    .main-header {
        display: flex;
    }
}

/* ─── Page header ──────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a2e;
    margin: 0;
}

/* ─── Cards ────────────────────────────────────────────────── */
.card {
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* ─── Tables ───────────────────────────────────────────────── */
.table-modern {
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
}

.table-modern thead th {
    background: #f8f9fa;
    border-bottom: 2px solid #e2e8f0;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
    padding: 0.75rem 1rem;
}

.table-modern tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid #f0f0f0;
}

.table-modern tbody tr:hover {
    background: #f8f9fc;
}

/* ─── Badges de nível ──────────────────────────────────────── */
.badge-nivel {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.35em 0.75em;
    border-radius: 50rem;
}

.badge-administrador {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

.badge-gestor {
    background: rgba(13, 110, 253, 0.1);
    color: #0d6efd;
}

.badge-junior {
    background: rgba(108, 117, 125, 0.1);
    color: #6c757d;
}

/* ─── Stat cards ───────────────────────────────────────────── */
.stat-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.75rem;
    font-size: 1.25rem;
}

/* ─── Badges de canal ─────────────────────────────────────── */
.badge-canal {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.35em 0.75em;
    border-radius: 50rem;
}

.badge-whatsapp {
    background: rgba(37, 211, 102, 0.1);
    color: #25d366;
}

.badge-instagram {
    background: rgba(225, 48, 108, 0.1);
    color: #e1306c;
}

/* ─── Badges de status de conexão ─────────────────────────── */
.badge-status {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.3em 0.65em;
    border-radius: 50rem;
}

.badge-conectado {
    background: rgba(25, 135, 84, 0.1);
    color: #198754;
}

.badge-desconectado {
    background: rgba(108, 117, 125, 0.1);
    color: #6c757d;
}

.badge-conectando {
    background: rgba(255, 193, 7, 0.15);
    color: #cc9a06;
}

.badge-erro {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

.badge-nao-configurado {
    background: rgba(108, 117, 125, 0.06);
    color: #adb5bd;
}

/* ─── Channel card selection ──────────────────────────────── */
.channel-card {
    cursor: pointer;
    border: 2px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.25rem;
    text-align: center;
    transition: all 0.2s;
}

.channel-card:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.03);
}

.channel-card.selected {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.06);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.channel-card i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* ─── Form floating fix ───────────────────────────────────── */
.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* ─── Chat layout ─────────────────────────────────────────── */
.chat-container {
    display: flex;
    height: calc(100vh - 140px);
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    background: #fff;
}

.chat-sidebar {
    width: 320px;
    min-width: 320px;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.chat-sidebar-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-conversation-list {
    flex: 1;
    overflow-y: auto;
}

.chat-conversation-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.15s;
    cursor: pointer;
}

.chat-conversation-item:hover {
    background: #f8f9fc;
    color: inherit;
}

.chat-conversation-item.active {
    background: rgba(102, 126, 234, 0.08);
    border-left: 3px solid #667eea;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #e9ecef;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #6c757d;
    flex-shrink: 0;
}

.chat-conversation-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chat-contact-name {
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    display: inline-block;
}

.chat-time {
    font-size: 0.7rem;
    color: #adb5bd;
    white-space: nowrap;
}

.chat-preview {
    font-size: 0.8rem;
    color: #8c8c8c;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
    display: inline-block;
}

.chat-unread-badge {
    background: #667eea;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 50rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    flex-shrink: 0;
}

/* Chat main area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #f0f2f5;
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chat-header {
    padding: 0.75rem 1.25rem;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.chat-bubble {
    max-width: 65%;
    padding: 0.55rem 0.85rem;
    border-radius: 0.65rem;
    position: relative;
    word-wrap: break-word;
}

.chat-bubble-received {
    background: #fff;
    align-self: flex-start;
    border-top-left-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}

.chat-bubble-sent {
    background: #d9fdd3;
    align-self: flex-end;
    border-top-right-radius: 4px;
}

.chat-bubble-text {
    font-size: 0.875rem;
    line-height: 1.4;
    white-space: pre-wrap;
}

.chat-bubble-time {
    font-size: 0.65rem;
    color: #8c8c8c;
    text-align: right;
    margin-top: 2px;
}

.chat-input {
    padding: 0.75rem 1.25rem;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.chat-send-btn {
    width: 46px;
    height: 38px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

@media (max-width: 767.98px) {
    .chat-container {
        flex-direction: column;
        height: calc(100vh - 120px);
    }

    .chat-sidebar {
        width: 100%;
        min-width: 0;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }

    .chat-bubble {
        max-width: 85%;
    }
}