/* =============================================
   MADORSOFT - SISTEMA DE TICKETS DE SOPORTE
   CSS Principal del Panel de Administración
   Versión: 1.0.0
   Fuentes: Instrument Sans (títulos) + Inter (cuerpo)
   Paleta: #1a8cff (primary), #202124 (dark), #0cbc87 (success)
   ============================================= */

/* ---- Importar fuentes ---- */
@import url('https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400;500;600;700&family=Inter:wght@300;400;500;600&display=swap');

/* ---- Variables del sistema ---- */
:root {
    --mad-primary:        #1a8cff;
    --mad-primary-dark:   #0064d4;
    --mad-primary-light:  #e8f3ff;
    --mad-primary-rgb:    26, 140, 255;

    --mad-sidebar-bg:     #12151e;
    --mad-sidebar-width:  260px;
    --mad-navbar-height:  64px;

    --mad-body-bg:        #f0f2f7;
    --mad-card-bg:        #ffffff;
    --mad-border:         #e2e6ed;

    --mad-text:           #202124;
    --mad-text-muted:     #606261;
    --mad-heading-font:   'Instrument Sans', sans-serif;
    --mad-body-font:      'Inter', sans-serif;

    --mad-success:        #0cbc87;
    --mad-warning:        #f7c32e;
    --mad-danger:         #d6293e;
    --mad-info:           #17a2b8;
    --mad-orange:         #fd7e14;

    --mad-shadow-sm:      0 2px 8px rgba(29, 58, 83, 0.08);
    --mad-shadow:         0 4px 20px rgba(29, 58, 83, 0.10);
    --mad-shadow-lg:      0 8px 40px rgba(29, 58, 83, 0.14);
    --mad-radius:         0.5rem;
    --mad-radius-sm:      0.313rem;
    --mad-radius-lg:      0.75rem;

    --mad-sidebar-text:       rgba(255, 255, 255, 0.65);
    --mad-sidebar-text-hover: rgba(255, 255, 255, 0.95);
    --mad-sidebar-active-bg:  rgba(26, 140, 255, 0.18);
    --mad-sidebar-section:    rgba(255, 255, 255, 0.30);
}

/* =============================================
   RESET Y BASE
   ============================================= */

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: var(--mad-body-font);
    font-size: 0.9rem;
    color: var(--mad-text);
    background-color: var(--mad-body-bg);
    margin: 0;
    padding: 0;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--mad-heading-font);
    color: var(--mad-text);
    font-weight: 600;
}

a { text-decoration: none; }

/* =============================================
   LAYOUT PRINCIPAL: sidebar + contenido
   ============================================= */

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.app-sidebar {
    width: var(--mad-sidebar-width);
    min-height: 100vh;
    background: linear-gradient(180deg, #151821 0%, #12151e 100%);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.app-sidebar::-webkit-scrollbar { width: 4px; }
.app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

/* Logo del sidebar */
.sidebar-logo {
    padding: 1.35rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-shrink: 0;
}

.sidebar-logo img {
    height: 36px;
    width: auto;
}

.sidebar-logo-text {
    font-family: var(--mad-heading-font);
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
    letter-spacing: -0.01em;
}

.sidebar-logo-sub {
    font-size: 0.65rem;
    color: rgba(255,255,255,0.28);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    display: block;
    margin-top: 1px;
}

/* Secciones de navegación */
.sidebar-section-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.25);
    padding: 1.25rem 1.5rem 0.4rem;
}

/* Links de navegación */
.sidebar-nav {
    padding: 0.75rem 0;
    flex: 1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.9rem;
    border-left: 3px solid transparent;
    border-radius: 0 var(--mad-radius-sm) var(--mad-radius-sm) 0;
    color: var(--mad-sidebar-text);
    font-size: 0.865rem;
    font-weight: 500;
    transition: all 0.15s ease;
    cursor: pointer;
    white-space: nowrap;
    margin-bottom: 3px;
    text-decoration: none;
}

.sidebar-link:hover {
    background-color: rgba(255,255,255,0.06);
    color: var(--mad-sidebar-text-hover);
    border-left-color: rgba(26,140,255,0.35);
}

.sidebar-link.active {
    background-color: rgba(26,140,255,0.13);
    color: #fff;
    font-weight: 600;
    border-left-color: var(--mad-primary);
}

.sidebar-link .bi {
    font-size: 1rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    opacity: 0.85;
}

.sidebar-link.active .bi,
.sidebar-link:hover .bi {
    opacity: 1;
}

/* Badge en sidebar (contador de notificaciones) */
.sidebar-badge {
    margin-left: auto;
    background: var(--mad-primary);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 50rem;
    line-height: 1.6;
}

/* Footer del sidebar */
.sidebar-footer {
    padding: 0.75rem 0.65rem;
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 0.85rem;
    border-radius: var(--mad-radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
}

.sidebar-user:hover {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.07);
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--mad-primary), #0066cc);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mad-heading-font);
    font-weight: 700;
    font-size: 0.82rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(26,140,255,0.3);
}

.sidebar-user-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(255,255,255,0.9);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.68rem;
    color: rgba(255,255,255,0.38);
    white-space: nowrap;
}

/* ---- Área de contenido principal ---- */
.app-main {
    margin-left: var(--mad-sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---- Navbar superior ---- */
.app-navbar {
    height: var(--mad-navbar-height);
    background: #fff;
    border-bottom: 1px solid var(--mad-border);
    display: flex;
    align-items: center;
    padding: 0 1.75rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    gap: 1rem;
    box-shadow: var(--mad-shadow-sm);
}

.navbar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--mad-text-muted);
    padding: 0.35rem;
    cursor: pointer;
    border-radius: var(--mad-radius-sm);
    transition: background 0.15s;
}

.navbar-toggle:hover { background: var(--mad-body-bg); }

.navbar-page-title {
    font-family: var(--mad-heading-font);
    font-size: 1rem;
    font-weight: 600;
    color: var(--mad-text);
    margin: 0;
}

.navbar-spacer { flex: 1; }

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--mad-radius-sm);
    background: none;
    border: 1px solid var(--mad-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--mad-text-muted);
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}

.navbar-icon-btn:hover {
    background: var(--mad-body-bg);
    color: var(--mad-text);
}

.navbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--mad-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mad-heading-font);
    font-weight: 700;
    font-size: 0.8rem;
    color: #fff;
    cursor: pointer;
    border: 2px solid var(--mad-primary-light);
}

/* ---- Área de contenido de páginas ---- */
.app-content {
    padding: 1.75rem;
    flex: 1;
}

/* =============================================
   ENCABEZADO DE PÁGINA
   ============================================= */

.page-header {
    margin-bottom: 1.5rem;
}

.page-title {
    font-family: var(--mad-heading-font);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--mad-text);
    margin: 0;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--mad-text-muted);
    margin-top: 0.25rem;
}

/* =============================================
   TARJETAS (CARDS)
   ============================================= */

.mad-card {
    background: var(--mad-card-bg);
    border-radius: var(--mad-radius);
    border: 1px solid var(--mad-border);
    box-shadow: var(--mad-shadow-sm);
    overflow: hidden;
}

.mad-card-header {
    padding: 1.1rem 1.5rem;
    border-bottom: 1px solid var(--mad-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.mad-card-title {
    font-family: var(--mad-heading-font);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--mad-text);
    margin: 0;
}

.mad-card-actions { margin-left: auto; }

.mad-card-body { padding: 1.5rem; }

/* =============================================
   TARJETAS DE ESTADÍSTICAS (STATS)
   ============================================= */

.stat-card {
    background: var(--mad-card-bg);
    border-radius: var(--mad-radius);
    border: 1px solid var(--mad-border);
    box-shadow: var(--mad-shadow-sm);
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover {
    box-shadow: var(--mad-shadow);
    transform: translateY(-2px);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--mad-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-icon.primary   { background: var(--mad-primary-light); color: var(--mad-primary); }
.stat-icon.success   { background: #d4f4ec; color: var(--mad-success); }
.stat-icon.warning   { background: #fef9e7; color: var(--mad-warning); }
.stat-icon.danger    { background: #fce8ea; color: var(--mad-danger); }
.stat-icon.orange    { background: #fff3e0; color: var(--mad-orange); }
.stat-icon.info      { background: #d1ecf1; color: var(--mad-info); }

.stat-info { flex: 1; min-width: 0; }

.stat-value {
    font-family: var(--mad-heading-font);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--mad-text);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--mad-text-muted);
    font-weight: 500;
}

/* =============================================
   TABLA DE TICKETS
   ============================================= */

.tickets-table-wrapper {
    overflow-x: auto;
}

.tickets-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.tickets-table thead th {
    background: #f8f9fc;
    padding: 0.75rem 1rem;
    text-align: left;
    font-family: var(--mad-heading-font);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--mad-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--mad-border);
    white-space: nowrap;
}

.tickets-table tbody td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--mad-border);
    vertical-align: middle;
}

.tickets-table tbody tr:last-child td { border-bottom: none; }

.tickets-table tbody tr {
    transition: background 0.15s;
    cursor: pointer;
}

.tickets-table tbody tr:hover { background: #f8f9fc; }

.ticket-number {
    font-family: var(--mad-heading-font);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--mad-primary);
}

.ticket-title {
    font-weight: 500;
    color: var(--mad-text);
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ticket-title small {
    display: block;
    font-size: 0.75rem;
    color: var(--mad-text-muted);
    font-weight: 400;
}

/* =============================================
   BADGES: ESTADO Y URGENCIA
   ============================================= */

.badge-estado,
.badge-urgencia {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.65rem;
    border-radius: 50rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

/* Estados */
.badge-nuevo      { background: var(--mad-primary-light); color: var(--mad-primary); }
.badge-asignado   { background: #fff3e0; color: var(--mad-orange); }
.badge-cerrado    { background: #d4f4ec; color: var(--mad-success); }

/* Urgencias */
.badge-pendiente { background: #f3f4f6; color: #9ca3af; font-style: italic; }
.badge-baja      { background: #f0f2f7; color: var(--mad-text-muted); }
.badge-media     { background: var(--mad-primary-light); color: var(--mad-primary); }
.badge-alta      { background: #fff3e0; color: var(--mad-orange); }
.badge-critica   { background: #fce8ea; color: var(--mad-danger); }

/* Punto indicador */
.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* =============================================
   FILTROS / TOOLBAR DE BÚSQUEDA
   ============================================= */

.filters-bar {
    background: var(--mad-card-bg);
    border: 1px solid var(--mad-border);
    border-radius: var(--mad-radius);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem 0.75rem;
    align-items: flex-end;
    box-shadow: var(--mad-shadow-sm);
}

/* El buscador siempre ocupa la fila completa */
.filters-bar .filter-group:first-child {
    flex: 1 1 100%;
    min-width: unset;
}

.filters-bar .filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 130px;
}

.filters-bar .filter-group label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--mad-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.filters-bar .form-control,
.filters-bar .form-select {
    font-family: var(--mad-body-font);
    font-size: 0.85rem;
    height: 36px;
    border-color: var(--mad-border);
    border-radius: var(--mad-radius-sm);
    background-color: var(--mad-body-bg);
    transition: border-color .15s, box-shadow .15s;
}

.filters-bar .form-control:focus,
.filters-bar .form-select:focus {
    border-color: var(--mad-primary);
    box-shadow: 0 0 0 3px rgba(var(--mad-primary-rgb), 0.12);
    background-color: #fff;
}

.filters-bar input[type="date"] {
    font-family: var(--mad-body-font);
}

.filters-bar .btn-mad {
    height: 36px;
    display: flex;
    align-items: center;
    padding-top: 0;
    padding-bottom: 0;
}

/* Buscador: placeholder visible solo al enfocar */
#f-buscar::placeholder { color: transparent; }
#f-buscar:focus::placeholder { color: var(--mad-text-muted); opacity: .7; }

/* Separador visual entre buscador y filtros */
.filters-bar .filter-group:first-child .form-control {
    height: 40px;
    font-size: 0.9rem;
    border-radius: var(--mad-radius-sm);
    padding-left: 2.4rem;
}

/* =============================================
   FORMULARIOS
   ============================================= */

.mad-form-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--mad-text);
    margin-bottom: 0.35rem;
    display: block;
}

.mad-form-control,
.mad-form-select {
    width: 100%;
    border: 1px solid var(--mad-border);
    border-radius: var(--mad-radius-sm);
    padding: 0.55rem 0.9rem;
    font-family: var(--mad-body-font);
    font-size: 0.875rem;
    color: var(--mad-text);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.mad-form-control:focus,
.mad-form-select:focus {
    border-color: var(--mad-primary);
    box-shadow: 0 0 0 3px rgba(var(--mad-primary-rgb), 0.12);
}

.mad-form-control::placeholder { color: var(--mad-text-muted); }

textarea.mad-form-control {
    resize: vertical;
    min-height: 100px;
}

/* =============================================
   BOTONES
   ============================================= */

.btn-mad {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 1.1rem;
    border-radius: var(--mad-radius-sm);
    font-family: var(--mad-body-font);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.18s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn-mad-primary {
    background: var(--mad-primary);
    color: #fff;
}

.btn-mad-primary:hover {
    background: var(--mad-primary-dark);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--mad-primary-rgb), 0.35);
}

.btn-mad-outline {
    background: transparent;
    color: var(--mad-text-muted);
    border: 1px solid var(--mad-border);
}

.btn-mad-outline:hover {
    background: var(--mad-body-bg);
    color: var(--mad-text);
    border-color: #c0c4cc;
}

.btn-mad-success {
    background: var(--mad-success);
    color: #fff;
}

.btn-mad-success:hover {
    background: #0aa070;
    color: #fff;
}

.btn-mad-danger {
    background: var(--mad-danger);
    color: #fff;
}

.btn-mad-danger:hover {
    background: #b8202f;
    color: #fff;
}

.btn-mad-sm {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}

.btn-mad-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    justify-content: center;
    border-radius: var(--mad-radius-sm);
}

/* =============================================
   DETALLE DE TICKET
   ============================================= */

.ticket-detail-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.5rem;
    align-items: start;
}

.ticket-info-row {
    display: flex;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--mad-border);
    gap: 1rem;
}

.ticket-info-row:last-child { border-bottom: none; }

.ticket-info-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--mad-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    min-width: 120px;
    flex-shrink: 0;
}

.ticket-info-value {
    font-size: 0.875rem;
    color: var(--mad-text);
    font-weight: 500;
    word-break: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
}

/* =============================================
   CHAT DE COMENTARIOS
   ============================================= */

.chat-container {
    display: flex;
    flex-direction: column;
    height: 450px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: #f8f9fc;
    border-radius: var(--mad-radius-sm);
    margin-bottom: 1rem;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--mad-border); border-radius: 4px; }

/* Burbuja de mensaje */
.chat-bubble-wrapper {
    display: flex;
    gap: 0.65rem;
    align-items: flex-end;
    width: 100%;
}

.chat-bubble-wrapper.own {
    flex-direction: row-reverse;
}

/* El div interno (contiene nombre + burbuja) */
.chat-bubble-wrapper > div {
    display: flex;
    flex-direction: column;
    max-width: 72%;
}

.chat-bubble-wrapper.own > div {
    align-items: flex-end;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mad-heading-font);
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.chat-avatar.staff-avatar   { background: var(--mad-primary); }
.chat-avatar.client-avatar  { background: var(--mad-success); }
.chat-avatar.admin-avatar   { background: var(--mad-danger); }

.chat-bubble {
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    word-break: break-word;
}

.chat-bubble-wrapper.own .chat-bubble {
    border-radius: 12px;
    border-bottom-right-radius: 4px;
    background: var(--mad-primary);
    color: #fff;
}

.chat-bubble-wrapper:not(.own) .chat-bubble {
    background: #fff;
    border: 1px solid var(--mad-border);
    color: var(--mad-text);
}

.chat-bubble-internal {
    background: #fef9e7 !important;
    border: 1px dashed var(--mad-warning) !important;
    color: var(--mad-text) !important;
}

.chat-bubble-name {
    font-size: 0.72rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
    opacity: 0.75;
}

.chat-bubble-text {
    font-size: 0.875rem;
    line-height: 1.5;
    word-break: break-word;
}

.chat-bubble-time {
    font-size: 0.68rem;
    opacity: 0.6;
    margin-top: 0.25rem;
    text-align: right;
}

.chat-internal-label {
    font-size: 0.68rem;
    color: var(--mad-warning);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.2rem;
    margin-bottom: 0.2rem;
}

/* Input de nuevo mensaje */
.chat-input-area {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--mad-border);
    border-radius: var(--mad-radius-sm);
    padding: 0.6rem 0.9rem;
    font-family: var(--mad-body-font);
    font-size: 0.875rem;
    resize: none;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    max-height: 120px;
    line-height: 1.5;
}

.chat-input:focus {
    border-color: var(--mad-primary);
    box-shadow: 0 0 0 3px rgba(var(--mad-primary-rgb), 0.12);
}

/* Botón enviar: mismo alto que el textarea */
.chat-input-row .btn-mad {
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1rem;
    min-width: 44px;
}

/* =============================================
   COMENTARIOS / ACTIVIDAD
   ============================================= */

.comments-list {
    display: flex;
    flex-direction: column;
}

.comment-item {
    display: flex;
    gap: 0.85rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--mad-border);
}

.comment-item:first-child { padding-top: 0; }
.comment-item:last-child  { border-bottom: none; padding-bottom: 0; }

.comment-item.internal {
    background: #fffbeb;
    border-left: 3px solid var(--mad-warning);
    padding-left: 0.85rem;
    margin-left: -1.25rem;
    padding-right: 0;
    border-bottom-color: #fef3c7;
}

.comment-content {
    flex: 1;
    min-width: 0;
}

.comment-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.4rem;
}

.comment-author {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--mad-text);
}

.comment-role {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 20px;
}

.comment-role.role-admin   { background: rgba(124,58,237,.1); color: #7c3aed; }
.comment-role.role-soporte { background: rgba(3,105,161,.1);  color: #0369a1; }
.comment-role.role-cliente { background: rgba(4,120,87,.1);   color: #047857; }

.comment-internal-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 20px;
    background: rgba(234,179,8,.12);
    color: #b45309;
}

.comment-time {
    font-size: 0.72rem;
    color: var(--mad-text-muted);
    margin-left: auto;
    white-space: nowrap;
}

.comment-body {
    font-size: 0.875rem;
    line-height: 1.65;
    color: var(--mad-text);
    white-space: pre-wrap;
    word-break: break-word;
}

/* Área para agregar comentario */
.comment-add-area {
    display: flex;
    gap: 0.75rem;
    padding-top: 1rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--mad-border);
    align-items: flex-start;
}

.comment-add-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.comment-add-textarea {
    width: 100%;
    border: 1px solid var(--mad-border);
    border-radius: var(--mad-radius-sm);
    padding: 0.65rem 0.9rem;
    font-family: var(--mad-body-font);
    font-size: 0.875rem;
    resize: vertical;
    outline: none;
    min-height: 76px;
    transition: border-color 0.15s, box-shadow 0.15s;
    line-height: 1.55;
}

.comment-add-textarea:focus {
    border-color: var(--mad-primary);
    box-shadow: 0 0 0 3px rgba(var(--mad-primary-rgb), 0.12);
}

.comment-add-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* =============================================
   GALERÍA DE IMÁGENES
   ============================================= */

.images-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.75rem;
}

.image-thumb {
    aspect-ratio: 1;
    border-radius: var(--mad-radius-sm);
    overflow: hidden;
    border: 1px solid var(--mad-border);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.image-thumb:hover {
    transform: scale(1.04);
    box-shadow: var(--mad-shadow);
}

.image-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Upload area */
.upload-area {
    border: 2px dashed var(--mad-border);
    border-radius: var(--mad-radius);
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: #fafbfd;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--mad-primary);
    background: var(--mad-primary-light);
}

.upload-area .upload-icon {
    font-size: 2rem;
    color: var(--mad-text-muted);
    margin-bottom: 0.5rem;
}

.upload-area p {
    font-size: 0.875rem;
    color: var(--mad-text-muted);
    margin: 0;
}

/* =============================================
   PÁGINAS DE AUTH (LOGIN / REGISTRO)
   ============================================= */

.auth-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f1420 0%, #1a1d2e 40%, #0d1520 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

/* Fondo decorativo */
.auth-page::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(26, 140, 255, 0.12) 0%, transparent 70%);
    top: -200px;
    right: -200px;
    pointer-events: none;
}

.auth-page::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(12, 188, 135, 0.08) 0%, transparent 70%);
    bottom: -150px;
    left: -100px;
    pointer-events: none;
}

.auth-card {
    background: #fff;
    border-radius: var(--mad-radius-lg);
    box-shadow: var(--mad-shadow-lg);
    width: 100%;
    max-width: 440px;
    padding: 2.5rem 2.25rem;
    position: relative;
    z-index: 1;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo img { height: 42px; }

.auth-title {
    font-family: var(--mad-heading-font);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--mad-text);
    text-align: center;
    margin-bottom: 0.4rem;
}

.auth-subtitle {
    font-size: 0.875rem;
    color: var(--mad-text-muted);
    text-align: center;
    margin-bottom: 2rem;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.25rem 0;
    color: var(--mad-text-muted);
    font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--mad-border);
}

/* =============================================
   PAGINACIÓN
   ============================================= */

.mad-pagination {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    justify-content: flex-end;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.mad-page-btn {
    min-width: 34px;
    height: 34px;
    border-radius: var(--mad-radius-sm);
    border: 1px solid var(--mad-border);
    background: #fff;
    color: var(--mad-text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    padding: 0 0.5rem;
}

.mad-page-btn:hover {
    border-color: var(--mad-primary);
    color: var(--mad-primary);
}

.mad-page-btn.active {
    background: var(--mad-primary);
    border-color: var(--mad-primary);
    color: #fff;
}

.mad-page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* =============================================
   TOAST / NOTIFICACIONES
   ============================================= */

.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 360px;
}

.mad-toast {
    background: #fff;
    border-radius: var(--mad-radius);
    box-shadow: var(--mad-shadow-lg);
    padding: 0.9rem 1.2rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    border-left: 4px solid var(--mad-primary);
    animation: slideInToast 0.3s ease;
    font-size: 0.875rem;
}

.mad-toast.success { border-color: var(--mad-success); }
.mad-toast.error   { border-color: var(--mad-danger); }
.mad-toast.warning { border-color: var(--mad-warning); }

.mad-toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.mad-toast.success .mad-toast-icon { color: var(--mad-success); }
.mad-toast.error   .mad-toast-icon { color: var(--mad-danger); }
.mad-toast.warning .mad-toast-icon { color: var(--mad-warning); }
.mad-toast:not(.success):not(.error):not(.warning) .mad-toast-icon { color: var(--mad-primary); }

.mad-toast-body { flex: 1; }
.mad-toast-title { font-weight: 600; color: var(--mad-text); }
.mad-toast-msg   { color: var(--mad-text-muted); margin-top: 0.2rem; }

@keyframes slideInToast {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* =============================================
   MODAL
   ============================================= */

.mad-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(18, 21, 30, 0.55);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

.mad-modal {
    background: #fff;
    border-radius: var(--mad-radius-lg);
    box-shadow: var(--mad-shadow-lg);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
}

.mad-modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--mad-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.mad-modal-title {
    font-family: var(--mad-heading-font);
    font-size: 1rem;
    font-weight: 700;
    color: var(--mad-text);
    margin: 0;
    flex: 1;
}

.mad-modal-close {
    width: 28px;
    height: 28px;
    border-radius: var(--mad-radius-sm);
    background: none;
    border: 1px solid var(--mad-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--mad-text-muted);
    font-size: 0.9rem;
    transition: all 0.15s;
}

.mad-modal-close:hover {
    background: var(--mad-body-bg);
    color: var(--mad-text);
}

.mad-modal-body { padding: 1.5rem; }

.mad-modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--mad-border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* =============================================
   ESTADO VACÍO
   ============================================= */

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--mad-text-muted);
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h5 {
    font-family: var(--mad-heading-font);
    font-size: 1rem;
    color: var(--mad-text-muted);
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
}

/* =============================================
   SPINNER DE CARGA
   ============================================= */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.7);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mad-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--mad-border);
    border-top-color: var(--mad-primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================
   PANEL LATERAL DEL TICKET (Info + acciones)
   ============================================= */

.ticket-sidebar-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.ticket-sidebar-panel .mad-card-body {
    padding: 1rem 1.25rem;
}

/* =============================================
   RESPONSIVE
   ============================================= */

@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0;
    }

    .navbar-toggle {
        display: flex;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1039;
        display: none;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .ticket-detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 767.98px) {
    .app-content { padding: 1rem; }
    .filters-bar { flex-direction: column; }
    .filters-bar .filter-group { min-width: 100%; }
    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.4rem; }
}

/* =============================================
   UTILIDADES
   ============================================= */

.text-primary-mad { color: var(--mad-primary) !important; }
.bg-primary-mad   { background: var(--mad-primary-light) !important; }
.fw-600           { font-weight: 600 !important; }
.fw-700           { font-weight: 700 !important; }
.font-heading     { font-family: var(--mad-heading-font) !important; }
.gap-2px          { gap: 2px; }

/* Separador con texto */
.divider-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--mad-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 1rem 0;
}

.divider-label::before,
.divider-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--mad-border);
}

/* =============================================
   MÓDULO DE PROYECTOS
   ============================================= */

/* --- Badges de estado de tarea --- */
.badge-tarea {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.65rem;
    border-radius: 2rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.tarea-pendiente   { background: #f3f4f6; color: #6b7280; }
.tarea-en-progreso { background: #dbeafe; color: #1d4ed8; }
.tarea-actualizado { background: #fef9c3; color: #a16207; }
.tarea-en-pruebas  { background: #ede9fe; color: #6d28d9; }
.tarea-aceptado    { background: #dcfce7; color: #16a34a; }
.tarea-rechazado   { background: #fee2e2; color: #dc2626; }
.tarea-cancelado   { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }

/* --- Badges de estado de proyecto --- */
.badge-proy {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.65rem;
    border-radius: 2rem;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}
.proy-activo     { background: #dbeafe; color: #1d4ed8; }
.proy-pausado    { background: #fef9c3; color: #a16207; }
.proy-completado { background: #dcfce7; color: #16a34a; }
.proy-cancelado  { background: #f3f4f6; color: #6b7280; }

/* --- Tarjeta de proyecto --- */
.proyecto-card {
    background: #fff;
    border: 1px solid var(--mad-border);
    border-radius: 1rem;
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow 0.18s, transform 0.15s, border-color 0.15s;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    position: relative;
}
.proyecto-card:hover {
    box-shadow: 0 8px 28px rgba(26,140,255,.12);
    border-color: var(--mad-primary);
    transform: translateY(-2px);
}
.proyecto-card-accent {
    height: 4px;
    width: 100%;
    background: linear-gradient(90deg, var(--mad-primary), #60a5fa);
    flex-shrink: 0;
}
.proyecto-card-accent.activo     { background: linear-gradient(90deg,#1a8cff,#60a5fa); }
.proyecto-card-accent.pausado    { background: linear-gradient(90deg,#f7c32e,#fde68a); }
.proyecto-card-accent.completado { background: linear-gradient(90deg,#0cbc87,#6ee7b7); }
.proyecto-card-accent.cancelado  { background: linear-gradient(90deg,#9ca3af,#d1d5db); }

.proyecto-card-body {
    padding: 1.2rem 1.3rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    flex: 1;
}
.proyecto-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}
.proyecto-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 0.6rem;
    background: var(--mad-primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-family: var(--mad-heading-font);
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--mad-primary);
}
.proyecto-card-title {
    font-family: var(--mad-heading-font);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--mad-text);
    margin: 0 0 0.2rem;
    line-height: 1.35;
}
.proyecto-card-empresa {
    font-size: 0.77rem;
    color: var(--mad-text-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* Progress bar */
.prog-bar-wrap {
    background: var(--mad-body-bg);
    border-radius: 2rem;
    height: 6px;
    overflow: hidden;
}
.prog-bar-fill {
    height: 100%;
    border-radius: 2rem;
    background: linear-gradient(90deg, var(--mad-primary), #60a5fa);
    transition: width 0.5s ease;
}
.prog-bar-fill.done { background: linear-gradient(90deg, var(--mad-success), #6ee7b7); }

.proyecto-card-stats {
    display: flex;
    gap: 0;
    border-top: 1px solid var(--mad-border);
    margin: 0 -1.3rem -0.9rem;
}
.proyecto-card-stat {
    flex: 1;
    text-align: center;
    padding: 0.65rem 0.5rem;
    border-right: 1px solid var(--mad-border);
    font-size: 0.72rem;
    color: var(--mad-text-muted);
}
.proyecto-card-stat:last-child { border-right: none; }
.proyecto-card-stat strong {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--mad-heading-font);
    color: var(--mad-text);
    margin-bottom: 0.1rem;
}
.proyecto-card-meta {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    font-size: 0.77rem;
    color: var(--mad-text-muted);
    flex-wrap: wrap;
}

/* --- Grid de proyectos --- */
.proyectos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.15rem;
}

/* --- Tarea card en proyecto-detalle --- */
.tarea-row {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--mad-border);
    transition: background 0.15s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}
.tarea-row:last-child { border-bottom: none; }
.tarea-row:hover { background: #f8fafc; }
.tarea-row-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--mad-text);
    min-width: 0;
    line-height: 1.4;
    margin-bottom: 0.5rem;
}
.tarea-row-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: #f1f5f9;
    border-radius: 0.35rem;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    color: var(--mad-text-muted);
    white-space: nowrap;
}

/* --- Checklist --- */
.checklist-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--mad-border);
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--mad-primary);
    cursor: pointer;
    flex-shrink: 0;
}
.checklist-item label {
    flex: 1;
    font-size: 0.875rem;
    cursor: pointer;
    transition: opacity 0.15s;
}
.checklist-item.done label {
    text-decoration: line-through;
    opacity: 0.5;
}
.checklist-item .btn-del-check {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--mad-text-muted);
    font-size: 0.85rem;
    padding: 0.2rem;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.1s, color 0.1s;
}
.checklist-item:hover .btn-del-check { opacity: 1; }
.checklist-item .btn-del-check:hover { color: var(--mad-danger); }

/* --- Status flow panel (tarea-detalle) --- */
.estado-flow {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.estado-flow-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border-radius: var(--mad-radius-sm);
    border: 1.5px solid var(--mad-border);
    background: #fff;
    cursor: pointer;
    font-family: var(--mad-body-font);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.15s;
    width: 100%;
    text-align: left;
}
.estado-flow-btn:hover { border-color: var(--mad-primary); background: var(--mad-primary-light); color: var(--mad-primary); }
.estado-flow-btn.danger:hover { border-color: var(--mad-danger); background: #fee2e2; color: var(--mad-danger); }
.estado-flow-btn.success:hover { border-color: var(--mad-success); background: #dcfce7; color: var(--mad-success); }

/* --- Selector de estado en modal proyecto --- */
.estado-proy-opt {
    padding: .55rem .4rem;
    border: 1.5px solid var(--mad-border);
    border-radius: .5rem;
    text-align: center;
    font-size: .72rem;
    font-weight: 600;
    color: var(--mad-text-muted);
    transition: all .15s;
    background: #fff;
}
.estado-proy-opt:hover { border-color: var(--mad-primary); color: var(--mad-primary); background: var(--mad-primary-light); }
.estado-proy-opt.selected { border-color: var(--mad-primary); color: var(--mad-primary); background: var(--mad-primary-light); }

/* --- Validador portal --- */
.validador-project-card {
    background: var(--mad-card-bg);
    border: 1px solid var(--mad-border);
    border-radius: var(--mad-radius-lg);
    padding: 1.5rem;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
    text-decoration: none;
    color: inherit;
    display: block;
}
.validador-project-card:hover {
    box-shadow: var(--mad-shadow);
    border-color: var(--mad-primary);
}

/* --- Tarea validación card --- */
.tarea-val-card {
    background: #fff;
    border: 1px solid var(--mad-border);
    border-radius: var(--mad-radius);
    padding: 1rem 1.25rem;
    margin-bottom: 0.65rem;
    transition: box-shadow 0.12s;
}
.tarea-val-card.en-pruebas {
    border-left: 3px solid #7c3aed;
    background: #faf5ff;
}
.tarea-val-card.aceptada  { border-left: 3px solid var(--mad-success); }
.tarea-val-card.rechazada { border-left: 3px solid var(--mad-danger); }
