:root {
    --azul: #0F51B0;
    --navy: #0A2E6E;
    --azul-tint: #D6E4F7;
    --amarillo: #FFDE59;
    --blanco: #FFFFFF;
    --gris-texto: #1A1F2E;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--gris-texto);
    background: var(--blanco);
}

/* --- Login --- */
.login-body {
    background: var(--azul);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--blanco);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 10px 30px rgba(10, 46, 110, 0.25);
}

.login-title {
    color: var(--navy);
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--azul);
    font-weight: 600;
    margin-bottom: 24px;
}

.login-card label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-top: 16px;
    margin-bottom: 6px;
}

.login-card input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--azul-tint);
    border-radius: 8px;
    font-size: 15px;
}

.login-card input:focus {
    outline: none;
    border-color: var(--azul);
}

.login-card button {
    width: 100%;
    margin-top: 24px;
    padding: 12px;
    background: var(--azul);
    color: var(--blanco);
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.login-card button:hover {
    background: var(--navy);
}

.login-error {
    background: #FDECEC;
    color: #B00020;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    margin-top: 16px;
}

/* --- App shell --- */
.topbar {
    background: var(--navy);
    color: var(--blanco);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topbar-title {
    font-weight: 700;
    font-size: 18px;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 14px;
}

.logout-link {
    color: var(--amarillo);
    text-decoration: none;
    font-weight: 600;
}

.content {
    padding: 32px 24px;
}

.content h2 {
    color: var(--navy);
    margin-bottom: 12px;
}

/* --- App shell con sidebar (vistas internas: Dashboard, Empresas, Contactos, Issues) --- */
.app-shell {
    display: flex;
    min-height: calc(100vh - 60px);
}

.sidebar {
    width: 200px;
    background: var(--azul-tint);
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.sidebar-link {
    display: block;
    padding: 12px 24px;
    color: var(--navy);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: rgba(15, 81, 176, 0.1);
}

.sidebar-link.active {
    background: var(--blanco);
    border-left-color: var(--azul);
    color: var(--azul);
}

.sidebar-link-disabled {
    color: #9AA5B8;
    cursor: not-allowed;
}

.content {
    flex: 1;
    padding: 32px;
    overflow-x: auto;
}

.content-subtitle {
    color: #5A6478;
    font-size: 14px;
    margin-bottom: 20px;
}

/* --- Buscador --- */
.search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 20px;
}

.search-bar input {
    padding: 8px 12px;
    border: 1px solid var(--azul-tint);
    border-radius: 8px;
    font-size: 14px;
    min-width: 240px;
}

.search-bar button {
    padding: 8px 16px;
    background: var(--azul);
    color: var(--blanco);
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.search-bar button:hover {
    background: var(--navy);
}

.clear-link {
    font-size: 13px;
    color: var(--azul);
}

/* --- Tablas de datos --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--blanco);
    font-size: 14px;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--navy);
    color: var(--blanco);
    font-weight: 600;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--azul-tint);
}

.data-table tr:hover td {
    background: rgba(214, 228, 247, 0.35);
}

.data-table a {
    color: var(--azul);
    font-weight: 600;
    text-decoration: none;
}

.data-table a:hover {
    text-decoration: underline;
}

.row-alerta td:nth-child(2) {
    color: #B00020;
    font-weight: 700;
}

/* --- Detalle de empresa --- */
.back-link {
    display: inline-block;
    margin-bottom: 12px;
    color: var(--azul);
    font-weight: 600;
    text-decoration: none;
    font-size: 14px;
}

.detail-grid {
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin-top: 20px;
}

.detail-card {
    background: var(--blanco);
    border: 1px solid var(--azul-tint);
    border-radius: 12px;
    padding: 20px;
}

.detail-card h3 {
    color: var(--navy);
    margin-bottom: 12px;
    font-size: 16px;
}

.detail-card p {
    margin-bottom: 6px;
    font-size: 14px;
}

/* --- Issues: filtros por etapa, badges, formularios --- */
.titulo-con-accion {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 8px;
}

.btn-primario {
    display: inline-block;
    padding: 10px 18px;
    background: var(--azul);
    color: var(--blanco);
    border: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
}

.btn-primario:hover {
    background: var(--navy);
}

.filtro-etapas {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.filtro-chip {
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--azul-tint);
    color: var(--navy);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}

.filtro-chip.activo {
    background: var(--azul);
    color: var(--blanco);
}

.etapa-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.etapa-nuevo-issue {
    background: var(--azul-tint);
    color: var(--navy);
}

.etapa-en-proceso {
    background: #FFF3C4;
    color: #7A5B00;
}

.etapa-limbo {
    background: #E5E7EB;
    color: #4B5563;
}

.etapa-cobrado-exitoso {
    background: #D1F5E0;
    color: #0F7A3D;
}

.etapa-cuenta-incobrable {
    background: #FDECEC;
    color: #B00020;
}

/* --- Formularios de Issues --- */
.issue-form .detail-card {
    margin-bottom: 20px;
}

.checklist {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checklist-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.form-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 12px;
}

.form-row select,
.form-row input[type="text"] {
    padding: 8px 12px;
    border: 1px solid var(--azul-tint);
    border-radius: 8px;
    font-size: 14px;
}

.evento-form textarea {
    width: 100%;
    min-height: 70px;
    padding: 8px 12px;
    border: 1px solid var(--azul-tint);
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 10px;
    font-family: inherit;
    resize: vertical;
}

.evento-form input[type="date"] {
    padding: 8px 12px;
    border: 1px solid var(--azul-tint);
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 12px;
    display: block;
}

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

/* --- Avisos (mensajes flash) --- */
.aviso-ok {
    background: #E8F5EC;
    color: #1B6B35;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}
.content > .login-error {
    margin-top: 0;
    margin-bottom: 16px;
}

/* --- De cuándo son los datos de Alegra --- */
.consulta-alegra {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #555;
}
.btn-secundario {
    padding: 6px 12px;
    background: var(--blanco);
    color: var(--azul);
    border: 1px solid var(--azul);
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}
.btn-secundario:hover {
    background: var(--azul);
    color: var(--blanco);
}

/* --- Dashboard y Cartera vencida --- */
.tarjetas-resumen {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin: 16px 0 24px;
}

.tarjeta {
    border: 1px solid var(--azul-tint);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tarjeta-titulo {
    font-size: 13px;
    color: #5A6378;
}

.tarjeta-valor {
    font-size: 22px;
    font-weight: 700;
    color: var(--navy);
}

.tarjeta-alerta {
    border-color: #F2B8B5;
    background: #FFF5F4;
}

.tarjeta-alerta .tarjeta-valor {
    color: #B00020;
}

.bloque {
    margin-bottom: 24px;
}

.texto-chico {
    font-size: 12px;
    color: #5A6378;
}

.celda-notas {
    max-width: 380px;
    white-space: pre-line;
}

.estado {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

.estado-atrasado {
    background: #FDE2E1;
    color: #B00020;
    margin-left: 0;
}

.estado-hoy {
    background: var(--amarillo);
    color: var(--gris-texto);
}

.fila-total td {
    font-weight: 700;
    border-top: 2px solid var(--azul-tint);
}

.monto-vencido {
    color: #B00020;
    font-weight: 700;
}

.facturas-cliente summary {
    cursor: pointer;
    font-size: 12px;
    color: #5A6378;
    margin-top: 4px;
}

.tabla-mini {
    margin-top: 6px;
    font-size: 12px;
    border-collapse: collapse;
}

.tabla-mini td {
    padding: 2px 10px 2px 0;
    white-space: nowrap;
}

.tabla-mini tr.resaltada td {
    font-weight: 700;
}

.acciones {
    white-space: nowrap;
}

.acciones .btn-secundario {
    display: inline-block;
    text-decoration: none;
    margin: 2px 0;
}

/* --- Reporte CxC --- */
.tabla-reporte td:not(:first-child),
.tabla-reporte th:not(:first-child) {
    text-align: right;
    white-space: nowrap;
}

.tabla-reporte .col-antiguedad {
    background: #1B4A94;
}

.botones-titulo {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.botones-titulo .btn-secundario {
    text-decoration: none;
    display: inline-block;
}

form.en-linea {
    display: inline;
    margin: 0;
}

.monto-baja {
    color: #1B6B35;
    font-weight: 700;
}

/* --- Historial de cortes --- */
.tendencia {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 760px;
}

.tendencia-fila {
    display: grid;
    grid-template-columns: 150px 1fr 130px;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: inherit;
    text-decoration: none;
}

.tendencia-fila:hover .tendencia-nombre {
    text-decoration: underline;
}

.tendencia-barra {
    background: #EEF2FA;
    border-radius: 4px;
    height: 14px;
    overflow: hidden;
}

.tendencia-barra span {
    display: block;
    height: 100%;
    background: var(--azul);
}

.tendencia-monto {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.tabla-historial td:first-child {
    white-space: nowrap;
}
