/* =====================================================
   Aistem RH - Stylesheet Principal
   ===================================================== */

:root {
    --primary: #dc2626;
    --primary-dark: #991b1b;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #6b7280;
    --dark: #1e293b;
    --light: #f9fafb;
    --border: #e5e7eb;
    --text: #374151;
    --text-muted: #9ca3af;
    --sidebar-width: 260px;
    --header-height: 60px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f3f4f6;
    color: var(--text);
    line-height: 1.5;
}

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

/* =====================================================
   Login
   ===================================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    padding: 20px;
}

.login-box {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    padding: 40px;
}

.login-brand {
    text-align: center;
    margin-bottom: 32px;
}

.login-brand i {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 12px;
}

.login-brand h1 {
    font-size: 24px;
    color: var(--dark);
    margin-bottom: 4px;
}

.login-brand p {
    color: var(--text-muted);
    font-size: 14px;
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--dark);
}

.login-form input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    transition: border-color .2s, box-shadow .2s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(220,38,38,0.1);
}

.input-password {
    position: relative;
}

.input-password input { padding-right: 44px; }

.toggle-password {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
}

.login-message {
    margin-top: 16px;
    padding: 12px;
    border-radius: var(--radius);
    font-size: 14px;
    text-align: center;
    display: none;
}

.login-message.success { background: #d1fae5; color: #065f46; display: block; }
.login-message.error { background: #fee2e2; color: #991b1b; display: block; }

/* =====================================================
   Layout
   ===================================================== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--dark);
    color: #d1d5db;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: transform .3s;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: #fff;
    font-weight: 700;
    font-size: 18px;
}

.sidebar-brand i { font-size: 24px; color: var(--primary); }

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.nav-section {
    padding: 16px 20px 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #64748b;
    font-weight: 600;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: #9ca3af;
    font-size: 14px;
    transition: all .2s;
    border-left: 3px solid transparent;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(255,255,255,0.05);
    color: #fff;
    border-left-color: var(--primary);
}

.nav-link i { width: 20px; text-align: center; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.05);
    padding: 8px 0;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-header {
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    font-weight: 500;
    font-size: 14px;
}

.user-badge {
    font-size: 11px;
    padding: 2px 10px;
    border-radius: 20px;
    font-weight: 600;
    text-transform: uppercase;
}

.user-badge.perfil-super_admin { background: #fef3c7; color: #92400e; }
.user-badge.perfil-administrador { background: #fee2e2; color: #991b1b; }
.user-badge.perfil-operador { background: #d1fae5; color: #065f46; }

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

/* =====================================================
   Página
   ===================================================== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--dark);
}

.page-header h1 i { color: var(--primary); margin-right: 8px; }

.text-muted { color: var(--text-muted); }

/* =====================================================
   Cards & Stats
   ===================================================== */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.card-header h3 i { color: var(--primary); margin-right: 8px; }

.card-body { padding: 20px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    flex-shrink: 0;
}

.bg-primary { background: var(--primary); }
.bg-success { background: var(--success); }
.bg-danger { background: var(--danger); }
.bg-warning { background: var(--warning); color: #fff; }
.bg-info { background: var(--info); }
.bg-secondary { background: var(--secondary); }

.stat-number {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--dark);
    line-height: 1;
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
}

/* =====================================================
   Botões
   ===================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity .2s, transform .1s;
    line-height: 1.5;
}

.btn:hover { opacity: .9; }
.btn:active { transform: scale(.98); }

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

.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* =====================================================
   Formulários
   ===================================================== */
.form-group {
    margin-bottom: 16px;
}

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    transition: border-color .2s, box-shadow .2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(220,38,38,0.08);
}

.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.form-row .form-group { flex: 1; min-width: 200px; }

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

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

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400 !important;
    cursor: pointer;
}

.form-message {
    margin-top: 16px;
    padding: 12px;
    border-radius: var(--radius);
    font-size: 14px;
    display: none;
}

.form-message.success { background: #d1fae5; color: #065f46; display: block; }
.form-message.error { background: #fee2e2; color: #991b1b; display: block; }

/* =====================================================
   Tabelas
   ===================================================== */
.table-responsive { overflow-x: auto; }

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

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

.table th {
    font-weight: 600;
    color: var(--dark);
    background: #f9fafb;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .3px;
}

.table tr:hover td { background: #f9fafb; }

/* =====================================================
   Badges
   ===================================================== */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge.perfil-super_admin { background: #fef3c7; color: #92400e; }
.badge.perfil-administrador { background: #fee2e2; color: #991b1b; }
.badge.perfil-operador { background: #d1fae5; color: #065f46; }

.badge.status-ativo { background: #d1fae5; color: #065f46; }
.badge.status-inativo { background: #fee2e2; color: #991b1b; }

/* =====================================================
   Ações rápidas
   ===================================================== */
.quick-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* =====================================================
   Erros
   ===================================================== */
.error-page {
    text-align: center;
    padding: 60px 20px;
}

.error-code {
    font-size: 96px;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 16px;
}

.error-page h1 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--dark);
}

.error-page p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* =====================================================
   Badges extras
   ===================================================== */
.badge.prioridade-baixa { background: #d1fae5; color: #065f46; }
.badge.prioridade-media { background: #fee2e2; color: #991b1b; }
.badge.prioridade-alta { background: #fef3c7; color: #92400e; }
.badge.prioridade-urgente { background: #fee2e2; color: #991b1b; }

.badge.status-aberta { background: #d1fae5; color: #065f46; }
.badge.status-pausada { background: #fef3c7; color: #92400e; }
.badge.status-encerrada { background: #e5e7eb; color: #4b5563; }

.badge.origem-web { background: #fee2e2; color: #991b1b; }
.badge.origem-whatsapp { background: #d1fae5; color: #065f46; }
.badge.origem-email { background: #fef3c7; color: #92400e; }
.badge.origem-manual { background: #e5e7eb; color: #4b5563; }
.badge.origem-portaria { background: #fce7f3; color: #9d174d; }
.badge.origem-indicacao_interna { background: #ddd6fe; color: #5b21b6; }

.badge.canal-whatsapp { background: #d1fae5; color: #065f46; }
.badge.canal-email { background: #fee2e2; color: #991b1b; }

.badge.status-enviado { background: #d1fae5; color: #065f46; }
.badge.status-pendente { background: #fef3c7; color: #92400e; }
.badge.status-falhou { background: #fee2e2; color: #991b1b; }
.badge.status-enviando { background: #fee2e2; color: #991b1b; }
.badge.status-reenvio_solicitado { background: #fce7f3; color: #9d174d; }

/* =====================================================
   Ficha 360º
   ===================================================== */
.ficha-360 { display: grid; gap: 20px; }

.ficha-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.ficha-item label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .3px;
    margin-bottom: 4px;
}

.ficha-item span {
    font-size: 15px;
    font-weight: 500;
    color: var(--dark);
}

/* =====================================================
   Timeline
   ===================================================== */
.timeline {
    position: relative;
    padding-left: 24px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 20px;
}

.timeline-dot {
    position: absolute;
    left: -22px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px var(--primary);
}

.timeline-content strong {
    display: block;
    font-size: 14px;
    color: var(--dark);
}

.timeline-content small {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.timeline-content p {
    font-size: 13px;
    color: var(--text);
    background: #f9fafb;
    padding: 8px;
    border-radius: var(--radius);
}

/* =====================================================
   Responsivo
   ===================================================== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .quick-actions { flex-direction: column; }
    .quick-actions .btn { width: 100%; justify-content: center; }
}


/* =====================================================
   Kanban Pipeline
   ===================================================== */
.kanban-board {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 16px;
    min-height: 500px;
}

.kanban-column {
    min-width: 280px;
    max-width: 320px;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-top: 4px solid var(--border);
}

.kanban-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.kanban-title-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.kanban-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kanban-vaga-badge {
    font-size: 11px;
    background: #f3f4f6;
    padding: 2px 8px;
    border-radius: 9999px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.kanban-count {
    background: var(--light);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 9999px;
    min-width: 24px;
    text-align: center;
}

.kanban-actions .btn-link {
    color: var(--text-muted);
    padding: 2px 6px;
}

.kanban-body {
    padding: 10px;
    flex: 1;
    overflow-y: auto;
    max-height: calc(100vh - 280px);
    min-height: 120px;
}

.kanban-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 24px 8px;
}

.kanban-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
    cursor: grab;
    transition: box-shadow 0.15s, transform 0.1s;
}

.kanban-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    border-color: #d1d5db;
}

.kanban-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.kanban-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.kanban-card-header strong {
    font-size: 13px;
    color: var(--dark);
}

.kanban-card-meta > div {
    margin-bottom: 2px;
}

.kanban-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.kanban-card-link {
    color: var(--text-muted);
    margin-left: 8px;
}

.kanban-card-link:hover {
    color: var(--primary);
}

.kanban-template-tag {
    color: var(--primary);
    font-size: 11px;
    cursor: help;
}

.kanban-column.drag-over .kanban-body {
    background: #fef2f2;
    border-radius: 0 0 var(--radius) var(--radius);
}


/* =====================================================
   Modal Pipeline - Editar Etapa
   ===================================================== */
.template-check-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding-right: 4px;
}

.template-check-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.template-check-item:hover {
    border-color: var(--primary);
    background: #fef2f2;
}

.template-check-item input[type="checkbox"] {
    margin-top: 3px;
    flex-shrink: 0;
    accent-color: var(--primary);
}

.template-check-body {
    flex: 1;
    min-width: 0;
}

.template-check-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--dark);
    margin-bottom: 4px;
    word-break: break-word;
}

.badge.canal-whatsapp { background: #10b981; color: #fff; }
.badge.canal-email { background: #3b82f6; color: #fff; }

.modal-header .modal-title {
    font-weight: 600;
}

.form-control-color {
    height: 38px;
    padding: 4px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
}


/* =====================================================
   Drag & Drop fixes com Bootstrap
   ===================================================== */
.kanban-card {
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
.kanban-card:active {
    cursor: grabbing;
}
.kanban-card.dragging {
    opacity: 0.4;
    cursor: grabbing;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.kanban-column.drag-over .kanban-body {
    background: #fef2f2 !important;
    outline: 2px dashed var(--primary);
    outline-offset: -2px;
}
