/* ==============================================================================
   HERRAMIENTAS DEL DEFENSOR - HOJA DE ESTILOS MODERNA
   Google Fonts: Inter & Outfit | Modo Claro / Oscuro | Mobile First
   ============================================================================== */

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

:root {
    /* Paleta en Modo Claro */
    --bg-main: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f1f5f9;
    --bg-sidebar: #0f172a;
    --bg-sidebar-hover: #1e293b;
    --text-sidebar: #94a3b8;
    --text-sidebar-active: #ffffff;
    
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --primary-border: #bfdbfe;
    
    --accent-queja: #2563eb;
    --accent-queja-bg: #eff6ff;
    --accent-apoyo: #059669;
    --accent-apoyo-bg: #ecfdf5;
    
    --success: #10b981;
    --success-bg: #ecfdf5;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --info: #0ea5e9;
    --info-bg: #f0f9ff;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --sidebar-width: 260px;
    --navbar-height: 64px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-main: #090d16;
    --bg-surface: #111827;
    --bg-surface-hover: #1f2937;
    --bg-sidebar: #0b1120;
    --bg-sidebar-hover: #162032;
    --text-sidebar: #9ca3af;
    --text-sidebar-active: #f3f4f6;
    
    --border-color: #1f2937;
    --border-light: #162032;
    
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --text-light: #6b7280;
    
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: rgba(59, 130, 246, 0.15);
    --primary-border: rgba(59, 130, 246, 0.3);
    
    --accent-queja: #60a5fa;
    --accent-queja-bg: rgba(37, 99, 235, 0.2);
    --accent-apoyo: #34d399;
    --accent-apoyo-bg: rgba(5, 150, 105, 0.2);
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

/* ==============================================================================
   RESET & TIPOGRAFÍA BASE
   ============================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, h6, .brand-title {
    font-family: 'Outfit', sans-serif;
    color: var(--text-main);
    font-weight: 600;
    line-height: 1.25;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}
a:hover {
    color: var(--primary-hover);
}

/* ==============================================================================
   LAYOUT PRINCIPAL
   ============================================================================== */
.app-container {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Sidebar Drawer (Oculto por defecto en todos los tamaños de pantalla) */
.app-sidebar {
    width: var(--sidebar-width);
    max-width: 85vw;
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
    overflow-y: auto;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: none;
}

.app-sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.6);
}

.sidebar-header {
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-close-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    color: #94a3b8;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.sidebar-close-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.25);
}

.sidebar-header .logo-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    font-size: 18px;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.sidebar-brand-img {
    height: 38px;
    width: auto;
    max-width: 175px;
    object-fit: contain;
    background: #ffffff;
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease;
}

.sidebar-brand-img:hover {
    transform: scale(1.02);
}

.navbar-brand-img {
    height: 30px;
    width: auto;
    max-width: 140px;
    object-fit: contain;
    background: #ffffff;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.auth-brand-img {
    max-height: 58px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    background: #ffffff;
    padding: 6px 14px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: 1.25rem;
    display: inline-block;
}

.sidebar-header .brand-text {
    font-size: 1.05rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.02em;
}

.sidebar-close-btn {
    display: none;
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-sidebar);
    cursor: pointer;
    padding: 0.25rem;
}

.sidebar-close-btn:hover {
    color: #ffffff;
}

.sidebar-nav {
    flex: 1;
    padding: 1.25rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.nav-group-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 0 0.75rem 0.5rem;
}

.nav-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-md);
    color: var(--text-sidebar);
    font-weight: 500;
    font-size: 0.875rem;
    transition: var(--transition);
}

.nav-link:hover {
    background-color: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
}

.nav-link.active {
    background-color: var(--primary);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.nav-link .nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
}

.nav-link .badge {
    margin-left: auto;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-full);
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #475569, #334155);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.72rem;
    color: #94a3b8;
}

/* Telón de fondo (Backdrop activo al abrir el menú) */
.sidebar-backdrop {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 45;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* Main Content Area (Ocupa todo el ancho en cualquier resolución) */
.app-main {
    flex: 1;
    margin-left: 0;
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: var(--transition);
}

/* Top Navbar */
.app-navbar {
    height: var(--navbar-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    position: sticky;
    top: 0;
    z-index: 30;
    backdrop-filter: blur(8px);
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-toggle-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.navbar-title {
    font-size: 1.2rem;
    font-weight: 600;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Theme Toggle Button & Icon Button */
.btn-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-main);
    border-color: var(--text-muted);
}

/* Main Canvas */
.app-content {
    flex: 1;
    padding: 1.75rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* Footer */
.app-footer {
    padding: 1.25rem 1.75rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-surface);
}

/* ==============================================================================
   COMPONENTES UI: CARDS, BOTONES, TABLAS, ALERTAS
   ============================================================================== */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: var(--transition);
}

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

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

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

/* KPI Cards Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.75rem;
}

.kpi-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    text-decoration: none;
    color: inherit;
}

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

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--kpi-accent, var(--primary));
}

.kpi-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.kpi-value {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
}

.kpi-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.kpi-main-link {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
    justify-content: flex-start;
    text-decoration: none;
    color: inherit;
}

.kpi-main-link .kpi-sub {
    min-height: 1.9rem;
    display: flex;
    align-items: flex-start;
    line-height: 1.25;
}

.kpi-main-link:hover .kpi-sub {
    color: var(--primary);
}

.kpi-sublinks {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: auto;
    padding-top: 0.6rem;
    border-top: 1px dashed var(--border-color);
}

.kpi-sublink-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.76rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.22rem 0.45rem;
    border-radius: var(--radius-sm);
    background-color: var(--bg-body);
    border: 1px solid transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.kpi-sublink-item:hover {
    background-color: var(--bg-surface);
    border-color: var(--primary-light);
    color: var(--primary);
}

.kpi-sublink-count {
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    padding: 0.08rem 0.4rem;
    border-radius: 9999px;
    border: 1px solid var(--border-color);
}

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 1.15rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    text-decoration: none;
    min-height: 38px;
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover {
    background-color: var(--primary-hover);
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-main);
}
.btn-outline:hover {
    background-color: var(--bg-surface-hover);
    border-color: var(--text-muted);
}

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

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    line-height: 1;
}

.badge-queja {
    background-color: var(--accent-queja-bg);
    color: var(--accent-queja);
    border: 1px solid rgba(37, 99, 235, 0.2);
}

.badge-apoyo {
    background-color: var(--accent-apoyo-bg);
    color: var(--accent-apoyo);
    border: 1px solid rgba(5, 150, 105, 0.2);
}

.badge-success {
    background-color: var(--success-bg);
    color: var(--success);
}
.badge-warning {
    background-color: var(--warning-bg);
    color: var(--warning);
}
.badge-danger {
    background-color: var(--danger-bg);
    color: var(--danger);
}
.badge-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

/* Tablas */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 650px;
}

.table th {
    background-color: var(--bg-surface-hover);
    color: var(--text-muted);
    font-weight: 600;
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}

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

/* Alertas Flash */
.alert {
    padding: 0.9rem 1.15rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    border: 1px solid transparent;
}

.alert-success {
    background-color: var(--success-bg);
    color: #065f46;
    border-color: #a7f3d0;
}
.alert-error, .alert-danger {
    background-color: var(--danger-bg);
    color: #991b1b;
    border-color: #fecaca;
}
.alert-warning {
    background-color: var(--warning-bg);
    color: #92400e;
    border-color: #fde68a;
}
.alert-info {
    background-color: var(--info-bg);
    color: #075985;
    border-color: #bae6fd;
}

/* ==============================================================================
   FORMULARIOS Y PANTALLA DE LOGIN
   ============================================================================== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background: radial-gradient(circle at top, rgba(37, 99, 235, 0.08), transparent 40%), var(--bg-main);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 24px;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    margin-bottom: 1rem;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.65rem 0.9rem;
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-main);
    transition: var(--transition);
    outline: none;
    min-height: 38px;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ==============================================================================
   PESTAÑAS (TABS) & TIMELINE
   ============================================================================== */
.tabs-wrapper {
    border-bottom: 1px solid var(--border-color);
}

.nav-tabs {
    list-style: none;
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.tab-link {
    display: inline-flex;
    align-items: center;
    padding: 0.75rem 1.15rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    transition: var(--transition);
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
}

.tab-link:hover {
    color: var(--text-main);
    border-bottom-color: var(--border-color);
}

.tab-link.active {
    color: var(--primary);
    font-weight: 600;
    border-bottom-color: var(--primary);
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Timeline */
.timeline {
    position: relative;
    padding-left: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

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

.timeline-item {
    position: relative;
}

.timeline-badge {
    position: absolute;
    left: -2rem;
    top: 4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid var(--bg-surface);
    box-shadow: 0 0 0 2px var(--primary-border);
}

.timeline-content {
    background: var(--bg-surface-hover);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}


/* ==============================================================================
   RESPONSIVE / ADAPTABILIDAD MÓVIL (≤ 768px)
   ============================================================================== */
@media (max-width: 768px) {
    .app-navbar {
        padding: 0 1rem;
    }

    .navbar-title {
        font-size: 1.05rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 55vw;
    }

    .app-content {
        padding: 1rem;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .kpi-card {
        padding: 1rem;
    }

    .kpi-value {
        font-size: 1.5rem;
    }

    .app-footer {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }
}
