/* =========================================
   1. VARIABLES & TEMAS (Design System Original)
   ========================================= */
   :root {
    /* --- PALETA GLOBAL SISTEMA --- */
    --header-bg: #1e293b;         /* Azul oscuro profundo (CRM Style) */
    --header-text: #f8fafc;       /* Texto blanco */
    --brand-color: #2563eb;       /* Azul primario vibrante */
    
    /* Dimensiones */
    --sidebar-width: 260px;
    --header-height: 60px;
    --transition-speed: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* --- TEMA CLARO (Default) --- */
    --bg-body: #f3f4f6;           /* Gris azulado muy suave (Coincide con BG) */
    --bg-surface: #ffffff;        /* Blanco puro */
    --bg-sidebar: #ffffff;
    --text-main: #111827;         /* Gris oscuro casi negro */
    --text-muted: #6b7280;        /* Gris medio */
    --border-color: #e5e7eb;
    --input-bg: #ffffff;
    --input-border: #d1d5db;

    /* Footer */
    --bg-footer: #e5e7eb;
    --text-footer: #6b7280;
    --footer-height: 60px; 
    
    /* Sombras (Mejoradas para profundidad) */
    --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);
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* --- COLORES DASHBOARD (Integrados) --- */
    --c-green: #10b981; --c-green-light: #ecfdf5;
    --c-blue: #3b82f6;  --c-blue-light: #eff6ff;
    --c-teal: #14b8a6;  --c-teal-light: #f0fdfa;
    --c-orange: #f97316; --c-orange-light: #fff7ed;
    --c-red: #ef4444;    --c-red-light: #fef2f2;

    --sidebar-width-collapsed: 80px; 
}

[data-theme="dark"] {
    --brand-color: #3b82f6;
    --bg-body: #0f172a;
    --bg-surface: #1e293b;
    --bg-sidebar: #1e293b;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border-color: #374151;
    --input-bg: #111827;
    --input-border: #4b5563;
    --bg-footer: #0f172a;  
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.5);

    --c-green-light: rgba(16, 185, 129, 0.1);
    --c-blue-light: rgba(59, 130, 246, 0.1);
    --c-teal-light: rgba(20, 184, 166, 0.1);
    --c-orange-light: rgba(249, 115, 22, 0.1);
    --c-red-light: rgba(239, 68, 68, 0.1);
}

/* =========================================
   2. RESET & ESTRUCTURA BASICA
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.5;
    overflow-x: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

a { text-decoration: none; color: inherit; transition: 0.2s; }
ul { list-style: none; }
img { max-width: 100%; display: block; }

/* =========================================
   3. HEADER (Z-Index Corregido para Mapa)
   ========================================= */
.app-header {
    height: var(--header-height);
    background-color: var(--header-bg);
    color: var(--header-text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: fixed;
    top: 0; left: 0; right: 0;
    
    /* CORRECCIÓN: Z-Index alto para que el mapa no pase por encima */
    z-index: 1000 !important;
    
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-left { 
    display: flex; 
    align-items: center; 
    gap: 16px; 
    width: var(--sidebar-width) !important; 
    padding-left: 20px; 
    height: 100%;
    flex-shrink: 0;
}

.btn-hamburger {
    background: transparent; border: none; color: var(--header-text);
    cursor: pointer; padding: 8px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
}
.btn-hamburger:hover { background-color: rgba(255,255,255,0.1); }

.app-logo {
    font-size: 20px; font-weight: 700; letter-spacing: -0.5px;
    color: #fff; white-space: nowrap;
}

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

/* User Dropdown */
.user-dropdown-container { position: relative; }

.user-trigger {
    display: flex; align-items: center; gap: 10px; cursor: pointer;
    padding: 6px 12px; border-radius: var(--radius-lg);
    transition: background 0.2s; user-select: none;
}
.user-trigger:hover { background-color: rgba(255,255,255,0.1); }

.user-avatar {
    width: 32px; height: 32px; background: var(--brand-color); color: white;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 14px;
}
.user-info { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.user-name { font-weight: 500; font-size: 13px; }
.user-role { font-size: 11px; opacity: 0.8; }

.user-dropdown-menu {
    position: absolute; top: 120%; right: 0; width: 220px;
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    padding: 8px 0; opacity: 0; visibility: hidden;
    transform: translateY(-10px); transition: all 0.2s ease; z-index: 1100;
}
.user-dropdown-menu.active { opacity: 1; visibility: visible; transform: translateY(0); }

.dropdown-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px;
    color: var(--text-main); font-size: 14px;
}
.dropdown-item:hover { background-color: var(--bg-body); color: var(--brand-color); }
.dropdown-divider { height: 1px; background: var(--border-color); margin: 6px 0; }

/* =========================================
   4. BREADCRUMB
   ========================================= */
.breadcrumb { margin-bottom: 24px; }

.breadcrumb ul {
    display: flex; flex-wrap: wrap; align-items: baseline;
    gap: 8px; padding: 0; margin: 0;
}

.breadcrumb-item {
    display: flex; align-items: center; font-size: 13px; color: var(--text-muted);
}
.breadcrumb a { color: var(--text-muted); transition: color 0.2s; }
.breadcrumb a:hover { color: var(--brand-color); text-decoration: underline; }

.breadcrumb-item:not(:last-child)::after {
    content: "›"; margin-left: 8px; font-size: 14px;
    color: var(--text-muted); opacity: 0.5; position: relative; top: 1px;
}

.breadcrumb-item:last-child {
    font-size: 24px; font-weight: 700; color: var(--text-main); margin-left: 4px;
}

/* =========================================
   5. SIDEBAR & LAYOUT (Z-Index Corregido)
   ========================================= */
.app-container {
    display: flex; padding-top: var(--header-height);
    min-height: 100vh; position: relative; overflow-x: hidden;
}

/* Contenido Principal */
.app-content {
    flex: 1; margin-left: var(--sidebar-width);
    display: flex; flex-direction: column;
    min-height: calc(100vh - var(--header-height));
    transition: margin-left var(--transition-speed); 
    padding: 0; 
    width: 100%;
}

.app-page-body {
    flex: 1; padding: 24px; width: 100%;
}

/* Footer Sticky */
.app-footer {
    height: var(--footer-height);
    background-color: var(--bg-footer);
    border-top: 1px solid var(--border-color);
    padding: 0 20px;
    margin-top: auto;
    display: flex; align-items: center; justify-content: center;
}

.footer-content {
    font-size: 12px; color: var(--text-muted); font-weight: 500;
    display: flex; justify-content: center; gap: 10px;
}

/* Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    
    /* CORRECCIÓN: Z-Index medio para que tape al mapa pero no al header */
    z-index: 900 !important;
    
    display: flex; flex-direction: column; justify-content: space-between;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap; overflow: hidden; padding: 0;
}

.sidebar-content {
    padding: 20px 12px;
    flex: 1; overflow-y: auto; overflow-x: hidden;
}

/* --- ITEM DEL MENÚ --- */
.menu { 
  display: flex; 
  flex-direction: column; 
  gap: 4px; 
  padding: 0; 
  margin: 0; 
}

.menu-item { display: block; }

.menu-item a {
  display: flex;
  align-items: center;
  justify-content: flex-start; /* Siempre alineado a la izquierda */
  text-decoration: none;
  height: 44px; /* Altura fija del botón */
  
  /* PADDING: Ajustado para dar aire */
  padding: 0 12px; 
  
  margin: 0; 
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: 500;
  position: relative;
  width: 100%;
  overflow: hidden; /* Corta el texto largo */
  
  transition: background-color 0.2s, color 0.2s;
}

.menu-item a:hover, .menu-item a.active {
  background-color: var(--bg-body);
  color: var(--brand-color);
}

/* ICONO: Corregido para evitar cortes */
.menu-icon {
  /* Dimensiones fijas estrictas */
  width: 24px;
  min-width: 24px; 
  height: 24px;
  
  /* Centrado interno del SVG */
  display: flex;
  align-items: center;
  justify-content: center;
  
  /* Espacio fijo a la derecha para separar del texto */
  margin-right: 12px; 
  
  /* CRÍTICO: Impide que el flexbox lo aplaste */
  flex-shrink: 0; 
}

/* TEXTO: Se desvanece suavemente */
.menu-text {
  opacity: 1;
  transition: opacity 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
    height: var(--footer-height); border-top: 1px solid var(--border-color);
    display: flex; align-items: center; padding: 0 16px;
    justify-content: flex-end; background-color: var(--bg-sidebar);
}
.btn-collapse {
    background: transparent; border: none; color: var(--text-muted);
    cursor: pointer; padding: 8px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.3s;
}
.btn-collapse:hover { background-color: var(--bg-body); color: var(--brand-color); }

/* Sidebar Colapsado */
body.sidebar-collapsed .app-sidebar { width: var(--sidebar-width-collapsed); }
body.sidebar-collapsed .app-content { margin-left: var(--sidebar-width-collapsed); }
body.sidebar-collapsed .menu-text { opacity: 0; pointer-events: none; }
body.sidebar-collapsed .btn-collapse { margin-left: 0; transform: rotate(180deg); }


/* =========================================
   6. UTILIDADES DE ALINEACIÓN & SEARCH GROUP (CRÍTICO)
   ========================================= */

/* Header de la página */
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 24px; flex-wrap: wrap; gap: 16px; min-height: 40px;
}
.page-actions {
    display: flex; align-items: center; gap: 12px; margin-left: auto;
}

/* --- ESTILOS DEL BUSCADOR RESTAURADOS --- */
.search-group { display: flex; align-items: stretch; }

.input-search-left {
    border-top-right-radius: 0; border-bottom-right-radius: 0; border-right: 0;
    width: 200px; transition: width 0.3s;
}
.input-search-left:focus { width: 240px; z-index: 2; }

.btn-search-right {
    border-top-left-radius: 0; border-bottom-left-radius: 0;
    background-color: var(--bg-surface); border: 1px solid var(--input-border);
    color: var(--text-muted);
    display: flex; align-items: center; padding: 0 12px; /* Asegura centrado */
}
.btn-search-right:hover { color: var(--brand-color); background: var(--bg-body); }

/* Footer de Formulario */
.actions {
    display: flex; justify-content: flex-end; align-items: center;
    gap: 12px; margin-top: 32px; padding-top: 24px;
    border-top: 1px solid var(--border-color);
}


/* =========================================
   7. COMPONENTES UI (General)
   ========================================= */
.card {
    background: var(--bg-surface); 
    border-radius: var(--radius-md);
    /* Sombra original que te gusta */
    box-shadow: var(--shadow-card); 
    border: 1px solid var(--border-color);
    padding: 24px; margin-bottom: 24px;
    transition: box-shadow 0.2s ease-in-out, transform 0.2s ease-in-out;
}

/* Opcional hover */
.dashboard-cards .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.input, .form-control, select, textarea {
    width: 100%; padding: 10px 12px; background-color: var(--input-bg);
    border: 1px solid var(--input-border); border-radius: var(--radius-sm);
    color: var(--text-main); font-size: 14px; transition: border 0.2s, box-shadow 0.2s;
}
.input:focus, .form-control:focus, select:focus {
    outline: none; border-color: var(--brand-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* CORRECCIONES DARK MODE INPUTS */
[data-theme="dark"] .input,
[data-theme="dark"] .form-control,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background-color: var(--bg-body); color: var(--text-main); border-color: var(--border-color);
}
[data-theme="dark"] .input::placeholder,
[data-theme="dark"] textarea::placeholder { color: var(--text-muted); }


.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px; border-radius: var(--radius-sm);
    font-weight: 500; font-size: 13px; cursor: pointer;
    border: 1px solid var(--border-color); transition: all 0.2s;
    background-color: var(--bg-surface); color: var(--text-main);
}
.btn:hover { background-color: var(--bg-body); }
.btn-primary { background-color: var(--brand-color); color: #fff; border-color: transparent; }
.btn-primary:hover { filter: brightness(1.1); background-color: var(--brand-color); }
.btn-danger { background-color: #ef4444; color: white; border-color: transparent; }
.btn-success { background-color: #10b981; color: white; border-color: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
    background: var(--bg-body); text-align: left; padding: 12px 16px;
    font-size: 12px; text-transform: uppercase; color: var(--text-muted);
    font-weight: 600; border-bottom: 1px solid var(--border-color);
}
.table td {
    padding: 14px 16px; border-bottom: 1px solid var(--border-color);
    color: var(--text-main); font-size: 14px;
}
.table tr:last-child td { border-bottom: none; }
[data-theme="dark"] .table th { background-color: var(--bg-surface); color: var(--text-muted); }


/* Grid Helper */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }
.table-responsive { width: 100%; overflow-x: auto; border: 1px solid var(--border-color); border-radius: var(--radius-sm); }
.badge { display: inline-block; padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 500; background-color: var(--bg-body); border: 1px solid var(--border-color); color: var(--text-muted); }

/* UTILIDADES PARA VISTAS EJS (Restauradas) */
.form-section {
    background-color: var(--bg-body); 
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.03); 
}
.form-section-title {
    margin-top: 0; margin-bottom: 16px; font-size: 16px;
    font-weight: 600; color: var(--text-main);
}
.divider { border: 0; border-top: 1px solid var(--border-color); margin: 24px 0; }

/* =========================================
   8. LOGIN PAGE
   ========================================= */
.login-wrapper {
  min-height: 100vh; width: 100%; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2c7bb6 0%, #1e5799 100%);
}
.login-card {
  background: #ffffff; width: 100%; max-width: 400px; padding: 40px 30px;
  border-radius: 12px; 
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  text-align: center;
}
.login-header h2 { color: #334155; font-size: 24px; font-weight: 700; margin-bottom: 25px; }
.btn-login {
  width: 100%; padding: 12px; margin-top: 10px; background-color: #1e73be; 
  color: #ffffff; font-size: 16px; font-weight: 600; border: none; border-radius: 6px; cursor: pointer;
}
.alert-error {
  background-color: #fee2e2; color: #dc2626; padding: 10px; border-radius: 6px; margin-bottom: 20px; border: 1px solid #fecaca;
}

/* =========================================
   9. DASHBOARD (Restaurado)
   ========================================= */
.dashboard-container { width: 100%; max-width: 1600px; margin: 0 auto; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; padding-bottom: 10px; }
.section-header h3 { font-size: 18px; font-weight: 700; color: var(--text-main); margin: 0; }
.section-container {
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: 12px; padding: 20px; box-shadow: var(--shadow-card);
}
.mt-4 { margin-top: 24px; }
.no-border { border: none; padding-bottom: 0; margin-bottom: 15px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.access-card {
  background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 12px;
  padding: 24px; display: flex; flex-direction: column; transition: transform 0.2s, box-shadow 0.2s; position: relative; height: 100%; box-shadow: var(--shadow-sm);
}
.access-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--c-green); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.icon-box { width: 40px; height: 40px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: white; }
.bg-green { background-color: var(--c-green); }
.bg-blue { background-color: var(--c-blue); }
.bg-teal { background-color: var(--c-teal); }
.bg-gray { background-color: var(--text-muted); }
.card-index { font-size: 14px; color: var(--text-muted); font-weight: 700; border: 1px solid var(--bg-body); border-radius: 6px; padding: 2px 8px; }
.card-content { flex: 1; margin-bottom: 20px; }
.card-content h4 { font-size: 16px; font-weight: 700; color: var(--text-main); margin-bottom: 8px; }
.card-content p { font-size: 13px; color: var(--text-muted); line-height: 1.4; margin: 0; }
.card-link { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 4px; text-decoration: none !important; transition: gap 0.2s; }
.card-link:hover { gap: 8px; }
.text-green { color: var(--c-green) !important; }
.actions-row { display: flex; flex-wrap: wrap; gap: 16px; }
.btn-action {
  flex: 1; white-space: nowrap; padding: 12px 20px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; background: var(--bg-surface); border: 1px solid transparent; transition: all 0.2s; min-width: 200px; text-align: center; box-shadow: var(--shadow-sm);
}
.action-green { color: #059669; border-color: #a7f3d0; background-color: var(--c-green-light); }
.action-blue { color: #2563eb; border-color: #bfdbfe; background-color: var(--c-blue-light); }
.action-orange { color: #ea580c; border-color: #fed7aa; background-color: var(--c-orange-light); }
.action-red { color: #dc2626; border-color: #fecaca; background-color: var(--c-red-light); }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.stat-card { border: 1px solid var(--border-color); border-radius: 12px; padding: 20px; background: var(--bg-surface); box-shadow: var(--shadow-sm); position: relative; }
.stat-header { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.stat-title { font-size: 13px; font-weight: 600; color: var(--text-muted); flex: 1; }
.dots { color: var(--border-color); letter-spacing: 2px; }
.stat-body { display: flex; align-items: baseline; gap: 10px; margin-bottom: 15px; }
.stat-number { font-size: 32px; font-weight: 700; color: var(--text-main); line-height: 1; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.badge-price { background: var(--c-green-light); color: #059669; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; border: 1px solid #a7f3d0; }
.badge-outline { border: 1px solid var(--border-color); padding: 2px 8px; border-radius: 12px; font-size: 11px; color: var(--text-muted); }
.stat-graph-placeholder { height: 40px; border: 2px dashed var(--border-color); border-radius: 6px; background: var(--bg-body); margin-top: auto; }
.badge-pill { font-size: 11px; background: var(--bg-surface); border: 1px solid var(--border-color); padding: 4px 12px; border-radius: 20px; color: var(--text-muted); font-weight: 500; }
.icon-small { font-size: 16px; }
.text-teal { color: var(--c-teal); }
.text-blue { color: var(--c-blue); }
.text-green { color: var(--c-green); }


/* =========================================
   10. MÓDULOS DE CASOS TÉCNICOS (Nuevos Agregados)
   ========================================= */

/* Galería Grid */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; margin-top: 15px; }
.photo-item { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 1 / 1; border: 1px solid var(--border-color); background-color: #f8fafc; }
.photo-item img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s ease; cursor: zoom-in; }
.photo-item:hover img { transform: scale(1.05); }
.photo-item .file-placeholder { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); padding: 5px; }
.photo-actions { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(to top, rgba(0,0,0,0.7), transparent); padding: 8px; display: flex; justify-content: flex-end; opacity: 0; transition: opacity 0.2s ease; }
.photo-item:hover .photo-actions { opacity: 1; }

/* Mapas (Leaflet) */
.map-container-view { margin-top: 10px; border: 1px solid var(--border-color); border-radius: 6px; overflow: hidden; background: #fff; }
.map-actions-bar { background: #f8fafc; padding: 6px 10px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border-color); font-size: 11px; }
.leaflet-container { z-index: 0; } /* Mapa siempre al fondo */

/* Timeline (Bitácora Compacta) */
.timeline { position: relative; margin-top: 10px; }
.timeline-item { padding: 15px 0; border-bottom: 1px solid var(--border-color); }
.timeline-item:last-child { border-bottom: none; }
.timeline-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.timeline-avatar { width: 28px; height: 28px; background: #e2e8f0; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #475569; flex-shrink: 0; }
.timeline-content { margin-left: 38px; white-space: pre-wrap; font-size: 13px; color: var(--text-main); line-height: 1.5; }

/* Adjunto en Timeline */
.timeline-attachment { margin-top: 10px; background: var(--bg-body); padding: 10px; border-radius: 8px; border: 1px solid var(--border-color); display: inline-block; }
.timeline-attachment img { max-height: 200px; border-radius: 4px; cursor: zoom-in; }

/* Botones Icono (Tablas) */
.btn-icon {
    width: 32px; height: 32px; display: inline-flex;
    align-items: center; justify-content: center;
    border-radius: 6px; border: 1px solid transparent;
    background-color: transparent; color: var(--text-muted);
    transition: all 0.2s ease; cursor: pointer;
}
.btn-icon:hover { background-color: var(--bg-body); color: var(--text-main); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-icon.success:hover { background-color: var(--c-green-light); color: var(--c-green); border-color: #a7f3d0; }
.btn-icon.danger:hover { background-color: var(--c-red-light); color: var(--c-red); border-color: #fecaca; }

/* Estilos Key-Value (Resumen Caso) */
.kv { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: flex; justify-content: space-between; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.kv-row:last-child { border-bottom: none; padding-bottom: 0; }
.kv-label { font-size: 13px; color: var(--text-muted); font-weight: 500; width: 140px; flex-shrink: 0; }
.kv-value { font-size: 13px; color: var(--text-main); font-weight: 500; flex: 1; text-align: right; }

/* Galería de Productos (Grid) */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 20px; }
.image-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-md); overflow: hidden; position: relative; transition: transform 0.2s, box-shadow 0.2s; }
.image-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--brand-color); }
.image-card-preview { height: 160px; width: 100%; background-color: var(--bg-body); display: flex; align-items: center; justify-content: center; overflow: hidden; border-bottom: 1px solid var(--border-color); }
.image-card-preview img { width: 100%; height: 100%; object-fit: contain; padding: 10px; }
.badge-overlay { position: absolute; top: 8px; right: 8px; background: rgba(16, 185, 129, 0.95); color: white; font-size: 10px; font-weight: 600; padding: 4px 8px; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); z-index: 2; }
.image-card-actions { padding: 10px; background: var(--bg-surface); }
.upload-container { border: 2px dashed var(--border-color); border-radius: var(--radius-md); padding: 24px; text-align: center; background-color: var(--bg-body); transition: all 0.2s; display: flex; flex-direction: column; gap: 16px; align-items: center; justify-content: center; }
.upload-container:hover { border-color: var(--brand-color); background-color: rgba(37, 99, 235, 0.02); }

/* =========================================
   11. MODALES GLOBALES (Sistema Standard)
   ========================================= */

/* Fondo oscuro (Backdrop) */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.6); /* Un poco más oscuro para enfoque */
    z-index: 2000; /* CRÍTICO: Mayor que el Header (1000) y Sidebar (900) */
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px); /* Blur elegante */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Estado Activo del Modal */
.modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* Contenedor del Modal (Card) */
.modal-content {
    background: var(--bg-surface); /* Se adapta a Dark/Light auto */
    width: 90%;
    max-width: 500px; /* Ancho estándar */
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    position: relative;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); /* Efecto rebote suave */
}

.modal-backdrop.active .modal-content {
    transform: scale(1);
}

/* Tamaños opcionales */
.modal-sm { max-width: 350px; } /* Para confirmaciones */
.modal-lg { max-width: 800px; } /* Para formularios grandes */

/* Elementos internos */
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    margin: 0; font-size: 18px; font-weight: 700; color: var(--text-main);
}

.btn-modal-close {
    background: transparent; border: none; font-size: 24px;
    color: var(--text-muted); cursor: pointer; line-height: 1;
    padding: 0; transition: color 0.2s;
}
.btn-modal-close:hover { color: var(--c-red); }

.modal-body {
    color: var(--text-main);
    font-size: 14px;
}

/* Inputs dentro del modal (Asegurar que se vean bien) */
.modal-body label {
    display: block; margin-bottom: 6px; font-weight: 600; 
    font-size: 12px; color: var(--text-muted);
}
.modal-body .input, 
.modal-body select { margin-bottom: 15px; }

.modal-footer {
    margin-top: 24px; padding-top: 20px;
    border-top: 1px solid var(--border-color);
    display: flex; justify-content: flex-end; gap: 12px;
}

/* =========================================
   12. MÓDULO BITÁCORA Y SEGUIMIENTO (Standard)
   ========================================= */

/* --- Filtros (Chips) --- */
.visita-filter-group {
    display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}

.badge-filter {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 4px 12px;
    border-radius: 20px; /* Estilo Chip */
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
}

.badge-filter:hover {
    background: var(--bg-body);
    border-color: var(--brand-color);
    color: var(--text-main);
}

.badge-filter.active {
    background: var(--brand-color);
    color: #ffffff;
    border-color: var(--brand-color);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

/* --- Avatares --- */
.avatar-circle {
    width: 32px; height: 32px;
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 12px; color: var(--text-muted);
    flex-shrink: 0;
}

.avatar-circle.sm {
    width: 24px; height: 24px; font-size: 10px;
}

/* --- Hilos de Conversación (Threading) --- */
.replies-container {
    margin-top: 12px;
    padding-left: 16px;
    border-left: 2px solid var(--border-color);
}

/* --- Botones de Acción Sutiles --- */
.link-btn {
    background: none; border: none; padding: 0;
    font-size: 11px; color: var(--text-muted);
    cursor: pointer; transition: color 0.2s;
}
.link-btn:hover {
    color: var(--brand-color);
    text-decoration: underline;
}

/* --- Mini Galería (Adjuntos en Comentarios) --- */
.mini-gallery-grid {
    display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px;
}

.mini-gallery-item {
    width: 60px; height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-body);
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

.mini-gallery-grid.sm .mini-gallery-item {
    width: 40px; height: 40px; border-radius: 6px;
}

.mini-gallery-item img {
    width: 100%; height: 100%; object-fit: cover;
}

.mini-gallery-item:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-sm);
    z-index: 1;
}

.pdf-icon { font-size: 20px; }

/* --- Barra de Progreso (Resultados Visitas) --- */
.progress-wrapper {
    background: var(--border-color);
    border-radius: 4px;
    height: 6px;
    width: 100%;
    margin-top: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Herramientas de Input --- */
.tool-btn {
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    color: var(--text-muted);
    transition: all 0.2s;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid transparent;
}

.tool-btn:hover {
    background: var(--bg-body);
    color: var(--text-main);
    border-color: var(--border-color);
}

/* --- Contexto de Respuesta --- */
.reply-context-box {
    display: none; /* JS lo activa */
    background-color: var(--c-blue-light);
    color: var(--c-blue);
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 6px;
    margin-bottom: 10px;
    align-items: center;
    justify-content: space-between;
    border: 1px solid rgba(59, 130, 246, 0.2);
}