@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

/* Variáveis do Sistema de Design */
:root {
    --bg-primary: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active: #6366f1;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --accent: #6366f1;
    --border: #e2e8f0;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-primary);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    font-weight: 600;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--primary-dark);
}

/* Estrutura do Layout de Dashboard */
.app-container {
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar */
.app-sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    z-index: 100;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #1e293b;
}

.logo-text {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 800;
    background: linear-gradient(135deg, #a5b4fc, #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-menu {
    list-style: none;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
}

.menu-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--sidebar-text);
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s ease;
}

.menu-item a:hover {
    background-color: #1e293b;
    color: #ffffff;
}

.menu-item.active a {
    background-color: var(--sidebar-active);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid #1e293b;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--sidebar-text);
}

.sidebar-footer .user-info {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-name {
    font-weight: 600;
    color: #ffffff;
}

.user-role {
    font-size: 11px;
    background-color: #334155;
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 2px;
    display: inline-block;
}

/* Área de Conteúdo Principal */
.app-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Topbar */
.app-topbar {
    height: 70px;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    box-shadow: var(--shadow-sm);
}

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

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Botões do Sistema */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--primary));
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.3);
    color: #ffffff;
}

.btn-secondary {
    background-color: #e2e8f0;
    color: #334155;
}

.btn-secondary:hover {
    background-color: #cbd5e1;
}

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

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-success {
    background-color: var(--success);
    color: #ffffff;
}

.btn-success:hover {
    background-color: #059669;
}

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

/* Dashboard Grid */
.dashboard-grid {
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.metrics-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-metrics {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.metric-data h3 {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.metric-data p {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 800;
    color: var(--text-main);
}

.metric-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.metric-icon.indigo {
    background-color: rgba(99, 102, 241, 0.1);
    color: var(--accent);
}

.metric-icon.amber {
    background-color: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.metric-icon.blue {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.metric-icon.emerald {
    background-color: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

/* Dashboard Seções */
.sections-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

@media (max-width: 1024px) {
    .sections-row {
        grid-template-columns: 1fr;
    }
}

.section-title {
    font-size: 18px;
    margin-bottom: 20px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Tabelas */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table-custom {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.table-custom th {
    padding: 14px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    background-color: #fafafa;
}

.table-custom td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
}

.table-custom tr:hover {
    background-color: rgba(248, 250, 252, 0.5);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
}

.badge-aberto {
    background-color: #fef3c7;
    color: #d97706;
}

.badge-andamento {
    background-color: #dbeafe;
    color: #2563eb;
}

.badge-encerrado {
    background-color: #d1fae5;
    color: #059669;
}

.badge-alta {
    background-color: #fee2e2;
    color: #dc2626;
}

.badge-media {
    background-color: #ffedd5;
    color: #ea580c;
}

.badge-baixa {
    background-color: #f1f5f9;
    color: #475569;
}

.badge-ativo {
    background-color: #d1fae5;
    color: #059669;
}

.badge-inativo {
    background-color: #fee2e2;
    color: #dc2626;
}

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

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

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--text-main);
    background-color: #ffffff;
    transition: all 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Grid de Filtros */
.filters-card {
    background-color: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 20px;
    margin-bottom: 24px;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    align-items: flex-end;
}

/* Timeline / Chat do Chamado */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 500px;
    background-color: #f1f5f9;
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.chat-messages {
    flex-grow: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-bubble {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 16px;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
    position: relative;
    word-break: break-word;
}

/* Remetentes do chat */
.chat-bubble.cliente {
    align-self: flex-end;
    background-color: var(--primary);
    color: #ffffff;
    border-bottom-right-radius: 2px;
}

.chat-bubble.tecnico {
    align-self: flex-start;
    background-color: #ffffff;
    color: var(--text-main);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
}

.chat-bubble.admin {
    align-self: flex-start;
    background-color: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
    border-bottom-left-radius: 2px;
}

.bubble-meta {
    font-size: 11px;
    margin-bottom: 4px;
    font-weight: 600;
}

.bubble-time {
    display: block;
    text-align: right;
    font-size: 10px;
    margin-top: 6px;
    opacity: 0.8;
}

.chat-input-bar {
    background-color: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 16px;
}

.chat-input-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-textarea-row {
    display: flex;
    gap: 12px;
}

.chat-textarea-row textarea {
    flex-grow: 1;
    resize: none;
    height: 50px;
}

/* Anexos */
.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: rgba(255, 255, 255, 0.15);
    color: inherit;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    margin-top: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.chat-bubble.tecnico .attachment-link,
.chat-bubble.admin .attachment-link {
    background-color: #f1f5f9;
    color: var(--primary);
    border: 1px solid var(--border);
}

.attachment-link:hover {
    background-color: rgba(255, 255, 255, 0.25);
}

.chat-bubble.tecnico .attachment-link:hover,
.chat-bubble.admin .attachment-link:hover {
    background-color: #e2e8f0;
}

/* Lista de anexos na info do chamado */
.attachment-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.attachment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background-color: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}

/* Base de Conhecimento */
.kb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

.kb-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kb-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.kb-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.kb-tag {
    font-size: 11px;
    background-color: #f1f5f9;
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Login - Glassmorphism */
.login-body {
    background: radial-gradient(circle at 0% 0%, #1e1b4b 15%, #0f172a 80%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-wrapper {
    width: 100%;
    max-width: 440px;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 10px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    color: #ffffff;
}

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

.login-logo {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #a5b4fc, #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-subtitle {
    font-size: 14px;
    color: #94a3b8;
}

.login-wrapper .form-label {
    color: #94a3b8;
}

.login-wrapper .form-control {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.login-wrapper .form-control:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.25);
    background-color: rgba(255, 255, 255, 0.08);
}

.alert-message {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-danger {
    background-color: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.alert-success {
    background-color: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: #a7f3d0;
}

/* Responsividade Mobile */
@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
    }

    .app-sidebar.active {
        left: 0;
    }

    .menu-toggle {
        display: block;
    }

    .app-topbar {
        padding: 0 20px;
    }

    .dashboard-grid {
        padding: 20px;
    }

    .chat-bubble {
        max-width: 90%;
    }
}

/* --- ALINHAMENTO DO CHAT PERSONALIZADO (MENSAGENS ENVIADAS À ESQUERDA, RECEBIDAS À DIREITA) --- */
.chat-bubble.msg-enviada {
    align-self: flex-start !important;
    border-bottom-left-radius: 2px !important;
    border-bottom-right-radius: 16px !important;
}

.chat-bubble.msg-recebida {
    align-self: flex-end !important;
    border-bottom-right-radius: 2px !important;
    border-bottom-left-radius: 16px !important;
}

/* --- CARDS DE ANEXOS NA TIMELINE --- */
.chat-bubble-attachments {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
    width: 100%;
}

.chat-attachment-card {
    display: flex;
    flex-direction: column;
    background-color: rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.15);
    max-width: 280px;
    width: 100%;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease;
}

.chat-attachment-card:hover {
    transform: translateY(-2px);
}

.chat-bubble.tecnico .chat-attachment-card,
.chat-bubble.admin .chat-attachment-card {
    background-color: #f8fafc;
    border: 1px solid var(--border);
}

.chat-attachment-preview {
    position: relative;
    width: 100%;
    height: 150px;
    background-color: #0f172a;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
}

.chat-attachment-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.chat-attachment-preview:hover img {
    transform: scale(1.04);
}

.preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.4);
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 20px;
    transition: opacity 0.2s ease;
}

.chat-attachment-preview:hover .preview-overlay {
    opacity: 1;
}

.video-placeholder {
    font-size: 40px;
    color: #ffffff;
}

.video-play-icon {
    font-size: 44px;
    color: rgba(255, 255, 255, 0.85);
    transition: transform 0.2s ease, color 0.2s ease;
    z-index: 2;
}

.chat-attachment-preview:hover .video-play-icon {
    transform: scale(1.1);
    color: #ffffff;
}

.chat-attachment-info {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background-color: rgba(0, 0, 0, 0.03);
}

.chat-attachment-name {
    font-size: 12px;
    font-weight: 500;
    color: inherit;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

.chat-attachment-actions {
    display: flex;
    gap: 8px;
}

.btn-attachment-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background-color: rgba(255, 255, 255, 0.2);
    color: inherit !important;
    border: 1px solid rgba(255, 255, 255, 0.25);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.chat-bubble.tecnico .btn-attachment-action,
.chat-bubble.admin .btn-attachment-action {
    background-color: #ffffff;
    border: 1px solid var(--border);
    color: var(--text-main) !important;
}

.btn-attachment-action:hover {
    background-color: rgba(255, 255, 255, 0.35);
}

.chat-bubble.tecnico .btn-attachment-action:hover,
.chat-bubble.admin .btn-attachment-action:hover {
    background-color: #f1f5f9;
}

/* Generic file attachment card */
.chat-attachment-card.generic-attachment {
    flex-direction: row;
    align-items: center;
    padding: 10px;
    max-width: 320px;
}

.chat-attachment-icon-wrapper {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: inherit;
    flex-shrink: 0;
}

.chat-bubble.tecnico .chat-attachment-icon-wrapper,
.chat-bubble.admin .chat-attachment-icon-wrapper {
    background-color: #e2e8f0;
    color: var(--primary);
}

.chat-attachment-card.generic-attachment .chat-attachment-info {
    flex-grow: 1;
    min-width: 0;
    padding: 0 0 0 10px;
    background: none;
}

/* --- PREVIEW DE UPLOAD ACIMA DO INPUT --- */
#preview-upload-container {
    animation: slideDownPreview 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDownPreview {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.preview-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-thumb-icon {
    font-size: 20px;
    color: var(--text-muted);
}

/* --- MODAL LIGHTBOX DE VISUALIZAÇÃO DE MÍDIA --- */
.media-viewer-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.media-viewer-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(6px);
}

.media-viewer-content {
    position: relative;
    background-color: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    z-index: 10000;
    overflow: hidden;
    animation: fadeInModal 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInModal {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.media-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 16px;
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 80%;
}

.media-close-btn {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s ease;
    line-height: 1;
}

.media-close-btn:hover {
    color: var(--danger);
}

.media-viewer-body {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background-color: #0f172a;
    max-height: 60vh;
    overflow: hidden;
}

.media-viewer-body img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.media-viewer-body video {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
}

.media-viewer-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}